Skip to content

Commit fba471a

Browse files
authored
Merge pull request Expensify#86733 from Expensify/claude-fixMigratedUserWelcomeModal
Show migrated user welcome modal immediately and navigate to Home on dismiss
2 parents fd5edf6 + 2730bae commit fba471a

3 files changed

Lines changed: 44 additions & 3 deletions

File tree

src/components/MigratedUserWelcomeModal.tsx

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,11 @@ import {openExternalLink} from '@libs/actions/Link';
1111
import {dismissProductTraining} from '@libs/actions/Welcome';
1212
import convertToLTR from '@libs/convertToLTR';
1313
import Log from '@libs/Log';
14+
import Navigation from '@libs/Navigation/Navigation';
15+
import {buildCannedSearchQuery} from '@libs/SearchQueryUtils';
1416
import variables from '@styles/variables';
1517
import CONST from '@src/CONST';
18+
import ROUTES from '@src/ROUTES';
1619
import type {FeatureListItem} from './FeatureList';
1720
import FeatureTrainingModal from './FeatureTrainingModal';
1821
import Icon from './Icon';
@@ -58,6 +61,7 @@ function MigratedUserWelcomeModal() {
5861
const onClose = () => {
5962
Log.hmmm('[MigratedUserWelcomeModal] onClose called, dismissing product training');
6063
dismissProductTraining(CONST.MIGRATED_USER_WELCOME_MODAL);
64+
Navigation.navigate(ROUTES.SEARCH_ROOT.getRoute({query: buildCannedSearchQuery({type: CONST.SEARCH.DATA_TYPES.EXPENSE_REPORT})}));
6165
};
6266

6367
const featureListContent = (

src/libs/Navigation/guards/MigratedUserWelcomeModalGuard.ts

Lines changed: 37 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,29 +4,64 @@ import {tryNewDotOnyxSelector} from '@selectors/Onboarding';
44
import Onyx from 'react-native-onyx';
55
import type {OnyxEntry} from 'react-native-onyx';
66
import Log from '@libs/Log';
7+
import Navigation from '@libs/Navigation/Navigation';
78
import isProductTrainingElementDismissed from '@libs/TooltipUtils';
89
import CONST from '@src/CONST';
910
import NAVIGATORS from '@src/NAVIGATORS';
1011
import ONYXKEYS from '@src/ONYXKEYS';
1112
import ROUTES from '@src/ROUTES';
1213
import SCREENS from '@src/SCREENS';
13-
import type {DismissedProductTraining} from '@src/types/onyx';
14+
import type {DismissedProductTraining, Session} from '@src/types/onyx';
1415
import type {GuardResult, NavigationGuard} from './types';
1516

1617
let hasBeenAddedToNudgeMigration = false;
1718
let dismissedProductTraining: OnyxEntry<DismissedProductTraining>;
19+
let session: OnyxEntry<Session>;
20+
let isLoadingApp = true;
1821

1922
let hasRedirectedToMigratedUserModal = false;
2023

2124
function 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+
2559
Onyx.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

100135
export default MigratedUserWelcomeModalGuard;
101-
export {resetSessionFlag};
136+
export {resetSessionFlag, onSessionOrLoadingAppChanged};

src/libs/Navigation/guards/index.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import type {OnyxEntry} from 'react-native-onyx';
44
import getCurrentUrl from '@libs/Navigation/currentUrl';
55
import ONYXKEYS from '@src/ONYXKEYS';
66
import type {Session} from '@src/types/onyx';
7-
import MigratedUserWelcomeModalGuard from './MigratedUserWelcomeModalGuard';
7+
import MigratedUserWelcomeModalGuard, {onSessionOrLoadingAppChanged} from './MigratedUserWelcomeModalGuard';
88
import OnboardingGuard from './OnboardingGuard';
99
import type {GuardContext, GuardResult, NavigationGuard} from './types';
1010

@@ -19,13 +19,15 @@ Onyx.connectWithoutView({
1919
key: ONYXKEYS.SESSION,
2020
callback: (value) => {
2121
session = value;
22+
onSessionOrLoadingAppChanged(session, isLoadingApp);
2223
},
2324
});
2425

2526
Onyx.connectWithoutView({
2627
key: ONYXKEYS.IS_LOADING_APP,
2728
callback: (value) => {
2829
isLoadingApp = value ?? true;
30+
onSessionOrLoadingAppChanged(session, isLoadingApp);
2931
},
3032
});
3133

0 commit comments

Comments
 (0)