firstEventFooter.tsx 4.9 KB

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