firstEventFooter.tsx 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220
  1. import {Fragment, useContext, useEffect} from 'react';
  2. import styled from '@emotion/styled';
  3. import {motion, Variants} from 'framer-motion';
  4. import {Button} from 'sentry/components/button';
  5. import ButtonBar from 'sentry/components/buttonBar';
  6. import Link from 'sentry/components/links/link';
  7. import {OnboardingContext} from 'sentry/components/onboarding/onboardingContext';
  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 {Group, OnboardingStatus, Organization, Project} from 'sentry/types';
  13. import trackAdvancedAnalyticsEvent from 'sentry/utils/analytics/trackAdvancedAnalyticsEvent';
  14. import EventWaiter from 'sentry/utils/eventWaiter';
  15. import testableTransition from 'sentry/utils/testableTransition';
  16. import CreateSampleEventButton from 'sentry/views/onboarding/createSampleEventButton';
  17. import {usePersistedOnboardingState} from '../utils';
  18. import GenericFooter from './genericFooter';
  19. interface FirstEventFooterProps {
  20. handleFirstIssueReceived: () => void;
  21. hasFirstEvent: boolean;
  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. hasFirstEvent,
  33. handleFirstIssueReceived,
  34. }: FirstEventFooterProps) {
  35. const source = 'targeted_onboarding_first_event_footer';
  36. const [clientState, setClientState] = usePersistedOnboardingState();
  37. const onboardingContext = useContext(OnboardingContext);
  38. useEffect(() => {
  39. if (!project.slug) {
  40. return;
  41. }
  42. if (onboardingContext.data[project.id]?.status === OnboardingStatus.WAITING) {
  43. return;
  44. }
  45. onboardingContext.setProjectData({
  46. projectId: project.id,
  47. projectSlug: project.slug,
  48. status: OnboardingStatus.WAITING,
  49. });
  50. }, [project.id, project.slug, onboardingContext]);
  51. const getSecondaryCta = () => {
  52. // if hasn't sent first event, allow skiping.
  53. // if last, no secondary cta
  54. if (!hasFirstEvent && !isLast) {
  55. return <Button onClick={onClickSetupLater}>{t('Next Platform')}</Button>;
  56. }
  57. return null;
  58. };
  59. const getPrimaryCta = ({firstIssue}: {firstIssue: null | boolean | Group}) => {
  60. // if hasn't sent first event, allow creation of sample error
  61. if (!hasFirstEvent) {
  62. return (
  63. <CreateSampleEventButton
  64. project={project}
  65. source="targted-onboarding"
  66. priority="primary"
  67. >
  68. {t('View Sample Error')}
  69. </CreateSampleEventButton>
  70. );
  71. }
  72. return (
  73. <Button
  74. to={`/organizations/${organization.slug}/issues/${
  75. firstIssue && firstIssue !== true && 'id' in firstIssue
  76. ? `${firstIssue.id}/`
  77. : ''
  78. }?referrer=onboarding-first-event-footer`}
  79. priority="primary"
  80. >
  81. {t('Take me to my error')}
  82. </Button>
  83. );
  84. };
  85. return (
  86. <GridFooter>
  87. <SkipOnboardingLink
  88. onClick={() => {
  89. trackAdvancedAnalyticsEvent('growth.onboarding_clicked_skip', {
  90. organization,
  91. source,
  92. });
  93. if (clientState) {
  94. setClientState({
  95. ...clientState,
  96. state: 'skipped',
  97. });
  98. }
  99. }}
  100. to={`/organizations/${organization.slug}/issues/?referrer=onboarding-first-event-footer-skip`}
  101. >
  102. {t('Skip Onboarding')}
  103. </SkipOnboardingLink>
  104. <EventWaiter
  105. eventType="error"
  106. onIssueReceived={handleFirstIssueReceived}
  107. {...{project, organization}}
  108. >
  109. {({firstIssue}) => (
  110. <Fragment>
  111. <StatusWrapper>
  112. {hasFirstEvent ? (
  113. <IconCheckmark isCircled color="green400" />
  114. ) : (
  115. <WaitingIndicator />
  116. )}
  117. <AnimatedText errorReceived={hasFirstEvent}>
  118. {hasFirstEvent ? t('Error Received') : t('Waiting for error')}
  119. </AnimatedText>
  120. </StatusWrapper>
  121. <OnboardingButtonBar gap={2}>
  122. {getSecondaryCta()}
  123. {getPrimaryCta({firstIssue})}
  124. </OnboardingButtonBar>
  125. </Fragment>
  126. )}
  127. </EventWaiter>
  128. </GridFooter>
  129. );
  130. }
  131. const OnboardingButtonBar = styled(ButtonBar)`
  132. margin: ${space(2)} ${space(4)};
  133. justify-self: end;
  134. margin-left: auto;
  135. `;
  136. const AnimatedText = styled(motion.div, {
  137. shouldForwardProp: prop => prop !== 'errorReceived',
  138. })<{errorReceived: boolean}>`
  139. margin-left: ${space(1)};
  140. color: ${p => (p.errorReceived ? p.theme.successText : p.theme.pink400)};
  141. `;
  142. const indicatorAnimation: Variants = {
  143. initial: {opacity: 0, y: -10},
  144. animate: {opacity: 1, y: 0},
  145. exit: {opacity: 0, y: 10},
  146. };
  147. AnimatedText.defaultProps = {
  148. variants: indicatorAnimation,
  149. transition: testableTransition(),
  150. };
  151. const WaitingIndicator = styled(motion.div)`
  152. ${pulsingIndicatorStyles};
  153. background-color: ${p => p.theme.pink300};
  154. `;
  155. WaitingIndicator.defaultProps = {
  156. variants: indicatorAnimation,
  157. transition: testableTransition(),
  158. };
  159. const StatusWrapper = styled(motion.div)`
  160. display: flex;
  161. align-items: center;
  162. font-size: ${p => p.theme.fontSizeMedium};
  163. justify-content: center;
  164. @media (max-width: ${p => p.theme.breakpoints.small}) {
  165. display: none;
  166. }
  167. `;
  168. StatusWrapper.defaultProps = {
  169. initial: 'initial',
  170. animate: 'animate',
  171. exit: 'exit',
  172. variants: {
  173. initial: {opacity: 0, y: -10},
  174. animate: {
  175. opacity: 1,
  176. y: 0,
  177. transition: testableTransition({when: 'beforeChildren', staggerChildren: 0.35}),
  178. },
  179. exit: {opacity: 0, y: 10},
  180. },
  181. };
  182. const SkipOnboardingLink = styled(Link)`
  183. margin: auto ${space(4)};
  184. white-space: nowrap;
  185. @media (max-width: ${p => p.theme.breakpoints.small}) {
  186. display: none;
  187. }
  188. `;
  189. const GridFooter = styled(GenericFooter)`
  190. display: grid;
  191. grid-template-columns: 1fr 1fr 1fr;
  192. @media (max-width: ${p => p.theme.breakpoints.small}) {
  193. display: flex;
  194. flex-direction: row;
  195. justify-content: end;
  196. }
  197. `;