setupDocs.tsx 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160
  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. newOrg
  76. />
  77. ) : (
  78. <SdkDocumentation
  79. platform={currentPlatform}
  80. organization={organization}
  81. projectSlug={project.slug}
  82. projectId={project.id}
  83. activeProductSelection={products}
  84. newOrg
  85. />
  86. )}
  87. </Fragment>
  88. )}
  89. </MainContent>
  90. </Wrapper>
  91. <FirstEventFooter
  92. project={project}
  93. organization={organization}
  94. isLast
  95. onClickSetupLater={() => {
  96. const orgIssuesURL = `/organizations/${organization.slug}/issues/?project=${project.id}&referrer=onboarding-setup-docs`;
  97. trackAnalytics('growth.onboarding_clicked_setup_platform_later', {
  98. organization,
  99. platform: currentPlatformKey,
  100. project_id: project.id,
  101. });
  102. browserHistory.push(orgIssuesURL);
  103. }}
  104. />
  105. </Fragment>
  106. );
  107. }
  108. export default SetupDocs;
  109. const AnimatedContentWrapper = styled(motion.div)`
  110. overflow: hidden;
  111. `;
  112. AnimatedContentWrapper.defaultProps = {
  113. initial: {
  114. height: 0,
  115. },
  116. animate: {
  117. height: 'auto',
  118. },
  119. exit: {
  120. height: 0,
  121. },
  122. };
  123. const DocsWrapper = styled(motion.div)``;
  124. DocsWrapper.defaultProps = {
  125. initial: {opacity: 0, y: 40},
  126. animate: {opacity: 1, y: 0},
  127. exit: {opacity: 0},
  128. };
  129. const Wrapper = styled('div')`
  130. display: flex;
  131. flex-direction: row;
  132. margin: ${space(2)};
  133. justify-content: center;
  134. `;
  135. const MainContent = styled('div')`
  136. max-width: 850px;
  137. min-width: 0;
  138. flex-grow: 1;
  139. `;