firstEventFooter.tsx 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203
  1. import {useCallback} from 'react';
  2. import styled from '@emotion/styled';
  3. import type {Variants} from 'framer-motion';
  4. import {motion} from 'framer-motion';
  5. import {Button, LinkButton} from 'sentry/components/button';
  6. import ButtonBar from 'sentry/components/buttonBar';
  7. import Link from 'sentry/components/links/link';
  8. import {IconCheckmark} from 'sentry/icons';
  9. import {t} from 'sentry/locale';
  10. import pulsingIndicatorStyles from 'sentry/styles/pulsingIndicator';
  11. import {space} from 'sentry/styles/space';
  12. import type {Group} from 'sentry/types/group';
  13. import type {Organization} from 'sentry/types/organization';
  14. import type {Project} from 'sentry/types/project';
  15. import {trackAnalytics} from 'sentry/utils/analytics';
  16. import {useApiQuery} from 'sentry/utils/queryClient';
  17. import testableTransition from 'sentry/utils/testableTransition';
  18. import CreateSampleEventButton from 'sentry/views/onboarding/createSampleEventButton';
  19. import {useOnboardingSidebar} from 'sentry/views/onboarding/useOnboardingSidebar';
  20. import GenericFooter from './genericFooter';
  21. interface FirstEventFooterProps {
  22. isLast: boolean;
  23. onClickSetupLater: () => void;
  24. organization: Organization;
  25. project: Project;
  26. }
  27. export default function FirstEventFooter({
  28. organization,
  29. project,
  30. onClickSetupLater,
  31. isLast,
  32. }: FirstEventFooterProps) {
  33. const {activateSidebar} = useOnboardingSidebar();
  34. const {data: issues} = useApiQuery<Group[]>(
  35. [`/projects/${organization.slug}/${project.slug}/issues/`],
  36. {
  37. staleTime: Infinity,
  38. enabled: !!project.firstEvent,
  39. }
  40. );
  41. const firstIssue =
  42. !!project.firstEvent && issues
  43. ? issues.find((issue: Group) => issue.firstSeen === project.firstEvent)
  44. : undefined;
  45. const source = 'targeted_onboarding_first_event_footer';
  46. const getSecondaryCta = useCallback(() => {
  47. // if hasn't sent first event, allow skiping.
  48. // if last, no secondary cta
  49. if (!project?.firstEvent && !isLast) {
  50. return <Button onClick={onClickSetupLater}>{t('Next Platform')}</Button>;
  51. }
  52. return null;
  53. }, [project?.firstEvent, isLast, onClickSetupLater]);
  54. const getPrimaryCta = useCallback(() => {
  55. // if hasn't sent first event, allow creation of sample error
  56. if (!project?.firstEvent) {
  57. return (
  58. <CreateSampleEventButton
  59. project={project}
  60. source="targeted-onboarding"
  61. priority="primary"
  62. >
  63. {t('View Sample Error')}
  64. </CreateSampleEventButton>
  65. );
  66. }
  67. return (
  68. <LinkButton
  69. onClick={() =>
  70. trackAnalytics('growth.onboarding_take_to_error', {
  71. organization: project.organization,
  72. platform: project.platform,
  73. })
  74. }
  75. to={`/organizations/${organization.slug}/issues/${
  76. firstIssue && 'id' in firstIssue ? `${firstIssue.id}/` : ''
  77. }?referrer=onboarding-first-event-footer`}
  78. priority="primary"
  79. >
  80. {t('Take me to my error')}
  81. </LinkButton>
  82. );
  83. }, [project, organization.slug, firstIssue]);
  84. return (
  85. <GridFooter>
  86. <SkipOnboardingLink
  87. onClick={() => {
  88. trackAnalytics('growth.onboarding_clicked_skip', {
  89. organization,
  90. source,
  91. });
  92. activateSidebar({
  93. userClicked: false,
  94. source: 'targeted_onboarding_first_event_footer_skip',
  95. });
  96. }}
  97. to={`/organizations/${organization.slug}/issues/?referrer=onboarding-first-event-footer-skip`}
  98. >
  99. {t('Skip Onboarding')}
  100. </SkipOnboardingLink>
  101. <StatusWrapper
  102. initial="initial"
  103. animate="animate"
  104. exit="exit"
  105. variants={{
  106. initial: {opacity: 0, y: -10},
  107. animate: {
  108. opacity: 1,
  109. y: 0,
  110. transition: testableTransition({
  111. when: 'beforeChildren',
  112. staggerChildren: 0.35,
  113. }),
  114. },
  115. exit: {opacity: 0, y: 10},
  116. }}
  117. >
  118. {project?.firstEvent ? (
  119. <IconCheckmark isCircled color="green400" />
  120. ) : (
  121. <WaitingIndicator
  122. variants={indicatorAnimation}
  123. transition={testableTransition()}
  124. />
  125. )}
  126. <AnimatedText
  127. errorReceived={!!project?.firstEvent}
  128. variants={indicatorAnimation}
  129. transition={testableTransition()}
  130. >
  131. {project?.firstEvent ? t('Error Received') : t('Waiting for error')}
  132. </AnimatedText>
  133. </StatusWrapper>
  134. <OnboardingButtonBar gap={2}>
  135. {getSecondaryCta()}
  136. {getPrimaryCta()}
  137. </OnboardingButtonBar>
  138. </GridFooter>
  139. );
  140. }
  141. const OnboardingButtonBar = styled(ButtonBar)`
  142. margin: ${space(2)} ${space(4)};
  143. justify-self: end;
  144. margin-left: auto;
  145. `;
  146. const AnimatedText = styled(motion.div, {
  147. shouldForwardProp: prop => prop !== 'errorReceived',
  148. })<{errorReceived: boolean}>`
  149. margin-left: ${space(1)};
  150. color: ${p => (p.errorReceived ? p.theme.successText : p.theme.pink400)};
  151. `;
  152. const indicatorAnimation: Variants = {
  153. initial: {opacity: 0, y: -10},
  154. animate: {opacity: 1, y: 0},
  155. exit: {opacity: 0, y: 10},
  156. };
  157. const WaitingIndicator = styled(motion.div)`
  158. ${pulsingIndicatorStyles};
  159. background-color: ${p => p.theme.pink300};
  160. `;
  161. const StatusWrapper = styled(motion.div)`
  162. display: flex;
  163. align-items: center;
  164. font-size: ${p => p.theme.fontSizeMedium};
  165. justify-content: center;
  166. @media (max-width: ${p => p.theme.breakpoints.small}) {
  167. display: none;
  168. }
  169. `;
  170. const SkipOnboardingLink = styled(Link)`
  171. margin: auto ${space(4)};
  172. white-space: nowrap;
  173. @media (max-width: ${p => p.theme.breakpoints.small}) {
  174. display: none;
  175. }
  176. `;
  177. const GridFooter = styled(GenericFooter)`
  178. display: grid;
  179. grid-template-columns: 1fr 1fr 1fr;
  180. @media (max-width: ${p => p.theme.breakpoints.small}) {
  181. display: flex;
  182. flex-direction: row;
  183. justify-content: end;
  184. }
  185. `;