1
+ import type { RouteProp } from '@react-navigation/native' ;
2
+ import { useRoute } from '@react-navigation/native' ;
1
3
import React , { useEffect , useMemo , useState } from 'react' ;
2
4
import { ActivityIndicator , View } from 'react-native' ;
3
5
import { useOnyx } from 'react-native-onyx' ;
@@ -19,14 +21,15 @@ import {READ_COMMANDS} from '@libs/API/types';
19
21
import Clipboard from '@libs/Clipboard' ;
20
22
import * as ErrorUtils from '@libs/ErrorUtils' ;
21
23
import localFileDownload from '@libs/localFileDownload' ;
22
- import type { BackToParams } from '@libs/Navigation/types' ;
24
+ import type { BackToParams , SettingsNavigatorParamList } from '@libs/Navigation/types' ;
23
25
import StepWrapper from '@pages/settings/Security/TwoFactorAuth/StepWrapper/StepWrapper' ;
24
26
import useTwoFactorAuthContext from '@pages/settings/Security/TwoFactorAuth/TwoFactorAuthContext/useTwoFactorAuth' ;
25
27
import * as Session from '@userActions/Session' ;
26
28
import * as TwoFactorAuthActions from '@userActions/TwoFactorAuthActions' ;
27
29
import * as User from '@userActions/User' ;
28
30
import CONST from '@src/CONST' ;
29
31
import ONYXKEYS from '@src/ONYXKEYS' ;
32
+ import type SCREENS from '@src/SCREENS' ;
30
33
import { isEmptyObject } from '@src/types/utils/EmptyObject' ;
31
34
32
35
type CodesStepProps = BackToParams ;
@@ -46,6 +49,7 @@ function CodesStep({backTo}: CodesStepProps) {
46
49
47
50
const isUserValidated = user ?. validated ;
48
51
const contactMethod = account ?. primaryLogin ?? '' ;
52
+ const route = useRoute < RouteProp < SettingsNavigatorParamList , typeof SCREENS . SETTINGS . TWO_FACTOR_AUTH > > ( ) ;
49
53
50
54
const loginData = useMemo ( ( ) => loginList ?. [ contactMethod ] , [ loginList , contactMethod ] ) ;
51
55
const validateLoginError = ErrorUtils . getEarliestErrorField ( loginData , 'validateLogin' ) ;
@@ -73,7 +77,7 @@ function CodesStep({backTo}: CodesStepProps) {
73
77
} }
74
78
// When the 2FA code step is open from Xero flow, we don't need to pass backTo because we build the necessary root route
75
79
// from the backTo param in the route (in getMatchingRootRouteForRHPRoute) and goBack will not need a fallbackRoute.
76
- onBackButtonPress = { ( ) => TwoFactorAuthActions . quitAndNavigateBack ( route . params . forwardTo ?. includes ( READ_COMMANDS . CONNECT_POLICY_TO_XERO ) ? '' : backTo ) }
80
+ onBackButtonPress = { ( ) => TwoFactorAuthActions . quitAndNavigateBack ( route ? .params ? .forwardTo ?. includes ( READ_COMMANDS . CONNECT_POLICY_TO_XERO ) ? '' : backTo ) }
77
81
>
78
82
< ScrollView contentContainerStyle = { styles . flexGrow1 } >
79
83
{ ! ! isUserValidated && (
0 commit comments