Skip to content

Commit 63dd544

Browse files
committed
ref(onboarding): Snapshot and navigate directly on wizard completion
The project-details hook now reports completion through a single onComplete carrying the created project and the submitted form, so the wizard no longer needs to accumulate those pieces in state and defer its snapshot-and-navigate to an effect waiting for the writes to commit. Snapshot the completed session and navigate synchronously, dropping the pendingNavigation effect, the slug ref, and the two setState handlers.
1 parent 4c0248a commit 63dd544

1 file changed

Lines changed: 21 additions & 46 deletions

File tree

static/app/views/projectInstall/scmCreateProject.tsx

Lines changed: 21 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import {Fragment, useCallback, useEffect, useRef, useState} from 'react';
1+
import {Fragment, useCallback, useState} from 'react';
22
import {LayoutGroup, motion} from 'framer-motion';
33

44
import {Button} from '@sentry/scraps/button';
@@ -16,7 +16,6 @@ import {IconProject} from 'sentry/icons';
1616
import {t, tct} from 'sentry/locale';
1717
import type {Integration, Repository} from 'sentry/types/integrations';
1818
import type {OnboardingSelectedSDK} from 'sentry/types/onboarding';
19-
import type {Project} from 'sentry/types/project';
2019
import {decodeScalar} from 'sentry/utils/queryString';
2120
import {useCanCreateProject} from 'sentry/utils/useCanCreateProject';
2221
import {useLocation} from 'sentry/utils/useLocation';
@@ -27,7 +26,10 @@ import {ScmIntegrationConnect} from 'sentry/views/onboarding/components/scmInteg
2726
import {ScmPlatformFeaturesCore} from 'sentry/views/onboarding/components/scmPlatformFeaturesCore';
2827
import {ScmProjectDetailsCore} from 'sentry/views/onboarding/components/scmProjectDetailsCore';
2928
import {useScmPlatformDetection} from 'sentry/views/onboarding/components/useScmPlatformDetection';
30-
import {useScmProjectDetails} from 'sentry/views/onboarding/components/useScmProjectDetails';
29+
import {
30+
type ScmProjectDetailsCompletion,
31+
useScmProjectDetails,
32+
} from 'sentry/views/onboarding/components/useScmProjectDetails';
3133
import {useScmProviders} from 'sentry/views/onboarding/components/useScmProviders';
3234
import {makeProjectsPathname} from 'sentry/views/projects/pathname';
3335

@@ -71,7 +73,7 @@ export function ScmCreateProject() {
7173
const projectId = decodeScalar(location.query.project);
7274

7375
// Snapshot of the last completed wizard session, written when a project is
74-
// created (see the navigation effect below). Restored when this mount is a
76+
// created (see handleComplete in the wizard). Restored when this mount is a
7577
// return from that project's getting-started page, whose back nav tags the
7678
// URL with referrer + project id (mirrors createProject's autofill
7779
// condition). Computed reactively rather than once at mount because the tag
@@ -121,12 +123,6 @@ function ScmCreateProjectWizard({initialState}: {initialState: WizardState}) {
121123

122124
useScmPlatformDetection(selectedRepository);
123125

124-
// Slug of the project to land on. Seeded from a restored session (reuse path)
125-
// and updated when a new project is created. Held in a ref so the deferred
126-
// navigation reads the latest value without a stale closure.
127-
const createdProjectSlugRef = useRef(createdProjectSlug);
128-
const [pendingNavigation, setPendingNavigation] = useState(false);
129-
130126
const completeRepoStep = () => {
131127
setState(s => ({...s, repoStepCompleted: true}));
132128
};
@@ -184,47 +180,28 @@ function ScmCreateProjectWizard({initialState}: {initialState: WizardState}) {
184180
setState(s => ({...s, projectDetailsForm: undefined}));
185181
}, [setState]);
186182

187-
const handleProjectDetailsFormChange = useCallback(
188-
(projectDetailsFormState: ProjectDetailsFormState | undefined) => {
189-
setState(s => ({...s, projectDetailsForm: projectDetailsFormState}));
190-
},
191-
[setState]
192-
);
193-
194-
const handleProjectCreated = useCallback(
195-
(project: Project) => {
196-
createdProjectSlugRef.current = project.slug;
197-
// Persist id + slug so a return from getting-started is recognized (id)
198-
// and the reuse check has the slug. Committed before navigation runs
199-
// (see the deferred-navigation effect below).
200-
setState(s => ({
201-
...s,
183+
// Snapshot the completed session (the created project's id validates the
184+
// return from getting-started, the slug feeds the reuse check, and the form
185+
// seeds the fields) so it can be restored later (see ScmCreateProject), then
186+
// leave for the project's getting-started page. Live wizard state never
187+
// holds the created project, so there is nothing to commit before unmount.
188+
const handleComplete = useCallback(
189+
({project, projectDetailsForm: submittedForm}: ScmProjectDetailsCompletion) => {
190+
writeStorageValue(WIZARD_STORAGE_KEY, {
191+
...wizardState,
202192
createdProjectId: project.id,
203193
createdProjectSlug: project.slug,
204-
}));
205-
},
206-
[setState]
207-
);
208-
209-
// Defer the getting-started navigation to an effect so the create-time state
210-
// writes above commit before the session is snapshotted here.
211-
const handleComplete = useCallback(() => {
212-
setPendingNavigation(true);
213-
}, []);
214-
215-
useEffect(() => {
216-
if (pendingNavigation && createdProjectSlugRef.current) {
217-
// Snapshot the completed session so a return from getting-started can
218-
// restore it (see ScmCreateProject).
219-
writeStorageValue(WIZARD_STORAGE_KEY, wizardState);
194+
projectDetailsForm: submittedForm,
195+
});
220196
navigate(
221197
makeProjectsPathname({
222-
path: `/${createdProjectSlugRef.current}/getting-started/`,
198+
path: `/${project.slug}/getting-started/`,
223199
organization,
224200
})
225201
);
226-
}
227-
}, [pendingNavigation, wizardState, navigate, organization]);
202+
},
203+
[wizardState, navigate, organization]
204+
);
228205

229206
const form = useScmProjectDetails({
230207
analyticsFlow: 'project-creation',
@@ -233,8 +210,6 @@ function ScmCreateProjectWizard({initialState}: {initialState: WizardState}) {
233210
selectedRepository,
234211
createdProjectSlug,
235212
projectDetailsForm,
236-
onProjectCreated: handleProjectCreated,
237-
onProjectDetailsFormChange: handleProjectDetailsFormChange,
238213
onComplete: handleComplete,
239214
});
240215

0 commit comments

Comments
 (0)