Skip to content

Commit 41c675b

Browse files
authored
Merge pull request Expensify#66176 from callstack-internal/VickyStash/bugfix/improve-onboardingInitialPath-check
Improve `onboardingInitialPath` check
2 parents 56a72db + bf3a5c1 commit 41c675b

6 files changed

Lines changed: 60 additions & 26 deletions

File tree

src/Expensify.tsx

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,9 @@ function Expensify() {
102102
const [isSidebarLoaded] = useOnyx(ONYXKEYS.IS_SIDEBAR_LOADED, {canBeMissing: true});
103103
const [screenShareRequest] = useOnyx(ONYXKEYS.SCREEN_SHARE_REQUEST, {canBeMissing: true});
104104
const [lastVisitedPath] = useOnyx(ONYXKEYS.LAST_VISITED_PATH, {canBeMissing: true});
105+
const [currentOnboardingPurposeSelected] = useOnyx(ONYXKEYS.ONBOARDING_PURPOSE_SELECTED, {canBeMissing: true});
106+
const [currentOnboardingCompanySize] = useOnyx(ONYXKEYS.ONBOARDING_COMPANY_SIZE, {canBeMissing: true});
107+
const [onboardingInitialPath] = useOnyx(ONYXKEYS.ONBOARDING_LAST_VISITED_PATH, {canBeMissing: true});
105108

106109
useDebugShortcut();
107110
usePriorityMode();
@@ -206,12 +209,12 @@ function Expensify() {
206209
// If the app is opened from a deep link, get the reportID (if exists) from the deep link and navigate to the chat report
207210
Linking.getInitialURL().then((url) => {
208211
setInitialUrl(url as Route);
209-
Report.openReportFromDeepLink(url ?? '');
212+
Report.openReportFromDeepLink(url ?? '', currentOnboardingPurposeSelected, currentOnboardingCompanySize, onboardingInitialPath);
210213
});
211214

212215
// Open chat report from a deep link (only mobile native)
213216
Linking.addEventListener('url', (state) => {
214-
Report.openReportFromDeepLink(state.url);
217+
Report.openReportFromDeepLink(state.url, currentOnboardingPurposeSelected, currentOnboardingCompanySize, onboardingInitialPath);
215218
});
216219
if (CONFIG.IS_HYBRID_APP) {
217220
HybridAppModule.onURLListenerAdded();

src/hooks/useOnboardingFlow.ts

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,10 @@ function useOnboardingFlowRouter() {
2424
const [onboardingValues, isOnboardingCompletedMetadata] = useOnyx(ONYXKEYS.NVP_ONBOARDING, {
2525
canBeMissing: true,
2626
});
27+
const [currentOnboardingPurposeSelected] = useOnyx(ONYXKEYS.ONBOARDING_PURPOSE_SELECTED, {canBeMissing: true});
28+
const [currentOnboardingCompanySize] = useOnyx(ONYXKEYS.ONBOARDING_COMPANY_SIZE, {canBeMissing: true});
29+
const [onboardingInitialPath, onboardingInitialPathResult] = useOnyx(ONYXKEYS.ONBOARDING_LAST_VISITED_PATH, {canBeMissing: true});
30+
const isOnboardingInitialPathLoading = isLoadingOnyxValue(onboardingInitialPathResult);
2731

2832
const [account] = useOnyx(ONYXKEYS.ACCOUNT, {canBeMissing: true});
2933
const [sessionEmail] = useOnyx(ONYXKEYS.SESSION, {canBeMissing: true, selector: (session) => session?.email});
@@ -46,7 +50,7 @@ function useOnboardingFlowRouter() {
4650
if (currentUrl?.includes(ROUTES.TRANSITION_BETWEEN_APPS) && isLoggingInAsNewSessionUser) {
4751
return;
4852
}
49-
if (isLoadingApp !== false) {
53+
if (isLoadingApp !== false || isOnboardingInitialPathLoading) {
5054
return;
5155
}
5256

@@ -90,6 +94,9 @@ function useOnboardingFlowRouter() {
9094
onboardingValuesParam: onboardingValues,
9195
isUserFromPublicDomain: !!account?.isFromPublicDomain,
9296
hasAccessiblePolicies: !!account?.hasAccessibleDomainPolicies,
97+
currentOnboardingCompanySize,
98+
currentOnboardingPurposeSelected,
99+
onboardingInitialPath,
93100
});
94101
}
95102
}
@@ -101,6 +108,9 @@ function useOnboardingFlowRouter() {
101108
onboardingValuesParam: onboardingValues,
102109
isUserFromPublicDomain: !!account?.isFromPublicDomain,
103110
hasAccessiblePolicies: !!account?.hasAccessibleDomainPolicies,
111+
currentOnboardingCompanySize,
112+
currentOnboardingPurposeSelected,
113+
onboardingInitialPath,
104114
});
105115
}
106116
});
@@ -120,6 +130,10 @@ function useOnboardingFlowRouter() {
120130
account?.hasAccessibleDomainPolicies,
121131
currentUrl,
122132
isLoggingInAsNewSessionUser,
133+
currentOnboardingCompanySize,
134+
currentOnboardingPurposeSelected,
135+
onboardingInitialPath,
136+
isOnboardingInitialPathLoading,
123137
]);
124138

