Skip to content

Commit 7040383

Browse files
flodnvOSBotify
authored andcommitted
Merge pull request #76217 from software-mansion-labs/fix/browser-back-button-reopenes-same-page
(cherry picked from commit 188cb7d) (cherry-picked to staging by marcaaron)
1 parent 261ed3e commit 7040383

File tree

2 files changed

+16
-10
lines changed

2 files changed

+16
-10
lines changed

src/pages/ReimbursementAccount/ReimbursementAccountVerifyAccountPage.tsx

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import React from 'react';
2+
import Navigation from '@libs/Navigation/Navigation';
23
import type {PlatformStackScreenProps} from '@libs/Navigation/PlatformStackNavigation/types';
34
import type {SettingsNavigatorParamList} from '@libs/Navigation/types';
45
import VerifyAccountPageBase from '@pages/settings/VerifyAccountPageBase';
@@ -13,7 +14,9 @@ function ReimbursementAccountVerifyAccountPage({route}: ReimbursementAccountVeri
1314
return (
1415
<VerifyAccountPageBase
1516
navigateBackTo={ROUTES.BANK_ACCOUNT_WITH_STEP_TO_OPEN.getRoute(policyID, '', backTo)}
16-
navigateForwardTo={ROUTES.BANK_ACCOUNT_WITH_STEP_TO_OPEN.getRoute(policyID, '', backTo, CONST.BANK_ACCOUNT.STEP.COUNTRY)}
17+
handleClose={() => {
18+
Navigation.goBack(ROUTES.BANK_ACCOUNT_WITH_STEP_TO_OPEN.getRoute(policyID, '', backTo, CONST.BANK_ACCOUNT.STEP.COUNTRY), {compareParams: false});
19+
}}
1720
/>
1821
);
1922
}

src/pages/settings/VerifyAccountPageBase.tsx

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,12 @@ import ONYXKEYS from '@src/ONYXKEYS';
1313
import type {Route} from '@src/ROUTES';
1414
import {isEmptyObject} from '@src/types/utils/EmptyObject';
1515

16-
type VerifyAccountPageBaseProps = {navigateBackTo?: Route; navigateForwardTo?: Route};
16+
type VerifyAccountPageBaseProps = {navigateBackTo?: Route; navigateForwardTo?: Route; handleClose?: () => void};
1717

1818
/**
1919
* This is a base page as RHP for account verification. The back & forward url logic should be handled on per case basis in higher component.
2020
*/
21-
function VerifyAccountPageBase({navigateBackTo, navigateForwardTo}: VerifyAccountPageBaseProps) {
21+
function VerifyAccountPageBase({navigateBackTo, navigateForwardTo, handleClose}: VerifyAccountPageBaseProps) {
2222
const styles = useThemeStyles();
2323
const [account] = useOnyx(ONYXKEYS.ACCOUNT, {canBeMissing: true});
2424
const [loginList] = useOnyx(ONYXKEYS.LOGIN_LIST, {canBeMissing: true});
@@ -40,22 +40,25 @@ function VerifyAccountPageBase({navigateBackTo, navigateForwardTo}: VerifyAccoun
4040
[loginList, contactMethod, formatPhoneNumber],
4141
);
4242

43-
const handleClose = useCallback(() => {
43+
const handleCloseWithFallback = useCallback(() => {
44+
if (handleClose) {
45+
handleClose();
46+
return;
47+
}
4448
Navigation.goBack(navigateBackTo);
45-
}, [navigateBackTo]);
49+
}, [handleClose, navigateBackTo]);
4650

4751
// Handle navigation once the user is validated
4852
useEffect(() => {
4953
if (!isUserValidated) {
5054
return;
5155
}
52-
5356
if (navigateForwardTo) {
5457
Navigation.navigate(navigateForwardTo, {forceReplace: true});
5558
} else {
56-
handleClose();
59+
handleCloseWithFallback();
5760
}
58-
}, [isUserValidated, navigateForwardTo, handleClose]);
61+
}, [isUserValidated, navigateForwardTo, handleCloseWithFallback, handleClose]);
5962

6063
// Once user is validated or the modal is dismissed, we don't want to show empty content.
6164
if (isUserValidated) {
@@ -66,7 +69,7 @@ function VerifyAccountPageBase({navigateBackTo, navigateForwardTo}: VerifyAccoun
6669
>
6770
<HeaderWithBackButton
6871
title={translate('contacts.validateAccount')}
69-
onBackButtonPress={handleClose}
72+
onBackButtonPress={handleCloseWithFallback}
7073
/>
7174
<FullScreenLoadingIndicator style={[styles.flex1, styles.pRelative]} />
7275
</ScreenWrapper>
@@ -84,7 +87,7 @@ function VerifyAccountPageBase({navigateBackTo, navigateForwardTo}: VerifyAccoun
8487
handleSubmitForm={handleSubmitForm}
8588
validateError={!isEmptyObject(validateLoginError) ? validateLoginError : getLatestErrorField(loginData, 'validateCodeSent')}
8689
clearError={() => clearContactMethodErrors(contactMethod, !isEmptyObject(validateLoginError) ? 'validateLogin' : 'validateCodeSent')}
87-
onClose={handleClose}
90+
onClose={handleCloseWithFallback}
8891
/>
8992
);
9093
}

0 commit comments

Comments
 (0)