@@ -3,9 +3,7 @@ import useCurrentUserPersonalDetails from '@hooks/useCurrentUserPersonalDetails'
33import useOnyx from '@hooks/useOnyx' ;
44
55import { setSubmitMigrationModalShown } from '@userActions/User' ;
6- import { setOnboardingDeeplinkIntent } from '@userActions/Welcome' ;
76
8- import CONST from '@src/CONST' ;
97import ONYXKEYS from '@src/ONYXKEYS' ;
108
119import { hasCompletedGuidedSetupFlowSelector } from '@selectors/Onboarding' ;
@@ -15,10 +13,10 @@ import {useEffect, useRef} from 'react';
1513/**
1614 * Creates the Submit workspace requested by an `intent=submit` onboarding deeplink.
1715 *
18- * The link is sent to existing users, so it deliberately skips the onboarding UI entirely rather than pre-answering
19- * its questions: the workspace is created outright and the user lands wherever the "Submit to my employer" flow
20- * normally leaves them. Onboarding is suppressed for the whole session by useOnboardingFlowRouter and OnboardingGuard,
21- * both of which read the intent recorded here .
16+ * The link is only sent to existing users, so it acts solely on recipients who have already been through guided
17+ * setup: for them the workspace is created outright and they land wherever the "Submit to my employer" flow normally
18+ * leaves them. Anyone who still has onboarding ahead of them is left to it untouched, since that flow already offers
19+ * the Submit outcome .
2220 *
2321 * Only rendered once the deeplink has been recognised, so the Onyx subscriptions behind `useAutoCreateSubmitWorkspace`
2422 * are never set up for ordinary sessions.
@@ -34,30 +32,28 @@ function ApplySubmitOnboardingIntent() {
3432 const [ isOnboardingCompleted ] = useOnyx ( ONYXKEYS . NVP_ONBOARDING , { selector : hasCompletedGuidedSetupFlowSelector } ) ;
3533 const [ isSupportalSession ] = useOnyx ( ONYXKEYS . SESSION , { selector : isSupportalSessionSelector } ) ;
3634
37- const hasCreatedWorkspace = useRef ( false ) ;
35+ const hasRun = useRef ( false ) ;
3836
3937 useEffect ( ( ) => {
40- if ( isSupportalSession ) {
38+ if ( hasRun . current || ! hasLoadedApp || isOnboardingCompleted === undefined || isSupportalSession ) {
4139 return ;
4240 }
43- setOnboardingDeeplinkIntent ( CONST . ONBOARDING_INTENTS . SUBMIT ) ;
44- } , [ isSupportalSession ] ) ;
41+ hasRun . current = true ;
4542
46- useEffect ( ( ) => {
47- if ( hasCreatedWorkspace . current || ! hasLoadedApp || isOnboardingCompleted === undefined || isSupportalSession ) {
43+ // Recipients who never finished guided setup are left to the normal onboarding flow, which already offers
44+ // the Submit outcome.
45+ if ( ! isOnboardingCompleted ) {
4846 return ;
4947 }
50- hasCreatedWorkspace . current = true ;
5148
5249 // The deeplink delivers the same outcome as the Submit plan welcome modal, so record the modal as seen to
5350 // stop it from opening on top of the workspace we're about to create.
5451 setSubmitMigrationModalShown ( ) ;
5552
56- // Recipients who never finished guided setup still need it marked complete, otherwise they would be pulled
57- // into onboarding on their next sign-in. When the user already owns a Submit workspace,
53+ // Guided setup is already done, so it must not run again. When the user already owns a Submit workspace,
5854 // useAutoCreateSubmitWorkspace skips creation and navigates to that workspace instead, which is what makes
5955 // repeat clicks of the link idempotent.
60- autoCreateSubmitWorkspace ( firstName ?? '' , lastName ?? '' , ! isOnboardingCompleted ) ;
56+ autoCreateSubmitWorkspace ( firstName ?? '' , lastName ?? '' , false ) ;
6157 } , [ autoCreateSubmitWorkspace , firstName , hasLoadedApp , isOnboardingCompleted , isSupportalSession , lastName ] ) ;
6258
6359 return null ;
0 commit comments