firstEventFooter.tsx 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185
  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="targeted-onboarding"
  46. priority="primary"
  47. >
  48. {t('View Sample Error')}
  49. </CreateSampleEventButton>
  50. );
  51. }
  52. return (
  53. <LinkButton
  54. onClick={() =>
  55. trackAnalytics('growth.onboarding_take_to_error', {
  56. organization: project.organization,
  57. platform: project.platform,
  58. })
  59. }
  60. to={`/organizations/${organization.slug}/issues/${
  61. project?.firstIssue && 'id' in project.firstIssue
  62. ? `${project.firstIssue.id}/`
  63. : ''
  64. }?referrer=onboarding-first-event-footer`}
  65. priority="primary"
  66. >
  67. {t('Take me to my error')}
  68. </LinkButton>
  69. );
  70. }, [project, organization.slug]);
  71. return (
  72. <GridFooter>
  73. <SkipOnboardingLink
  74. onClick={() => {
  75. trackAnalytics('growth.onboarding_clicked_skip', {
  76. organization,
  77. source,
  78. });
  79. }}
  80. to={`/organizations/${organization.slug}/issues/?referrer=onboarding-first-event-footer-skip`}
  81. >
  82. {t('Skip Onboarding')}
  83. </SkipOnboardingLink>
  84. <StatusWrapper>
  85. {project?.firstError ? (
  86. <IconCheckmark isCircled color="green400" />
  87. ) : (
  88. <WaitingIndicator />
  89. )}
  90. <AnimatedText errorReceived={project?.firstError}>
  91. {project?.firstError ? t('Error Received') : t('Waiting for error')}
  92. </AnimatedText>
  93. </StatusWrapper>
  94. <OnboardingButtonBar gap={2}>
  95. {getSecondaryCta()}
  96. {getPrimaryCta()}
  97. </OnboardingButtonBar>
  98. </GridFooter>
  99. );
  100. }
  101. const OnboardingButtonBar = styled(ButtonBar)`
  102. margin: ${space(2)} ${space(4)};
  103. justify-self: end;
  104. margin-left: auto;
  105. `;
  106. const AnimatedText = styled(motion.div, {
  107. shouldForwardProp: prop => prop !== 'errorReceived',
  108. })<{errorReceived: boolean}>`
  109. margin-left: ${space(1)};
  110. color: ${p => (p.errorReceived ? p.theme.successText : p.theme.pink400)};
  111. `;
  112. const indicatorAnimation: Variants = {
  113. initial: {opacity: 0, y: -10},
  114. animate: {opacity: 1, y: 0},
  115. exit: {opacity: 0, y: 10},
  116. };
  117. AnimatedText.defaultProps = {
  118. variants: indicatorAnimation,
  119. transition: testableTransition(),
  120. };
  121. const WaitingIndicator = styled(motion.div)`
  122. ${pulsingIndicatorStyles};
  123. background-color: ${p => p.theme.pink300};
  124. `;
  125. WaitingIndicator.defaultProps = {
  126. variants: indicatorAnimation,
  127. transition: testableTransition(),
  128. };
  129. const StatusWrapper = styled(motion.div)`
  130. display: flex;
  131. align-items: center;
  132. font-size: ${p => p.theme.fontSizeMedium};
  133. justify-content: center;
  134. @media (max-width: ${p => p.theme.breakpoints.small}) {
  135. display: none;
  136. }
  137. `;
  138. StatusWrapper.defaultProps = {
  139. initial: 'initial',
  140. animate: 'animate',
  141. exit: 'exit',
  142. variants: {
  143. initial: {opacity: 0, y: -10},
  144. animate: {
  145. opacity: 1,
  146. y: 0,
  147. transition: testableTransition({when: 'beforeChildren', staggerChildren: 0.35}),
  148. },
  149. exit: {opacity: 0, y: 10},
  150. },
  151. };
  152. const SkipOnboardingLink = styled(Link)`
  153. margin: auto ${space(4)};
  154. white-space: nowrap;
  155. @media (max-width: ${p => p.theme.breakpoints.small}) {
  156. display: none;
  157. }
  158. `;
  159. const GridFooter = styled(GenericFooter)`
  160. display: grid;
  161. grid-template-columns: 1fr 1fr 1fr;
  162. @media (max-width: ${p => p.theme.breakpoints.small}) {
  163. display: flex;
  164. flex-direction: row;
  165. justify-content: end;
  166. }
  167. `;