firstEventFooter.tsx 5.3 KB

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