import {Fragment, useCallback, useEffect, useState} from 'react'; import styled from '@emotion/styled'; import {motion} from 'framer-motion'; import {openInviteMembersModal} from 'sentry/actionCreators/modal'; import {Alert} from 'sentry/components/alert'; import {Button} from 'sentry/components/button'; import ButtonBar from 'sentry/components/buttonBar'; import ExternalLink from 'sentry/components/links/externalLink'; import LoadingError from 'sentry/components/loadingError'; import platforms from 'sentry/data/platforms'; import {t, tct} from 'sentry/locale'; import {space} from 'sentry/styles/space'; import type {IntegrationProvider, Project} from 'sentry/types'; import {trackAnalytics} from 'sentry/utils/analytics'; import getDynamicText from 'sentry/utils/getDynamicText'; import {trackIntegrationAnalytics} from 'sentry/utils/integrationUtil'; import useApi from 'sentry/utils/useApi'; import useOrganization from 'sentry/utils/useOrganization'; import {AddIntegrationButton} from 'sentry/views/settings/organizationIntegrations/addIntegrationButton'; import AddInstallationInstructions from './components/integrations/addInstallationInstructions'; import PostInstallCodeSnippet from './components/integrations/postInstallCodeSnippet'; import SetupIntroduction from './components/setupIntroduction'; type Props = { integrationSlug: string; project: Project | null; onClickManualSetup?: () => void; }; function IntegrationSetup(props: Props) { const [hasError, setHasError] = useState(false); const [installed, setInstalled] = useState(false); const [provider, setProvider] = useState(null); const organization = useOrganization(); const {project, integrationSlug} = props; const api = useApi(); const fetchData = useCallback(() => { if (!integrationSlug) { return Promise.resolve(); } const endpoint = `/organizations/${organization.slug}/config/integrations/?provider_key=${integrationSlug}`; return api .requestPromise(endpoint) .then(integrations => { setProvider(integrations.providers[0]); setHasError(false); }) .catch(error => { setHasError(true); throw error; }); }, [integrationSlug, api, organization.slug]); useEffect(() => { fetchData(); }, [fetchData]); const loadingError = ( ); const testOnlyAlert = ( Platform documentation is not rendered in for tests in CI ); const renderSetupInstructions = () => { const currentPlatform = project?.platform ?? 'other'; return ( p.id === currentPlatform)?.name ?? '' )} platform={currentPlatform} /> ); }; const renderIntegrationInstructions = () => { if (!provider || !project) { return null; } return ( {renderSetupInstructions()} {tct( "Don't have have permissions to create a Cloudformation stack? [link:Invite your team instead].", { link: ( ); }; const renderPostInstallInstructions = () => { if (!project || !provider) { return null; } return ( {renderSetupInstructions()} { trackAnalytics('growth.onboarding_view_full_docs', { organization, }); }} href="https://docs.sentry.io/product/integrations/cloud-monitoring/aws-lambda/" > {t('View Full Documentation')} ); }; return ( {installed ? renderPostInstallInstructions() : renderIntegrationInstructions()} {getDynamicText({ value: !hasError ? null : loadingError, fixed: testOnlyAlert, })} ); } const DocsWrapper = styled(motion.div)``; DocsWrapper.defaultProps = { initial: {opacity: 0, y: 40}, animate: {opacity: 1, y: 0}, exit: {opacity: 0}, }; const StyledButtonBar = styled(ButtonBar)` margin-top: ${space(3)}; width: max-content; @media (max-width: ${p => p.theme.breakpoints.small}) { width: auto; grid-row-gap: ${space(1)}; grid-auto-flow: row; } `; export default IntegrationSetup;