@@ -13,12 +13,12 @@ import ONYXKEYS from '@src/ONYXKEYS';
1313import type { Route } from '@src/ROUTES' ;
1414import { 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