|
1 | 1 | import {useFocusEffect, useNavigation, useRoute} from '@react-navigation/native'; |
2 | 2 | import React, {useCallback, useEffect, useRef} from 'react'; |
3 | | -import {View} from 'react-native'; |
| 3 | +import {InteractionManager, View} from 'react-native'; |
4 | 4 | import type {ValueOf} from 'type-fest'; |
5 | 5 | import HeaderWithBackButton from '@components/HeaderWithBackButton'; |
6 | 6 | import ScreenWrapper from '@components/ScreenWrapper'; |
7 | 7 | import ScrollView from '@components/ScrollView'; |
8 | 8 | import Text from '@components/Text'; |
9 | 9 | import ValidateCodeActionForm from '@components/ValidateCodeActionForm'; |
10 | 10 | import type {ValidateCodeFormHandle} from '@components/ValidateCodeActionModal/ValidateCodeForm/BaseValidateCodeForm'; |
| 11 | +import useCurrentUserPersonalDetails from '@hooks/useCurrentUserPersonalDetails'; |
11 | 12 | import useLocalize from '@hooks/useLocalize'; |
12 | 13 | import useOnyx from '@hooks/useOnyx'; |
13 | 14 | import useThemeStyles from '@hooks/useThemeStyles'; |
@@ -83,6 +84,9 @@ function AccountValidatePage() { |
83 | 84 | canBeMissing: true, |
84 | 85 | }); |
85 | 86 |
|
| 87 | + const [privateSubscription] = useOnyx(ONYXKEYS.NVP_PRIVATE_SUBSCRIPTION, {canBeMissing: true}); |
| 88 | + const currentUserPersonalDetails = useCurrentUserPersonalDetails(); |
| 89 | + |
86 | 90 | const {params} = useRoute<PlatformStackRouteProp<SettingsNavigatorParamList, typeof SCREENS.SETTINGS.MERGE_ACCOUNTS.ACCOUNT_VALIDATE>>(); |
87 | 91 |
|
88 | 92 | const email = params.login ?? ''; |
@@ -116,6 +120,22 @@ function AccountValidatePage() { |
116 | 120 | }, [errorPage, email]), |
117 | 121 | ); |
118 | 122 |
|
| 123 | + useFocusEffect( |
| 124 | + useCallback(() => { |
| 125 | + const task = InteractionManager.runAfterInteractions(() => { |
| 126 | + if (privateSubscription?.type !== CONST.SUBSCRIPTION.TYPE.INVOICING) { |
| 127 | + return; |
| 128 | + } |
| 129 | + |
| 130 | + Navigation.navigate( |
| 131 | + ROUTES.SETTINGS_MERGE_ACCOUNTS_RESULT.getRoute(currentUserPersonalDetails.login ?? '', CONST.MERGE_ACCOUNT_RESULTS.ERR_INVOICING, ROUTES.SETTINGS_SECURITY), |
| 132 | + ); |
| 133 | + }); |
| 134 | + |
| 135 | + return () => task.cancel(); |
| 136 | + }, [privateSubscription?.type, currentUserPersonalDetails.login]), |
| 137 | + ); |
| 138 | + |
119 | 139 | useEffect(() => { |
120 | 140 | const unsubscribe = navigation.addListener('blur', () => { |
121 | 141 | clearGetValidateCodeForAccountMerge(); |
|
0 commit comments