1
- import React , { useEffect } from 'react' ;
1
+ import React , { useEffect , useState } from 'react' ;
2
+ import type { ValueOf } from 'type-fest' ;
2
3
import DelegateNoAccessWrapper from '@components/DelegateNoAccessWrapper' ;
3
4
import HeaderWithBackButton from '@components/HeaderWithBackButton' ;
4
5
import ScreenWrapper from '@components/ScreenWrapper' ;
5
6
import SelectionList from '@components/SelectionList' ;
6
7
import RadioListItem from '@components/SelectionList/RadioListItem' ;
7
8
import Text from '@components/Text' ;
8
9
import TextLink from '@components/TextLink' ;
10
+ import useBeforeRemove from '@hooks/useBeforeRemove' ;
9
11
import useLocalize from '@hooks/useLocalize' ;
10
12
import useThemeStyles from '@hooks/useThemeStyles' ;
11
- import { clearDelegateRolePendingAction , requestValidationCode , updateDelegateRoleOptimistically } from '@libs/actions/Delegate' ;
13
+ import { clearDelegateRolePendingAction , updateDelegateRoleOptimistically } from '@libs/actions/Delegate' ;
12
14
import Navigation from '@libs/Navigation/Navigation' ;
13
15
import type { PlatformStackScreenProps } from '@libs/Navigation/PlatformStackNavigation/types' ;
14
16
import type { SettingsNavigatorParamList } from '@libs/Navigation/types' ;
15
17
import CONST from '@src/CONST' ;
16
- import ROUTES from '@src/ROUTES' ;
17
18
import type SCREENS from '@src/SCREENS' ;
18
19
import type { DelegateRole } from '@src/types/onyx/Account' ;
20
+ import UpdateDelegateMagicCodeModal from './UpdateDelegateMagicCodeModal' ;
19
21
20
22
type UpdateDelegateRolePageProps = PlatformStackScreenProps < SettingsNavigatorParamList , typeof SCREENS . SETTINGS . DELEGATE . UPDATE_DELEGATE_ROLE > ;
21
23
22
24
function UpdateDelegateRolePage ( { route} : UpdateDelegateRolePageProps ) {
23
25
const { translate} = useLocalize ( ) ;
24
26
const login = route . params . login ;
25
27
const currentRole = route . params . currentRole ;
28
+ const [ isValidateCodeActionModalVisible , setIsValidateCodeActionModalVisible ] = useState ( false ) ;
29
+ const [ newRole , setNewRole ] = useState < ValueOf < typeof CONST . DELEGATE_ROLE > | null > ( ) ;
26
30
27
31
const styles = useThemeStyles ( ) ;
28
32
const roleOptions = Object . values ( CONST . DELEGATE_ROLE ) . map ( ( role ) => ( {
@@ -33,6 +37,7 @@ function UpdateDelegateRolePage({route}: UpdateDelegateRolePageProps) {
33
37
isSelected : role === currentRole ,
34
38
} ) ) ;
35
39
40
+ useBeforeRemove ( ( ) => setIsValidateCodeActionModalVisible ( false ) ) ;
36
41
useEffect ( ( ) => {
37
42
updateDelegateRoleOptimistically ( login ?? '' , currentRole as DelegateRole ) ;
38
43
return ( ) => clearDelegateRolePendingAction ( login ) ;
@@ -72,13 +77,22 @@ function UpdateDelegateRolePage({route}: UpdateDelegateRolePageProps) {
72
77
Navigation . dismissModal ( ) ;
73
78
return ;
74
79
}
75
-
76
- requestValidationCode ( ) ;
77
- Navigation . navigate ( ROUTES . SETTINGS_UPDATE_DELEGATE_ROLE_MAGIC_CODE . getRoute ( login , option . value ) ) ;
80
+ setNewRole ( option ?. value ) ;
81
+ setIsValidateCodeActionModalVisible ( true ) ;
78
82
} }
79
83
sections = { [ { data : roleOptions } ] }
80
84
ListItem = { RadioListItem }
81
85
/>
86
+ { ! ! newRole && (
87
+ < UpdateDelegateMagicCodeModal
88
+ login = { login }
89
+ role = { newRole }
90
+ isValidateCodeActionModalVisible = { isValidateCodeActionModalVisible }
91
+ onClose = { ( ) => {
92
+ setIsValidateCodeActionModalVisible ( false ) ;
93
+ } }
94
+ />
95
+ ) }
82
96
</ DelegateNoAccessWrapper >
83
97
</ ScreenWrapper >
84
98
) ;
0 commit comments