onboarding.tsx 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282
  1. import * as React from 'react';
  2. import {browserHistory, RouteComponentProps} from 'react-router';
  3. import styled from '@emotion/styled';
  4. import {AnimatePresence, motion, MotionProps, useAnimation} from 'framer-motion';
  5. import Button, {ButtonProps} from 'sentry/components/button';
  6. import Hook from 'sentry/components/hook';
  7. import Link from 'sentry/components/links/link';
  8. import LogoSentry from 'sentry/components/logoSentry';
  9. import SentryDocumentTitle from 'sentry/components/sentryDocumentTitle';
  10. import {PlatformKey} from 'sentry/data/platformCategories';
  11. import {IconArrow} from 'sentry/icons';
  12. import {t} from 'sentry/locale';
  13. import space from 'sentry/styles/space';
  14. import {Organization, Project} from 'sentry/types';
  15. import trackAdvancedAnalyticsEvent from 'sentry/utils/analytics/trackAdvancedAnalyticsEvent';
  16. import testableTransition from 'sentry/utils/testableTransition';
  17. import withOrganization from 'sentry/utils/withOrganization';
  18. import withProjects from 'sentry/utils/withProjects';
  19. import PageCorners from 'sentry/views/onboarding/components/pageCorners';
  20. import PlatformSelection from './platform';
  21. import SetupDocs from './setupDocs';
  22. import {StepDescriptor} from './types';
  23. import TargetedOnboardingWelcome from './welcome';
  24. type RouteParams = {
  25. orgId: string;
  26. step: string;
  27. };
  28. type Props = RouteComponentProps<RouteParams, {}> & {
  29. organization: Organization;
  30. projects: Project[];
  31. };
  32. const ONBOARDING_STEPS: StepDescriptor[] = [
  33. {
  34. id: 'welcome',
  35. title: t('Welcome'),
  36. Component: TargetedOnboardingWelcome,
  37. centered: true,
  38. },
  39. {
  40. id: 'select-platform',
  41. title: t('Select platforms'),
  42. Component: PlatformSelection,
  43. hasFooter: true,
  44. },
  45. {
  46. id: 'setup-docs',
  47. title: t('Install the Sentry SDK'),
  48. Component: SetupDocs,
  49. hasFooter: true,
  50. },
  51. ];
  52. function Onboarding(props: Props) {
  53. const {
  54. organization,
  55. params: {step: stepId},
  56. } = props;
  57. const stepObj = ONBOARDING_STEPS.find(({id}) => stepId === id);
  58. if (!stepObj) {
  59. return <div>Can't find</div>;
  60. }
  61. const cornerVariantControl = useAnimation();
  62. const updateCornerVariant = () => {
  63. // TODO: find better way to delay thhe corner animation
  64. setTimeout(
  65. () => cornerVariantControl.start(activeStepIndex === 0 ? 'top-right' : 'top-left'),
  66. 1000
  67. );
  68. };
  69. React.useEffect(updateCornerVariant, []);
  70. const [platforms, setPlatforms] = React.useState<PlatformKey[]>([]);
  71. const addPlatform = (platform: PlatformKey) => {
  72. setPlatforms([...platforms, platform]);
  73. };
  74. const removePlatform = (platform: PlatformKey) => {
  75. setPlatforms(platforms.filter(p => p !== platform));
  76. };
  77. const goNextStep = (step: StepDescriptor) => {
  78. const stepIndex = ONBOARDING_STEPS.findIndex(s => s.id === step.id);
  79. const nextStep = ONBOARDING_STEPS[stepIndex + 1];
  80. browserHistory.push(`/onboarding/${props.params.orgId}/${nextStep.id}/`);
  81. };
  82. const activeStepIndex = ONBOARDING_STEPS.findIndex(({id}) => props.params.step === id);
  83. const handleGoBack = () => {
  84. const previousStep = ONBOARDING_STEPS[activeStepIndex - 1];
  85. browserHistory.replace(`/onboarding/${props.params.orgId}/${previousStep.id}/`);
  86. };
  87. const genSkipOnboardingLink = () => {
  88. const source = `targeted-onboarding-${stepId}`;
  89. return (
  90. <SkipOnboardingLink
  91. onClick={() =>
  92. trackAdvancedAnalyticsEvent('growth.onboarding_clicked_skip', {
  93. organization,
  94. source,
  95. })
  96. }
  97. to={`/organizations/${organization.slug}/issues/`}
  98. >
  99. {t('Skip Onboarding')}
  100. </SkipOnboardingLink>
  101. );
  102. };
  103. return (
  104. <OnboardingWrapper data-test-id="targeted-onboarding">
  105. <SentryDocumentTitle title={stepObj.title} />
  106. <Header>
  107. <LogoSvg />
  108. <Hook name="onboarding:targeted-onboarding-header" />
  109. </Header>
  110. <Container hasFooter={!!stepObj.hasFooter}>
  111. <Back
  112. animate={activeStepIndex > 0 ? 'visible' : 'hidden'}
  113. onClick={handleGoBack}
  114. />
  115. <AnimatePresence exitBeforeEnter onExitComplete={updateCornerVariant}>
  116. <OnboardingStep
  117. centered={stepObj.centered}
  118. key={stepObj.id}
  119. data-test-id={`onboarding-step-${stepObj.id}`}
  120. >
  121. {stepObj.Component && (
  122. <stepObj.Component
  123. active
  124. stepIndex={activeStepIndex}
  125. onComplete={() => goNextStep(stepObj)}
  126. orgId={props.params.orgId}
  127. organization={props.organization}
  128. search={props.location.search}
  129. platforms={platforms}
  130. addPlatform={addPlatform}
  131. removePlatform={removePlatform}
  132. genSkipOnboardingLink={genSkipOnboardingLink}
  133. />
  134. )}
  135. </OnboardingStep>
  136. </AnimatePresence>
  137. <AdaptivePageCorners animateVariant={cornerVariantControl} />
  138. </Container>
  139. </OnboardingWrapper>
  140. );
  141. }
  142. const OnboardingWrapper = styled('main')`
  143. overflow: hidden;
  144. display: flex;
  145. flex-direction: column;
  146. flex-grow: 1;
  147. `;
  148. const Container = styled('div')<{hasFooter: boolean}>`
  149. display: flex;
  150. justify-content: center;
  151. position: relative;
  152. background: ${p => p.theme.background};
  153. padding: 120px ${space(3)};
  154. width: 100%;
  155. margin: 0 auto;
  156. flex-grow: 1;
  157. padding-bottom: ${p => p.hasFooter && '72px'};
  158. margin-bottom: ${p => p.hasFooter && '72px'};
  159. `;
  160. const Header = styled('header')`
  161. background: ${p => p.theme.background};
  162. padding: ${space(4)};
  163. position: sticky;
  164. top: 0;
  165. z-index: 100;
  166. box-shadow: 0 5px 10px rgba(0, 0, 0, 0.05);
  167. display: flex;
  168. justify-content: space-between;
  169. `;
  170. const LogoSvg = styled(LogoSentry)`
  171. width: 130px;
  172. height: 30px;
  173. color: ${p => p.theme.textColor};
  174. `;
  175. const OnboardingStep = styled(motion.div)<{centered?: boolean}>`
  176. display: flex;
  177. flex-direction: column;
  178. ${p =>
  179. p.centered &&
  180. `justify-content: center;
  181. align-items: center;`};
  182. `;
  183. OnboardingStep.defaultProps = {
  184. initial: 'initial',
  185. animate: 'animate',
  186. exit: 'exit',
  187. variants: {animate: {}},
  188. transition: testableTransition({
  189. staggerChildren: 0.2,
  190. }),
  191. };
  192. const Sidebar = styled(motion.div)`
  193. width: 850px;
  194. display: flex;
  195. flex-direction: column;
  196. align-items: center;
  197. `;
  198. Sidebar.defaultProps = {
  199. initial: 'initial',
  200. animate: 'animate',
  201. exit: 'exit',
  202. variants: {animate: {}},
  203. transition: testableTransition({
  204. staggerChildren: 0.2,
  205. }),
  206. };
  207. const AdaptivePageCorners = styled(PageCorners)`
  208. --corner-scale: 1;
  209. @media (max-width: ${p => p.theme.breakpoints[0]}) {
  210. --corner-scale: 0.5;
  211. }
  212. `;
  213. interface BackButtonProps extends Omit<ButtonProps, 'icon' | 'priority'> {
  214. animate: MotionProps['animate'];
  215. className?: string;
  216. }
  217. const Back = styled(({className, animate, ...props}: BackButtonProps) => (
  218. <motion.div
  219. className={className}
  220. animate={animate}
  221. transition={testableTransition()}
  222. variants={{
  223. initial: {opacity: 0, visibility: 'hidden'},
  224. visible: {
  225. opacity: 1,
  226. visibility: 'visible',
  227. transition: testableTransition({delay: 1}),
  228. },
  229. hidden: {
  230. opacity: 0,
  231. transitionEnd: {
  232. visibility: 'hidden',
  233. },
  234. },
  235. }}
  236. >
  237. <Button {...props} icon={<IconArrow direction="left" size="sm" />} priority="link">
  238. {t('Back')}
  239. </Button>
  240. </motion.div>
  241. ))`
  242. position: absolute;
  243. top: 40px;
  244. left: 20px;
  245. button {
  246. font-size: ${p => p.theme.fontSizeSmall};
  247. }
  248. `;
  249. const SkipOnboardingLink = styled(Link)`
  250. margin: auto ${space(4)};
  251. `;
  252. export default withOrganization(withProjects(Onboarding));