@@ -4,29 +4,64 @@ import {tryNewDotOnyxSelector} from '@selectors/Onboarding';
44import Onyx from 'react-native-onyx' ;
55import type { OnyxEntry } from 'react-native-onyx' ;
66import Log from '@libs/Log' ;
7+ import Navigation from '@libs/Navigation/Navigation' ;
78import isProductTrainingElementDismissed from '@libs/TooltipUtils' ;
89import CONST from '@src/CONST' ;
910import NAVIGATORS from '@src/NAVIGATORS' ;
1011import ONYXKEYS from '@src/ONYXKEYS' ;
1112import ROUTES from '@src/ROUTES' ;
1213import SCREENS from '@src/SCREENS' ;
13- import type { DismissedProductTraining } from '@src/types/onyx' ;
14+ import type { DismissedProductTraining , Session } from '@src/types/onyx' ;
1415import type { GuardResult , NavigationGuard } from './types' ;
1516
1617let hasBeenAddedToNudgeMigration = false ;
1718let dismissedProductTraining : OnyxEntry < DismissedProductTraining > ;
19+ let session : OnyxEntry < Session > ;
20+ let isLoadingApp = true ;
1821
1922let hasRedirectedToMigratedUserModal = false ;
2023
2124function resetSessionFlag ( ) {
2225 hasRedirectedToMigratedUserModal = false ;
2326}
2427
28+ /**
29+ * Proactively navigate to the migrated user welcome modal when all conditions are met,
30+ * without waiting for a user-initiated navigation action.
31+ */
32+ function navigateToMigratedUserWelcomeModalIfReady ( ) {
33+ if (
34+ ! session ?. authToken ||
35+ isLoadingApp ||
36+ hasRedirectedToMigratedUserModal ||
37+ ! hasBeenAddedToNudgeMigration ||
38+ isProductTrainingElementDismissed ( 'migratedUserWelcomeModal' , dismissedProductTraining )
39+ ) {
40+ return ;
41+ }
42+
43+ Log . info ( '[MigratedUserWelcomeModalGuard] Proactively navigating to migrated user welcome modal' ) ;
44+ hasRedirectedToMigratedUserModal = true ;
45+ Navigation . navigate ( ROUTES . MIGRATED_USER_WELCOME_MODAL . getRoute ( ) ) ;
46+ }
47+
48+ /**
49+ * Called by guards/index.ts when session or loading app state changes.
50+ * Reuses the shared Onyx subscriptions from guards/index.ts to avoid duplicate connections
51+ * that cause extra renders in performance tests.
52+ */
53+ function onSessionOrLoadingAppChanged ( sessionValue : OnyxEntry < Session > , isLoadingAppValue : boolean ) {
54+ session = sessionValue ;
55+ isLoadingApp = isLoadingAppValue ;
56+ navigateToMigratedUserWelcomeModalIfReady ( ) ;
57+ }
58+
2559Onyx . connectWithoutView ( {
2660 key : ONYXKEYS . NVP_TRY_NEW_DOT ,
2761 callback : ( value ) => {
2862 const result = value ? tryNewDotOnyxSelector ( value ) : undefined ;
2963 hasBeenAddedToNudgeMigration = result ?. hasBeenAddedToNudgeMigration ?? false ;
64+ navigateToMigratedUserWelcomeModalIfReady ( ) ;
3065 } ,
3166} ) ;
3267
@@ -98,4 +133,4 @@ const MigratedUserWelcomeModalGuard: NavigationGuard = {
98133} ;
99134
100135export default MigratedUserWelcomeModalGuard ;
101- export { resetSessionFlag } ;
136+ export { resetSessionFlag , onSessionOrLoadingAppChanged } ;
0 commit comments