1
1
import { Str } from 'expensify-common' ;
2
2
import React , { forwardRef , useEffect , useImperativeHandle , useRef , useState } from 'react' ;
3
- import type { ForwardedRef , RefAttributes } from 'react' ;
4
- import { withOnyx } from 'react-native-onyx' ;
3
+ import type { ForwardedRef } from 'react' ;
5
4
import type { OnyxEntry } from 'react-native-onyx' ;
5
+ import { useOnyx } from 'react-native-onyx' ;
6
6
import ColorSchemeWrapper from '@components/ColorSchemeWrapper' ;
7
7
import CustomStatusBarAndBackground from '@components/CustomStatusBarAndBackground' ;
8
8
import ScreenWrapper from '@components/ScreenWrapper' ;
@@ -24,7 +24,7 @@ import * as Session from '@userActions/Session';
24
24
import CONST from '@src/CONST' ;
25
25
import ONYXKEYS from '@src/ONYXKEYS' ;
26
26
import ROUTES from '@src/ROUTES' ;
27
- import type { Account , Credentials , Locale } from '@src/types/onyx' ;
27
+ import type { Account , Credentials } from '@src/types/onyx' ;
28
28
import { isEmptyObject } from '@src/types/utils/EmptyObject' ;
29
29
import ChooseSSOOrMagicCode from './ChooseSSOOrMagicCode' ;
30
30
import EmailDeliveryFailurePage from './EmailDeliveryFailurePage' ;
@@ -33,25 +33,12 @@ import type {InputHandle} from './LoginForm/types';
33
33
import SignInPageLayout from './SignInPageLayout' ;
34
34
import type { SignInPageLayoutRef } from './SignInPageLayout/types' ;
35
35
import SignUpWelcomeForm from './SignUpWelcomeForm' ;
36
+ import SMSDeliveryFailurePage from './SMSDeliveryFailurePage' ;
36
37
import UnlinkLoginForm from './UnlinkLoginForm' ;
37
38
import ValidateCodeForm from './ValidateCodeForm' ;
38
39
import type { BaseValidateCodeFormRef } from './ValidateCodeForm/BaseValidateCodeForm' ;
39
40
40
- type SignInPageInnerOnyxProps = {
41
- /** The details about the account that the user is signing in with */
42
- account : OnyxEntry < Account > ;
43
-
44
- /** The credentials of the person signing in */
45
- credentials : OnyxEntry < Credentials > ;
46
-
47
- /** Active Clients connected to ONYX Database */
48
- activeClients : OnyxEntry < string [ ] > ;
49
-
50
- /** The user's preferred locale */
51
- preferredLocale : OnyxEntry < Locale > ;
52
- } ;
53
-
54
- type SignInPageInnerProps = SignInPageInnerOnyxProps & {
41
+ type SignInPageInnerProps = {
55
42
shouldEnableMaxHeight ?: boolean ;
56
43
} ;
57
44
@@ -62,6 +49,7 @@ type SignInPageRef = {
62
49
type RenderOption = {
63
50
shouldShowLoginForm : boolean ;
64
51
shouldShowEmailDeliveryFailurePage : boolean ;
52
+ shouldShowSMSDeliveryFailurePage : boolean ;
65
53
shouldShowUnlinkLoginForm : boolean ;
66
54
shouldShowValidateCodeForm : boolean ;
67
55
shouldShowChooseSSOOrMagicCode : boolean ;
@@ -90,6 +78,7 @@ type GetRenderOptionsParams = {
90
78
* @param isUsingMagicCode
91
79
* @param hasInitiatedSAMLLogin
92
80
* @param hasEmailDeliveryFailure
81
+ * @param hasSMSDeliveryFailure
93
82
*/
94
83
function getRenderOptions ( {
95
84
hasLogin,
@@ -105,6 +94,7 @@ function getRenderOptions({
105
94
const isSAMLEnabled = ! ! account ?. isSAMLEnabled ;
106
95
const isSAMLRequired = ! ! account ?. isSAMLRequired ;
107
96
const hasEmailDeliveryFailure = ! ! account ?. hasEmailDeliveryFailure ;
97
+ const hasSMSDeliveryFailure = ! ! account ?. SMSDeliveryFailureStatus ?. hasSMSDeliveryFailure ;
108
98
109
99
// True, if the user has SAML required, and we haven't yet initiated SAML for their account
110
100
const shouldInitiateSAMLLogin = hasAccount && hasLogin && isSAMLRequired && ! hasInitiatedSAMLLogin && ! ! account . isLoading ;
@@ -121,13 +111,15 @@ function getRenderOptions({
121
111
const shouldShouldSignUpWelcomeForm = ! ! credentials ?. login && ! account ?. validated && ! account ?. accountExists && ! account ?. domainControlled ;
122
112
const shouldShowLoginForm = ! shouldShowAnotherLoginPageOpenedMessage && ! hasLogin && ! hasValidateCode ;
123
113
const shouldShowEmailDeliveryFailurePage = hasLogin && hasEmailDeliveryFailure && ! shouldShowChooseSSOOrMagicCode && ! shouldInitiateSAMLLogin ;
124
- const isUnvalidatedSecondaryLogin = hasLogin && ! isPrimaryLogin && ! account ?. validated && ! hasEmailDeliveryFailure ;
114
+ const shouldShowSMSDeliveryFailurePage = hasLogin && hasSMSDeliveryFailure && ! shouldShowChooseSSOOrMagicCode && ! shouldInitiateSAMLLogin ;
115
+ const isUnvalidatedSecondaryLogin = hasLogin && ! isPrimaryLogin && ! account ?. validated && ! hasEmailDeliveryFailure && ! hasSMSDeliveryFailure ;
125
116
const shouldShowValidateCodeForm =
126
117
! shouldShouldSignUpWelcomeForm &&
127
118
hasAccount &&
128
119
( hasLogin || hasValidateCode ) &&
129
120
! isUnvalidatedSecondaryLogin &&
130
121
! hasEmailDeliveryFailure &&
122
+ ! hasSMSDeliveryFailure &&
131
123
! shouldShowChooseSSOOrMagicCode &&
132
124
! isSAMLRequired ;
133
125
const shouldShowWelcomeHeader = shouldShowLoginForm || shouldShowValidateCodeForm || shouldShowChooseSSOOrMagicCode || isUnvalidatedSecondaryLogin || shouldShouldSignUpWelcomeForm ;
@@ -137,6 +129,7 @@ function getRenderOptions({
137
129
return {
138
130
shouldShowLoginForm,
139
131
shouldShowEmailDeliveryFailurePage,
132
+ shouldShowSMSDeliveryFailurePage,
140
133
shouldShowUnlinkLoginForm : ! shouldShouldSignUpWelcomeForm && isUnvalidatedSecondaryLogin ,
141
134
shouldShowValidateCodeForm,
142
135
shouldShowChooseSSOOrMagicCode,
@@ -147,7 +140,7 @@ function getRenderOptions({
147
140
} ;
148
141
}
149
142
150
- function SignInPage ( { credentials , account , activeClients = [ ] , preferredLocale , shouldEnableMaxHeight = true } : SignInPageInnerProps , ref : ForwardedRef < SignInPageRef > ) {
143
+ function SignInPage ( { shouldEnableMaxHeight = true } : SignInPageInnerProps , ref : ForwardedRef < SignInPageRef > ) {
151
144
const styles = useThemeStyles ( ) ;
152
145
const StyleUtils = useStyleUtils ( ) ;
153
146
const { translate, formatPhoneNumber} = useLocalize ( ) ;
@@ -157,6 +150,18 @@ function SignInPage({credentials, account, activeClients = [], preferredLocale,
157
150
const loginFormRef = useRef < InputHandle > ( null ) ;
158
151
const validateCodeFormRef = useRef < BaseValidateCodeFormRef > ( null ) ;
159
152
153
+ const [ account ] = useOnyx ( ONYXKEYS . ACCOUNT ) ;
154
+ const [ credentials ] = useOnyx ( ONYXKEYS . CREDENTIALS ) ;
155
+ /**
156
+ This variable is only added to make sure the component is re-rendered
157
+ whenever the activeClients change, so that we call the
158
+ ActiveClientManager.isClientTheLeader function
159
+ everytime the leader client changes.
160
+ We use that function to prevent repeating code that checks which client is the leader.
161
+ */
162
+ const [ activeClients = [ ] ] = useOnyx ( ONYXKEYS . ACTIVE_CLIENTS ) ;
163
+ const [ preferredLocale ] = useOnyx ( ONYXKEYS . NVP_PREFERRED_LOCALE ) ;
164
+
160
165
/** This state is needed to keep track of if user is using recovery code instead of 2fa code,
161
166
* and we need it here since welcome text(`welcomeText`) also depends on it */
162
167
const [ isUsingRecoveryCode , setIsUsingRecoveryCode ] = useState ( false ) ;
@@ -200,6 +205,7 @@ function SignInPage({credentials, account, activeClients = [], preferredLocale,
200
205
const {
201
206
shouldShowLoginForm,
202
207
shouldShowEmailDeliveryFailurePage,
208
+ shouldShowSMSDeliveryFailurePage,
203
209
shouldShowUnlinkLoginForm,
204
210
shouldShowValidateCodeForm,
205
211
shouldShowChooseSSOOrMagicCode,
@@ -249,11 +255,11 @@ function SignInPage({credentials, account, activeClients = [], preferredLocale,
249
255
? `${ translate ( 'welcomeText.welcome' ) } ${ translate ( 'welcomeText.welcomeEnterMagicCode' , { login : userLoginToDisplay } ) } `
250
256
: translate ( 'welcomeText.welcomeEnterMagicCode' , { login : userLoginToDisplay } ) ;
251
257
}
252
- } else if ( shouldShowUnlinkLoginForm || shouldShowEmailDeliveryFailurePage || shouldShowChooseSSOOrMagicCode ) {
258
+ } else if ( shouldShowUnlinkLoginForm || shouldShowEmailDeliveryFailurePage || shouldShowChooseSSOOrMagicCode || shouldShowSMSDeliveryFailurePage ) {
253
259
welcomeHeader = shouldUseNarrowLayout ? headerText : translate ( 'welcomeText.welcome' ) ;
254
260
255
261
// Don't show any welcome text if we're showing the user the email delivery failed view
256
- if ( shouldShowEmailDeliveryFailurePage || shouldShowChooseSSOOrMagicCode ) {
262
+ if ( shouldShowEmailDeliveryFailurePage || shouldShowChooseSSOOrMagicCode || shouldShowSMSDeliveryFailurePage ) {
257
263
welcomeText = '' ;
258
264
}
259
265
} else if ( shouldShouldSignUpWelcomeForm ) {
@@ -273,7 +279,8 @@ function SignInPage({credentials, account, activeClients = [], preferredLocale,
273
279
const navigateBack = ( ) => {
274
280
if (
275
281
shouldShouldSignUpWelcomeForm ||
276
- ( ! shouldShowAnotherLoginPageOpenedMessage && ( shouldShowEmailDeliveryFailurePage || shouldShowUnlinkLoginForm || shouldShowChooseSSOOrMagicCode ) )
282
+ ( ! shouldShowAnotherLoginPageOpenedMessage &&
283
+ ( shouldShowEmailDeliveryFailurePage || shouldShowUnlinkLoginForm || shouldShowChooseSSOOrMagicCode || shouldShowSMSDeliveryFailurePage ) )
277
284
) {
278
285
Session . clearSignInData ( ) ;
279
286
return ;
@@ -331,6 +338,7 @@ function SignInPage({credentials, account, activeClients = [], preferredLocale,
331
338
{ shouldShowUnlinkLoginForm && < UnlinkLoginForm /> }
332
339
{ shouldShowChooseSSOOrMagicCode && < ChooseSSOOrMagicCode setIsUsingMagicCode = { setIsUsingMagicCode } /> }
333
340
{ shouldShowEmailDeliveryFailurePage && < EmailDeliveryFailurePage /> }
341
+ { shouldShowSMSDeliveryFailurePage && < SMSDeliveryFailurePage /> }
334
342
</ >
335
343
) }
336
344
</ SignInPageLayout >
@@ -339,7 +347,6 @@ function SignInPage({credentials, account, activeClients = [], preferredLocale,
339
347
}
340
348
341
349
type SignInPageProps = SignInPageInnerProps ;
342
- type SignInPageOnyxProps = SignInPageInnerOnyxProps ;
343
350
const SignInPageWithRef = forwardRef ( SignInPage ) ;
344
351
345
352
function SignInPageThemeWrapper ( props : SignInPageProps , ref : ForwardedRef < SignInPageRef > ) {
@@ -361,20 +368,6 @@ function SignInPageThemeWrapper(props: SignInPageProps, ref: ForwardedRef<SignIn
361
368
362
369
SignInPageThemeWrapper . displayName = 'SignInPage' ;
363
370
364
- export default withOnyx < SignInPageProps & RefAttributes < SignInPageRef > , SignInPageOnyxProps > ( {
365
- account : { key : ONYXKEYS . ACCOUNT } ,
366
- credentials : { key : ONYXKEYS . CREDENTIALS } ,
367
- /**
368
- This variable is only added to make sure the component is re-rendered
369
- whenever the activeClients change, so that we call the
370
- ActiveClientManager.isClientTheLeader function
371
- everytime the leader client changes.
372
- We use that function to prevent repeating code that checks which client is the leader.
373
- */
374
- activeClients : { key : ONYXKEYS . ACTIVE_CLIENTS } ,
375
- preferredLocale : {
376
- key : ONYXKEYS . NVP_PREFERRED_LOCALE ,
377
- } ,
378
- } ) ( forwardRef ( SignInPageThemeWrapper ) ) ;
371
+ export default forwardRef ( SignInPageThemeWrapper ) ;
379
372
380
373
export type { SignInPageRef } ;
0 commit comments