setupDocs.tsx 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159
  1. import {Fragment, useCallback, useEffect, useMemo, useState} from 'react';
  2. import {browserHistory} from 'react-router';
  3. import styled from '@emotion/styled';
  4. import {motion} from 'framer-motion';
  5. import {SdkDocumentation} from 'sentry/components/onboarding/gettingStartedDoc/sdkDocumentation';
  6. import {ProductSolution} from 'sentry/components/onboarding/productSelection';
  7. import platforms from 'sentry/data/platforms';
  8. import {t} from 'sentry/locale';
  9. import {space} from 'sentry/styles/space';
  10. import {trackAnalytics} from 'sentry/utils/analytics';
  11. import {platformToIntegrationMap} from 'sentry/utils/integrationUtil';
  12. import useOrganization from 'sentry/utils/useOrganization';
  13. import SetupIntroduction from 'sentry/views/onboarding/components/setupIntroduction';
  14. import {SetupDocsLoader} from 'sentry/views/onboarding/setupDocsLoader';
  15. import FirstEventFooter from './components/firstEventFooter';
  16. import IntegrationSetup from './integrationSetup';
  17. import {StepProps} from './types';
  18. function SetupDocs({location, recentCreatedProject: project}: StepProps) {
  19. const organization = useOrganization();
  20. const [integrationUseManualSetup, setIntegrationUseManualSetup] = useState(false);
  21. const products = useMemo<ProductSolution[]>(
  22. () => (location.query.product ?? []) as ProductSolution[],
  23. [location.query.product]
  24. );
  25. const currentPlatformKey = project?.platform ?? 'other';
  26. const currentPlatform = platforms.find(p => p.id === currentPlatformKey);
  27. const [showLoaderOnboarding, setShowLoaderOnboarding] = useState(
  28. currentPlatformKey === 'javascript'
  29. );
  30. useEffect(() => {
  31. setShowLoaderOnboarding(currentPlatformKey === 'javascript');
  32. }, [currentPlatformKey]);
  33. const hideLoaderOnboarding = useCallback(() => {
  34. setShowLoaderOnboarding(false);
  35. if (!project?.id) {
  36. return;
  37. }
  38. trackAnalytics('onboarding.js_loader_npm_docs_shown', {
  39. organization,
  40. platform: currentPlatformKey,
  41. project_id: project?.id,
  42. });
  43. }, [organization, currentPlatformKey, project?.id]);
  44. if (!project || !currentPlatform) {
  45. return null;
  46. }
  47. const platformName = currentPlatform?.name ?? '';
  48. const integrationSlug = project?.platform && platformToIntegrationMap[project.platform];
  49. const showIntegrationOnboarding = integrationSlug && !integrationUseManualSetup;
  50. return (
  51. <Fragment>
  52. <Wrapper>
  53. <MainContent>
  54. {showIntegrationOnboarding ? (
  55. <IntegrationSetup
  56. integrationSlug={integrationSlug}
  57. project={project}
  58. onClickManualSetup={() => {
  59. setIntegrationUseManualSetup(true);
  60. }}
  61. />
  62. ) : (
  63. <Fragment>
  64. <SetupIntroduction
  65. stepHeaderText={t('Configure %s SDK', platformName)}
  66. platform={currentPlatformKey}
  67. />
  68. {showLoaderOnboarding ? (
  69. <SetupDocsLoader
  70. organization={organization}
  71. project={project}
  72. location={location}
  73. platform={currentPlatform.id}
  74. close={hideLoaderOnboarding}
  75. />
  76. ) : (
  77. <SdkDocumentation
  78. platform={currentPlatform}
  79. organization={organization}
  80. projectSlug={project.slug}
  81. projectId={project.id}
  82. activeProductSelection={products}
  83. newOrg
  84. />
  85. )}
  86. </Fragment>
  87. )}
  88. </MainContent>
  89. </Wrapper>
  90. <FirstEventFooter
  91. project={project}
  92. organization={organization}
  93. isLast
  94. onClickSetupLater={() => {
  95. const orgIssuesURL = `/organizations/${organization.slug}/issues/?project=${project.id}&referrer=onboarding-setup-docs`;
  96. trackAnalytics('growth.onboarding_clicked_setup_platform_later', {
  97. organization,
  98. platform: currentPlatformKey,
  99. project_id: project.id,
  100. });
  101. browserHistory.push(orgIssuesURL);
  102. }}
  103. />
  104. </Fragment>
  105. );
  106. }
  107. export default SetupDocs;
  108. const AnimatedContentWrapper = styled(motion.div)`
  109. overflow: hidden;
  110. `;
  111. AnimatedContentWrapper.defaultProps = {
  112. initial: {
  113. height: 0,
  114. },
  115. animate: {
  116. height: 'auto',
  117. },
  118. exit: {
  119. height: 0,
  120. },
  121. };
  122. const DocsWrapper = styled(motion.div)``;
  123. DocsWrapper.defaultProps = {
  124. initial: {opacity: 0, y: 40},
  125. animate: {opacity: 1, y: 0},
  126. exit: {opacity: 0},
  127. };
  128. const Wrapper = styled('div')`
  129. display: flex;
  130. flex-direction: row;
  131. margin: ${space(2)};
  132. justify-content: center;
  133. `;
  134. const MainContent = styled('div')`
  135. max-width: 850px;
  136. min-width: 0;
  137. flex-grow: 1;
  138. `;