onboardingCard.tsx 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190
  1. import styled from '@emotion/styled';
  2. import {motion} from 'framer-motion';
  3. import {PlatformIcon} from 'platformicons';
  4. import Button from 'sentry/components/button';
  5. import Card from 'sentry/components/card';
  6. import Link from 'sentry/components/links/link';
  7. import {IconChevron, IconClose, IconEllipsis} from 'sentry/icons';
  8. import {t, tct} from 'sentry/locale';
  9. import pulsingIndicatorStyles from 'sentry/styles/pulsingIndicator';
  10. import space from 'sentry/styles/space';
  11. import {OnboardingCustomComponentProps, Project} from 'sentry/types';
  12. import trackAdvancedAnalyticsEvent from 'sentry/utils/analytics/trackAdvancedAnalyticsEvent';
  13. import SkipConfirm from './skipConfirm';
  14. const MAX_PROJECT_COUNT = 3;
  15. export default function OnboardingProjectsCard({
  16. organization: org,
  17. onboardingState,
  18. setOnboardingState,
  19. projects: allProjects,
  20. }: OnboardingCustomComponentProps) {
  21. if (!onboardingState) {
  22. return null;
  23. }
  24. const handleSkip = () => {
  25. setOnboardingState({
  26. ...onboardingState,
  27. selectedPlatforms: [],
  28. });
  29. };
  30. // Projects selected during onboarding but not received first event
  31. const projects = onboardingState.selectedPlatforms
  32. .map(platform => onboardingState.platformToProjectIdMap[platform])
  33. .map(projectId => allProjects.find(p => p.slug === projectId))
  34. .filter(project => project && !project.firstEvent) as Project[];
  35. if (projects.length === 0) {
  36. return null;
  37. }
  38. return (
  39. <TaskCard key="onboarding-continue-card">
  40. <Title>{t('Project to Setup')}</Title>
  41. <OnboardingTaskProjectList>
  42. {projects.slice(0, MAX_PROJECT_COUNT).map(p => (
  43. <OnboardingTaskProjectListItem
  44. key={p.id}
  45. to={`/onboarding/${org.slug}/setup-docs/?project_id=${p.id}`}
  46. onClick={() => {
  47. trackAdvancedAnalyticsEvent('growth.onboarding_quick_start_cta', {
  48. platform: p.platform,
  49. organization: org,
  50. });
  51. }}
  52. >
  53. <OnboardingTaskProjectListItemInner>
  54. <StyledPlatformIcon platform={p.platform || 'default'} />
  55. {p.slug}
  56. <PulsingIndicator />
  57. <PulsingIndicatorText>{t('Waiting for event')}</PulsingIndicatorText>
  58. <IconChevron direction="right" />
  59. </OnboardingTaskProjectListItemInner>
  60. </OnboardingTaskProjectListItem>
  61. ))}
  62. {projects.length > MAX_PROJECT_COUNT && (
  63. <OnboardingTaskProjectListItem
  64. to={`/onboarding/${org.slug}/setup-docs/`}
  65. onClick={() => {
  66. trackAdvancedAnalyticsEvent('growth.onboarding_quick_start_cta', {
  67. organization: org,
  68. });
  69. }}
  70. >
  71. <OnboardingTaskProjectListItemInner>
  72. <StyledAndMoreIcon />
  73. {tct('and [num] more', {num: projects.length - MAX_PROJECT_COUNT})}
  74. </OnboardingTaskProjectListItemInner>
  75. </OnboardingTaskProjectListItem>
  76. )}
  77. </OnboardingTaskProjectList>
  78. <SkipConfirm onSkip={handleSkip}>
  79. {({skip}) => (
  80. <CloseButton
  81. borderless
  82. size="zero"
  83. aria-label={t('Close')}
  84. icon={<IconClose size="xs" />}
  85. onClick={skip}
  86. />
  87. )}
  88. </SkipConfirm>
  89. </TaskCard>
  90. );
  91. }
  92. const Heading = styled(motion.div)`
  93. display: flex;
  94. color: ${p => p.theme.purple300};
  95. font-size: ${p => p.theme.fontSizeExtraSmall};
  96. text-transform: uppercase;
  97. font-weight: 600;
  98. line-height: 1;
  99. margin-top: ${space(3)};
  100. `;
  101. Heading.defaultProps = {
  102. exit: 'exit',
  103. variants: {
  104. exit: {
  105. height: 0,
  106. marginTop: 0,
  107. opacity: 0,
  108. transition: {duration: 0.3},
  109. },
  110. },
  111. };
  112. const Title = styled('div')`
  113. font-weight: 600;
  114. margin: ${space(2)} ${space(3)} 0;
  115. `;
  116. const TaskCard = styled(motion(Card))`
  117. position: relative;
  118. overflow: visible;
  119. display: flex;
  120. flex-direction: column;
  121. padding-bottom: ${space(1)};
  122. `;
  123. TaskCard.defaultProps = {
  124. exit: 'exit',
  125. variants: {
  126. exit: {
  127. height: 0,
  128. overflow: 'hidden',
  129. transition: {duration: 0.3},
  130. },
  131. },
  132. };
  133. const OnboardingTaskProjectList = styled('div')`
  134. display: flex;
  135. flex-direction: column;
  136. `;
  137. const OnboardingTaskProjectListItemInner = styled('div')`
  138. padding: ${space(1)} 0;
  139. display: flex;
  140. align-items: center;
  141. `;
  142. const OnboardingTaskProjectListItem = styled(Link)`
  143. :hover {
  144. background-color: ${p => p.theme.hover};
  145. }
  146. border-radius: 0;
  147. padding: 0 ${space(3)};
  148. color: ${p => p.theme.textColor};
  149. :not(:last-child) {
  150. ${OnboardingTaskProjectListItemInner} {
  151. border-bottom: 1px solid ${p => p.theme.innerBorder};
  152. }
  153. }
  154. `;
  155. const PulsingIndicator = styled('div')`
  156. ${pulsingIndicatorStyles};
  157. margin-left: auto;
  158. `;
  159. const PulsingIndicatorText = styled('span')`
  160. color: ${p => p.theme.pink300};
  161. font-size: ${p => p.theme.fontSizeMedium};
  162. margin: 0 ${space(1)};
  163. `;
  164. const CloseButton = styled(Button)`
  165. position: absolute;
  166. right: ${space(1.5)};
  167. top: ${space(1.5)};
  168. color: ${p => p.theme.gray300};
  169. `;
  170. const StyledPlatformIcon = styled(PlatformIcon)`
  171. margin-right: ${space(1)};
  172. `;
  173. const StyledAndMoreIcon = styled(IconEllipsis)`
  174. margin-right: ${space(1)};
  175. `;