firstEventFooter.tsx 4.8 KB

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