@@ -7,7 +7,7 @@ import ConfirmModal from '@components/ConfirmModal';
7
7
import ErrorMessageRow from '@components/ErrorMessageRow' ;
8
8
import FullscreenLoadingIndicator from '@components/FullscreenLoadingIndicator' ;
9
9
import HeaderWithBackButton from '@components/HeaderWithBackButton' ;
10
- import * as Expensicons from '@components/Icon/Expensicons' ;
10
+ import { Star , Trashcan } from '@components/Icon/Expensicons' ;
11
11
import MenuItem from '@components/MenuItem' ;
12
12
import OfflineWithFeedback from '@components/OfflineWithFeedback' ;
13
13
import ScreenWrapper from '@components/ScreenWrapper' ;
@@ -20,14 +20,23 @@ import usePrevious from '@hooks/usePrevious';
20
20
import useTheme from '@hooks/useTheme' ;
21
21
import useThemeStyles from '@hooks/useThemeStyles' ;
22
22
import blurActiveElement from '@libs/Accessibility/blurActiveElement' ;
23
+ import {
24
+ clearContactMethod ,
25
+ clearContactMethodErrors ,
26
+ clearUnvalidatedNewContactMethodAction ,
27
+ deleteContactMethod ,
28
+ requestContactMethodValidateCode ,
29
+ resetContactMethodValidateCodeSentState ,
30
+ setContactMethodAsDefault ,
31
+ validateSecondaryLogin ,
32
+ } from '@libs/actions/User' ;
23
33
import { canUseTouchScreen } from '@libs/DeviceCapabilities' ;
24
- import * as ErrorUtils from '@libs/ErrorUtils' ;
34
+ import { getEarliestErrorField , getLatestErrorField } from '@libs/ErrorUtils' ;
25
35
import Navigation from '@libs/Navigation/Navigation' ;
26
36
import type { PlatformStackScreenProps } from '@libs/Navigation/PlatformStackNavigation/types' ;
27
37
import type { SettingsNavigatorParamList } from '@libs/Navigation/types' ;
28
38
import { addSMSDomainIfPhoneNumber } from '@libs/PhoneNumber' ;
29
- import * as Modal from '@userActions/Modal' ;
30
- import * as User from '@userActions/User' ;
39
+ import { close } from '@userActions/Modal' ;
31
40
import CONST from '@src/CONST' ;
32
41
import ONYXKEYS from '@src/ONYXKEYS' ;
33
42
import ROUTES from '@src/ROUTES' ;
@@ -80,13 +89,13 @@ function ContactMethodDetailsPage({route}: ContactMethodDetailsPageProps) {
80
89
} , [ route . params . contactMethod ] ) ;
81
90
const loginData = useMemo ( ( ) => loginList ?. [ contactMethod ] , [ loginList , contactMethod ] ) ;
82
91
const isDefaultContactMethod = useMemo ( ( ) => session ?. email === loginData ?. partnerUserID , [ session ?. email , loginData ?. partnerUserID ] ) ;
83
- const validateLoginError = ErrorUtils . getEarliestErrorField ( loginData , 'validateLogin' ) ;
92
+ const validateLoginError = getEarliestErrorField ( loginData , 'validateLogin' ) ;
84
93
85
94
/**
86
95
* Attempt to set this contact method as user's "Default contact method"
87
96
*/
88
97
const setAsDefault = useCallback ( ( ) => {
89
- User . setContactMethodAsDefault ( contactMethod , backTo ) ;
98
+ setContactMethodAsDefault ( contactMethod , backTo ) ;
90
99
} , [ contactMethod , backTo ] ) ;
91
100
92
101
/**
@@ -136,7 +145,7 @@ function ContactMethodDetailsPage({route}: ContactMethodDetailsPageProps) {
136
145
*/
137
146
const confirmDeleteAndHideModal = useCallback ( ( ) => {
138
147
toggleDeleteModal ( false ) ;
139
- User . deleteContactMethod ( contactMethod , loginList ?? { } , backTo ) ;
148
+ deleteContactMethod ( contactMethod , loginList ?? { } , backTo ) ;
140
149
} , [ contactMethod , loginList , toggleDeleteModal , backTo ] ) ;
141
150
142
151
const prevValidatedDate = usePrevious ( loginData ?. validatedDate ) ;
@@ -157,13 +166,17 @@ function ContactMethodDetailsPage({route}: ContactMethodDetailsPageProps) {
157
166
setIsValidateCodeActionModalVisible ( ! loginData ?. validatedDate ) ;
158
167
} , [ loginData ?. validatedDate , loginData ?. errorFields ?. addedLogin ] ) ;
159
168
169
+ useEffect ( ( ) => {
170
+ resetContactMethodValidateCodeSentState ( contactMethod ) ;
171
+ } , [ contactMethod ] ) ;
172
+
160
173
const getThreeDotsMenuItems = useCallback ( ( ) => {
161
174
const menuItems = [ ] ;
162
175
if ( isValidateCodeActionModalVisible && ! isDefaultContactMethod ) {
163
176
menuItems . push ( {
164
- icon : Expensicons . Trashcan ,
177
+ icon : Trashcan ,
165
178
text : translate ( 'common.remove' ) ,
166
- onSelected : ( ) => Modal . close ( ( ) => toggleDeleteModal ( true ) ) ,
179
+ onSelected : ( ) => close ( ( ) => toggleDeleteModal ( true ) ) ,
167
180
} ) ;
168
181
}
169
182
return menuItems ;
@@ -214,36 +227,36 @@ function ContactMethodDetailsPage({route}: ContactMethodDetailsPageProps) {
214
227
< >
215
228
{ canChangeDefaultContactMethod ? (
216
229
< OfflineWithFeedback
217
- errors = { ErrorUtils . getLatestErrorField ( loginData , 'defaultLogin' ) }
230
+ errors = { getLatestErrorField ( loginData , 'defaultLogin' ) }
218
231
errorRowStyles = { [ themeStyles . ml8 , themeStyles . mr5 ] }
219
- onClose = { ( ) => User . clearContactMethodErrors ( contactMethod , 'defaultLogin' ) }
232
+ onClose = { ( ) => clearContactMethodErrors ( contactMethod , 'defaultLogin' ) }
220
233
>
221
234
< MenuItem
222
235
title = { translate ( 'contacts.setAsDefault' ) }
223
- icon = { Expensicons . Star }
236
+ icon = { Star }
224
237
onPress = { setAsDefault }
225
238
/>
226
239
</ OfflineWithFeedback >
227
240
) : null }
228
241
{ isDefaultContactMethod ? (
229
242
< OfflineWithFeedback
230
243
pendingAction = { loginData . pendingFields ?. defaultLogin }
231
- errors = { ErrorUtils . getLatestErrorField ( loginData , isFailedRemovedContactMethod ? 'deletedLogin' : 'defaultLogin' ) }
244
+ errors = { getLatestErrorField ( loginData , isFailedRemovedContactMethod ? 'deletedLogin' : 'defaultLogin' ) }
232
245
errorRowStyles = { [ themeStyles . ml8 , themeStyles . mr5 ] }
233
- onClose = { ( ) => User . clearContactMethodErrors ( contactMethod , isFailedRemovedContactMethod ? 'deletedLogin' : 'defaultLogin' ) }
246
+ onClose = { ( ) => clearContactMethodErrors ( contactMethod , isFailedRemovedContactMethod ? 'deletedLogin' : 'defaultLogin' ) }
234
247
>
235
248
< Text style = { [ themeStyles . ph5 , themeStyles . mv3 ] } > { translate ( 'contacts.yourDefaultContactMethod' ) } </ Text >
236
249
</ OfflineWithFeedback >
237
250
) : (
238
251
< OfflineWithFeedback
239
252
pendingAction = { loginData . pendingFields ?. deletedLogin }
240
- errors = { ErrorUtils . getLatestErrorField ( loginData , 'deletedLogin' ) }
253
+ errors = { getLatestErrorField ( loginData , 'deletedLogin' ) }
241
254
errorRowStyles = { [ themeStyles . mt6 , themeStyles . ph5 ] }
242
- onClose = { ( ) => User . clearContactMethodErrors ( contactMethod , 'deletedLogin' ) }
255
+ onClose = { ( ) => clearContactMethodErrors ( contactMethod , 'deletedLogin' ) }
243
256
>
244
257
< MenuItem
245
258
title = { translate ( 'common.remove' ) }
246
- icon = { Expensicons . Trashcan }
259
+ icon = { Trashcan }
247
260
iconFill = { theme . danger }
248
261
onPress = { ( ) => toggleDeleteModal ( true ) }
249
262
/>
@@ -265,11 +278,11 @@ function ContactMethodDetailsPage({route}: ContactMethodDetailsPageProps) {
265
278
< ScrollView keyboardShouldPersistTaps = "handled" >
266
279
{ isFailedAddContactMethod && (
267
280
< ErrorMessageRow
268
- errors = { ErrorUtils . getLatestErrorField ( loginData , 'addedLogin' ) }
281
+ errors = { getLatestErrorField ( loginData , 'addedLogin' ) }
269
282
errorRowStyles = { [ themeStyles . mh5 , themeStyles . mv3 ] }
270
283
onClose = { ( ) => {
271
- User . clearContactMethod ( contactMethod ) ;
272
- User . clearUnvalidatedNewContactMethodAction ( ) ;
284
+ clearContactMethod ( contactMethod ) ;
285
+ clearUnvalidatedNewContactMethodAction ( ) ;
273
286
Navigation . goBack ( ROUTES . SETTINGS_CONTACT_METHODS . getRoute ( backTo ) ) ;
274
287
} }
275
288
canDismissError
@@ -282,14 +295,14 @@ function ContactMethodDetailsPage({route}: ContactMethodDetailsPageProps) {
282
295
hasMagicCodeBeenSent = { hasMagicCodeBeenSent }
283
296
isVisible = { isValidateCodeActionModalVisible && ! loginData . validatedDate && ! ! loginData }
284
297
validatePendingAction = { loginData . pendingFields ?. validateCodeSent }
285
- handleSubmitForm = { ( validateCode ) => User . validateSecondaryLogin ( loginList , contactMethod , validateCode ) }
286
- validateError = { ! isEmptyObject ( validateLoginError ) ? validateLoginError : ErrorUtils . getLatestErrorField ( loginData , 'validateCodeSent' ) }
287
- clearError = { ( ) => User . clearContactMethodErrors ( contactMethod , ! isEmptyObject ( validateLoginError ) ? 'validateLogin' : 'validateCodeSent' ) }
298
+ handleSubmitForm = { ( validateCode ) => validateSecondaryLogin ( loginList , contactMethod , validateCode ) }
299
+ validateError = { ! isEmptyObject ( validateLoginError ) ? validateLoginError : getLatestErrorField ( loginData , 'validateCodeSent' ) }
300
+ clearError = { ( ) => clearContactMethodErrors ( contactMethod , ! isEmptyObject ( validateLoginError ) ? 'validateLogin' : 'validateCodeSent' ) }
288
301
onClose = { ( ) => {
289
302
Navigation . goBack ( ROUTES . SETTINGS_CONTACT_METHODS . getRoute ( backTo ) ) ;
290
303
setIsValidateCodeActionModalVisible ( false ) ;
291
304
} }
292
- sendValidateCode = { ( ) => User . requestContactMethodValidateCode ( contactMethod ) }
305
+ sendValidateCode = { ( ) => requestContactMethodValidateCode ( contactMethod ) }
293
306
descriptionPrimary = { translate ( 'contacts.enterMagicCode' , { contactMethod : formattedContactMethod } ) }
294
307
onThreeDotsButtonPress = { ( ) => {
295
308
// Hide the keyboard when the user clicks the three-dot menu.
0 commit comments