125139
return {isOnboardingCompleted: hasCompletedGuidedSetupFlowSelector(onboardingValues), isHybridAppOnboardingCompleted};

src/libs/Navigation/NavigationRoot.tsx

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,9 @@ function NavigationRoot({authenticated, lastVisitedPath, initialUrl, onReady}: N
104104
canBeMissing: true,
105105
});
106106
const [hasNonPersonalPolicy] = useOnyx(ONYXKEYS.HAS_NON_PERSONAL_POLICY, {canBeMissing: true});
107+
const [currentOnboardingPurposeSelected] = useOnyx(ONYXKEYS.ONBOARDING_PURPOSE_SELECTED, {canBeMissing: true});
108+
const [currentOnboardingCompanySize] = useOnyx(ONYXKEYS.ONBOARDING_COMPANY_SIZE, {canBeMissing: true});
109+
const [onboardingInitialPath] = useOnyx(ONYXKEYS.ONBOARDING_LAST_VISITED_PATH, {canBeMissing: true});
107110

108111
const previousAuthenticated = usePrevious(authenticated);
109112

@@ -135,6 +138,9 @@ function NavigationRoot({authenticated, lastVisitedPath, initialUrl, onReady}: N
135138
getOnboardingInitialPath({
136139
isUserFromPublicDomain: !!account.isFromPublicDomain,
137140
hasAccessiblePolicies: !!account.hasAccessibleDomainPolicies,
141+
currentOnboardingPurposeSelected,
142+
currentOnboardingCompanySize,
143+
onboardingInitialPath,
138144
}),
139145
linkingConfig.config,
140146
);

src/libs/actions/Report.ts

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3361,7 +3361,12 @@ function doneCheckingPublicRoom() {
33613361
Onyx.set(ONYXKEYS.IS_CHECKING_PUBLIC_ROOM, false);
33623362
}
33633363

