firstEventFooter.tsx 4.8 KB

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