firstEventFooter.tsx 5.2 KB

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