Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import React from 'react';
import Navigation from '@libs/Navigation/Navigation';
import type {PlatformStackScreenProps} from '@libs/Navigation/PlatformStackNavigation/types';
import type {SettingsNavigatorParamList} from '@libs/Navigation/types';
import VerifyAccountPageBase from '@pages/settings/VerifyAccountPageBase';
Expand All @@ -13,7 +14,9 @@ function ReimbursementAccountVerifyAccountPage({route}: ReimbursementAccountVeri
return (
<VerifyAccountPageBase
navigateBackTo={ROUTES.BANK_ACCOUNT_WITH_STEP_TO_OPEN.getRoute(policyID, '', backTo)}
navigateForwardTo={ROUTES.BANK_ACCOUNT_WITH_STEP_TO_OPEN.getRoute(policyID, '', backTo, CONST.BANK_ACCOUNT.STEP.COUNTRY)}
handleClose={() => {
Navigation.goBack(ROUTES.BANK_ACCOUNT_WITH_STEP_TO_OPEN.getRoute(policyID, '', backTo, CONST.BANK_ACCOUNT.STEP.COUNTRY), {compareParams: false});
}}
/>
);
}
Expand Down
21 changes: 12 additions & 9 deletions src/pages/settings/VerifyAccountPageBase.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,12 @@ import ONYXKEYS from '@src/ONYXKEYS';
import type {Route} from '@src/ROUTES';
import {isEmptyObject} from '@src/types/utils/EmptyObject';

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

/**
* 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.
*/
function VerifyAccountPageBase({navigateBackTo, navigateForwardTo}: VerifyAccountPageBaseProps) {
function VerifyAccountPageBase({navigateBackTo, navigateForwardTo, handleClose}: VerifyAccountPageBaseProps) {
const styles = useThemeStyles();
const [account] = useOnyx(ONYXKEYS.ACCOUNT, {canBeMissing: true});
const [loginList] = useOnyx(ONYXKEYS.LOGIN_LIST, {canBeMissing: true});
Expand All @@ -40,22 +40,25 @@ function VerifyAccountPageBase({navigateBackTo, navigateForwardTo}: VerifyAccoun
[loginList, contactMethod, formatPhoneNumber],
);

const handleClose = useCallback(() => {
const handleCloseWithFallback = useCallback(() => {
if (handleClose) {
handleClose();
return;
}
Navigation.goBack(navigateBackTo);
}, [navigateBackTo]);
}, [handleClose, navigateBackTo]);

// Handle navigation once the user is validated
useEffect(() => {
if (!isUserValidated) {
return;
}

if (navigateForwardTo) {
Navigation.navigate(navigateForwardTo, {forceReplace: true});
} else {
handleClose();
handleCloseWithFallback();
}
}, [isUserValidated, navigateForwardTo, handleClose]);
}, [isUserValidated, navigateForwardTo, handleCloseWithFallback, handleClose]);

// Once user is validated or the modal is dismissed, we don't want to show empty content.
if (isUserValidated) {
Expand All @@ -66,7 +69,7 @@ function VerifyAccountPageBase({navigateBackTo, navigateForwardTo}: VerifyAccoun
>
<HeaderWithBackButton
title={translate('contacts.validateAccount')}
onBackButtonPress={handleClose}
onBackButtonPress={handleCloseWithFallback}
/>
<FullScreenLoadingIndicator style={[styles.flex1, styles.pRelative]} />
</ScreenWrapper>
Expand All @@ -84,7 +87,7 @@ function VerifyAccountPageBase({navigateBackTo, navigateForwardTo}: VerifyAccoun
handleSubmitForm={handleSubmitForm}
validateError={!isEmptyObject(validateLoginError) ? validateLoginError : getLatestErrorField(loginData, 'validateCodeSent')}
clearError={() => clearContactMethodErrors(contactMethod, !isEmptyObject(validateLoginError) ? 'validateLogin' : 'validateCodeSent')}
onClose={handleClose}
onClose={handleCloseWithFallback}
/>
);
}
Expand Down
Loading