3364-
function openReportFromDeepLink(url: string) {
3364+
function openReportFromDeepLink(
3365+
url: string,
3366+
currentOnboardingPurposeSelected: OnyxEntry<OnboardingPurpose>,
3367+
currentOnboardingCompanySize: OnyxEntry<OnboardingCompanySize>,
3368+
onboardingInitialPath: OnyxEntry<string>,
3369+
) {
33653370
const reportID = getReportIDFromLink(url);
33663371
const isAuthenticated = hasAuthToken();
33673372

@@ -3468,6 +3473,9 @@ function openReportFromDeepLink(url: string) {
34683473
onboardingValuesParam: val,
34693474
hasAccessiblePolicies: !!account?.hasAccessibleDomainPolicies,
34703475
isUserFromPublicDomain: !!account?.isFromPublicDomain,
3476+
currentOnboardingPurposeSelected,
3477+
currentOnboardingCompanySize,
3478+
onboardingInitialPath,
34713479
}),
34723480
onCompleted: handleDeeplinkNavigation,
34733481
onCanceled: handleDeeplinkNavigation,

src/libs/actions/Welcome/OnboardingFlow.ts

Lines changed: 25 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import {findFocusedRoute, getStateFromPath} from '@react-navigation/native';
22
import type {NavigationState, PartialState} from '@react-navigation/native';
3+
import type {OnyxEntry} from 'react-native-onyx';
34
import Onyx from 'react-native-onyx';
45
import type {ValueOf} from 'type-fest';
56
import {translate} from '@libs/Localize';
@@ -15,18 +16,6 @@ import ONYXKEYS from '@src/ONYXKEYS';
1516
import ROUTES from '@src/ROUTES';
1617
import type {Locale, Onboarding} from '@src/types/onyx';
1718

18-
let onboardingInitialPath = '';
19-
const onboardingLastVisitedPathConnection = Onyx.connect({
20-
key: ONYXKEYS.ONBOARDING_LAST_VISITED_PATH,
21-
callback: (value) => {
22-
if (value === undefined) {
23-
return;
24-
}
25-
onboardingInitialPath = value;
26-
Onyx.disconnect(onboardingLastVisitedPathConnection);
27-
},
28-
});
29-
3019
let onboardingValues: Onboarding;
3120
Onyx.connect({
3221
key: ONYXKEYS.NVP_ONBOARDING,
@@ -38,15 +27,18 @@ Onyx.connect({
3827
},
3928
});
4029

30+
type OnboardingCompanySize = ValueOf<typeof CONST.ONBOARDING_COMPANY_SIZE>;
31+
type OnboardingPurpose = ValueOf<typeof CONST.ONBOARDING_CHOICES>;
32+
4133
type GetOnboardingInitialPathParamsType = {
4234
isUserFromPublicDomain: boolean;
4335
hasAccessiblePolicies: boolean;
4436
onboardingValuesParam?: Onboarding;
37+
currentOnboardingPurposeSelected: OnyxEntry<OnboardingPurpose>;
38+
currentOnboardingCompanySize: OnyxEntry<OnboardingCompanySize>;
39+
onboardingInitialPath: OnyxEntry<string>;
4540
};
4641

47-
type OnboardingCompanySize = ValueOf<typeof CONST.ONBOARDING_COMPANY_SIZE>;
48-
type OnboardingPurpose = ValueOf<typeof CONST.ONBOARDING_CHOICES>;
49-
5042
type OnboardingTaskLinks = Partial<{
5143
onboardingCompanySize: OnboardingCompanySize;
5244
integrationName: string;
@@ -100,12 +92,20 @@ function startOnboardingFlow(startOnboardingFlowParams: GetOnboardingInitialPath
10092
}
10193

10294
function getOnboardingInitialPath(getOnboardingInitialPathParams: GetOnboardingInitialPathParamsType): string {
103-
const {isUserFromPublicDomain, hasAccessiblePolicies, onboardingValuesParam} = getOnboardingInitialPathParams;
95+
const {
96+
isUserFromPublicDomain,
97+
hasAccessiblePolicies,
98+
onboardingValuesParam,
99+
currentOnboardingPurposeSelected,
100+
currentOnboardingCompanySize,
101+
onboardingInitialPath = '',
102+
} = getOnboardingInitialPathParams;
104103
const state = getStateFromPath(onboardingInitialPath, linkingConfig.config);
105104
const currentOnboardingValues = onboardingValuesParam ?? onboardingValues;
106105
const isVsb = currentOnboardingValues?.signupQualifier === CONST.ONBOARDING_SIGNUP_QUALIFIERS.VSB;
107106
const isSmb = currentOnboardingValues?.signupQualifier === CONST.ONBOARDING_SIGNUP_QUALIFIERS.SMB;
108107
const isIndividual = currentOnboardingValues?.signupQualifier === CONST.ONBOARDING_SIGNUP_QUALIFIERS.INDIVIDUAL;
108+
const isCurrentOnboardingPurposeManageTeam = currentOnboardingPurposeSelected === CONST.ONBOARDING_CHOICES.MANAGE_TEAM;
109109

110110
if (isVsb) {
111111
Onyx.set(ONYXKEYS.ONBOARDING_PURPOSE_SELECTED, CONST.ONBOARDING_CHOICES.MANAGE_TEAM);
@@ -137,6 +137,14 @@ function getOnboardingInitialPath(getOnboardingInitialPathParams: GetOnboardingI
137137
return `/${ROUTES.ONBOARDING_ROOT.route}`;
138138
}
139139

140+
if (onboardingInitialPath.includes(ROUTES.ONBOARDING_EMPLOYEES.route) && !isCurrentOnboardingPurposeManageTeam) {
141+
return `/${ROUTES.ONBOARDING_PURPOSE.route}`;
142+
}
143+
144+
if (onboardingInitialPath.includes(ROUTES.ONBOARDING_ACCOUNTING.route) && (!isCurrentOnboardingPurposeManageTeam || !currentOnboardingCompanySize)) {
145+
return `/${ROUTES.ONBOARDING_PURPOSE.route}`;
146+
}
147+
140148
return onboardingInitialPath;
141149
}
142150

@@ -382,8 +390,5 @@ const getOnboardingMessages = (locale?: Locale) => {
382390
};
383391
};
384392

385-
function clearInitialPath() {
386-
onboardingInitialPath = '';
387-
}
388393
export type {OnboardingMessage, OnboardingTask, OnboardingTaskLinks, OnboardingPurpose, OnboardingCompanySize};
389-
export {getOnboardingInitialPath, startOnboardingFlow, clearInitialPath, getOnboardingMessages};
394+
export {getOnboardingInitialPath, startOnboardingFlow, getOnboardingMessages};

src/libs/actions/Welcome/index.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ import type {OnboardingPurpose} from '@src/types/onyx';
1414
import type Onboarding from '@src/types/onyx/Onboarding';
1515
import type TryNewDot from '@src/types/onyx/TryNewDot';
1616
import {isEmptyObject} from '@src/types/utils/EmptyObject';
17-
import {clearInitialPath} from './OnboardingFlow';
1817
import type {OnboardingCompanySize} from './OnboardingFlow';
1918

2019
type OnboardingData = Onboarding | undefined;
@@ -200,7 +199,6 @@ function resetAllChecks() {
200199
});
201200
isLoadingReportData = true;
202201
isOnboardingInProgress = false;
203-
clearInitialPath();
204202
}
205203

206204
function setSelfTourViewed(shouldUpdateOnyxDataOnlyLocally = false) {

0 commit comments

Comments
 (0)