@@ -15,6 +15,7 @@ import {getAllNonDeletedTransactions} from '@libs/MoneyRequestReportUtils';
1515import type { PlatformStackRouteProp } from '@libs/Navigation/PlatformStackNavigation/types' ;
1616import TransitionTracker from '@libs/Navigation/TransitionTracker' ;
1717import type { CancelHandle } from '@libs/Navigation/TransitionTracker' ;
18+ import { isSupportedInviteOnboardingChoice , isSupportedPendingInviteOnboarding } from '@libs/OnboardingUtils' ;
1819import { getFilteredReportActionsForReportView , getIOUActionForReportID , getOneTransactionThreadReportID , isCreatedAction } from '@libs/ReportActionsUtils' ;
1920import {
2021 isChatThread ,
@@ -134,6 +135,10 @@ function ReportFetchHandler() {
134135
135136 const isInviteOnboardingComplete = introSelected ?. isInviteOnboardingComplete ?? false ;
136137 const isOnboardingCompleted = onboarding ?. hasCompletedGuidedSetupFlow ?? false ;
138+ const isRegularOnboardingPending = ! ! introSelected && ! introSelected . inviteType && isSupportedInviteOnboardingChoice ( introSelected . choice ) && ! isOnboardingCompleted ;
139+ const isPendingInviteOnboarding = isSupportedPendingInviteOnboarding ( introSelected ) ;
140+ const onboardingSignal = introSelected ? `${ introSelected . choice ?? '' } :${ introSelected . inviteType ?? '' } :${ isInviteOnboardingComplete ? 'complete' : 'pending' } ` : '' ;
141+ const shouldDeferGuidedSetupOpenReport = ! ! isLoadingApp && ( isRegularOnboardingPending || isPendingInviteOnboarding ) ;
137142
138143 const fetchReport = useEffectEvent ( ( ) => {
139144 if ( reportMetadata . isOptimisticReport && report ?. type === CONST . REPORT . TYPE . CHAT && ! isPolicyExpenseChat ( report ) ) {
@@ -144,18 +149,12 @@ function ReportFetchHandler() {
144149 return ;
145150 }
146151
147- // When a user goes through onboarding for the first time , various tasks are created for chatting with Concierge.
152+ // When a user goes through guided setup , various tasks are created for chatting with Concierge.
148153 // If this function is called too early (while the application is still loading), we will not have information about policies,
149154 // which means we will not be able to obtain the correct link for one of the tasks.
150155 // More information here: https://github.com/Expensify/App/issues/71742
151- if ( isLoadingApp && introSelected && ! isOnboardingCompleted && ! isInviteOnboardingComplete ) {
152- const { choice, inviteType} = introSelected ;
153- const isInviteIOUorInvoice = inviteType === CONST . ONBOARDING_INVITE_TYPES . IOU || inviteType === CONST . ONBOARDING_INVITE_TYPES . INVOICE ;
154- const isInviteChoiceCorrect = choice === CONST . ONBOARDING_CHOICES . ADMIN || choice === CONST . ONBOARDING_CHOICES . SUBMIT || choice === CONST . ONBOARDING_CHOICES . CHAT_SPLIT ;
155-
156- if ( isInviteChoiceCorrect && ! isInviteIOUorInvoice ) {
157- return ;
158- }
156+ if ( shouldDeferGuidedSetupOpenReport ) {
157+ return ;
159158 }
160159
161160 openReport ( { reportID : reportIDFromRoute , introSelected, reportActionID : reportActionIDFromRoute , betas} ) ;
@@ -305,9 +304,10 @@ function ReportFetchHandler() {
305304 useEffect ( ( ) => {
306305 // This function is triggered when a user clicks on a link to navigate to a report.
307306 // For each link click, we retrieve the report data again, even though it may already be cached.
308- // There should be only one openReport execution per page start or navigating
307+ // Usually this triggers one openReport execution per page start or navigation. If guided setup is deferred while app data loads,
308+ // rerun once the defer signal clears so openReport includes the loaded onboarding data.
309309 fetchReport ( ) ;
310- } , [ route , isLinkedMessagePageReady , reportActionIDFromRoute ] ) ;
310+ } , [ route , isLinkedMessagePageReady , reportActionIDFromRoute , shouldDeferGuidedSetupOpenReport , onboardingSignal ] ) ;
311311
312312 useEffect ( ( ) => {
313313 // This function is only triggered when a user is invited to a room after opening the link.
0 commit comments