-
Notifications
You must be signed in to change notification settings - Fork 3k
/
Copy pathReimbursementAccountPage.tsx
587 lines (536 loc) · 27 KB
/
ReimbursementAccountPage.tsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
import {Str} from 'expensify-common';
import lodashPick from 'lodash/pick';
import React, {useEffect, useRef, useState} from 'react';
import {View} from 'react-native';
import {useOnyx} from 'react-native-onyx';
import type {ValueOf} from 'type-fest';
import FullPageNotFoundView from '@components/BlockingViews/FullPageNotFoundView';
import FullScreenLoadingIndicator from '@components/FullscreenLoadingIndicator';
import HeaderWithBackButton from '@components/HeaderWithBackButton';
import {useSession} from '@components/OnyxProvider';
import ReimbursementAccountLoadingIndicator from '@components/ReimbursementAccountLoadingIndicator';
import ScreenWrapper from '@components/ScreenWrapper';
import Text from '@components/Text';
import useBeforeRemove from '@hooks/useBeforeRemove';
import useEnvironment from '@hooks/useEnvironment';
import useLocalize from '@hooks/useLocalize';
import useNetwork from '@hooks/useNetwork';
import usePrevious from '@hooks/usePrevious';
import useThemeStyles from '@hooks/useThemeStyles';
import getPlaidOAuthReceivedRedirectURI from '@libs/getPlaidOAuthReceivedRedirectURI';
import BankAccount from '@libs/models/BankAccount';
import Navigation from '@libs/Navigation/Navigation';
import type {PlatformStackRouteProp, PlatformStackScreenProps} from '@libs/Navigation/PlatformStackNavigation/types';
import type {ReimbursementAccountNavigatorParamList} from '@libs/Navigation/types';
import * as PolicyUtils from '@libs/PolicyUtils';
import shouldReopenOnfido from '@libs/shouldReopenOnfido';
import type {WithPolicyOnyxProps} from '@pages/workspace/withPolicy';
import withPolicy from '@pages/workspace/withPolicy';
import * as BankAccounts from '@userActions/BankAccounts';
import * as ReimbursementAccount from '@userActions/ReimbursementAccount';
import CONST from '@src/CONST';
import ONYXKEYS from '@src/ONYXKEYS';
import type SCREENS from '@src/SCREENS';
import type {InputID} from '@src/types/form/ReimbursementAccountForm';
import type {ACHDataReimbursementAccount, BankAccountStep as TBankAccountStep} from '@src/types/onyx/ReimbursementAccount';
import {isEmptyObject} from '@src/types/utils/EmptyObject';
import ACHContractStep from './ACHContractStep';
import BankAccountStep from './BankAccountStep';
import BeneficialOwnersStep from './BeneficialOwnersStep';
import CompanyStep from './CompanyStep';
import ConnectBankAccount from './ConnectBankAccount/ConnectBankAccount';
import ContinueBankAccountSetup from './ContinueBankAccountSetup';
import EnableBankAccount from './EnableBankAccount/EnableBankAccount';
import Agreements from './NonUSD/Agreements';
import BankInfo from './NonUSD/BankInfo/BankInfo';
import BeneficialOwnerInfo from './NonUSD/BeneficialOwnerInfo/BeneficialOwnerInfo';
import BusinessInfo from './NonUSD/BusinessInfo/BusinessInfo';
import Country from './NonUSD/Country/Country';
import Finish from './NonUSD/Finish';
import SignerInfo from './NonUSD/SignerInfo';
import RequestorStep from './RequestorStep';
type ReimbursementAccountPageProps = WithPolicyOnyxProps & PlatformStackScreenProps<ReimbursementAccountNavigatorParamList, typeof SCREENS.REIMBURSEMENT_ACCOUNT_ROOT>;
const ROUTE_NAMES = {
COMPANY: 'company',
PERSONAL_INFORMATION: 'personal-information',
BENEFICIAL_OWNERS: 'beneficial-owners',
CONTRACT: 'contract',
VALIDATE: 'validate',
ENABLE: 'enable',
NEW: 'new',
};
const SUPPORTED_FOREIGN_CURRENCIES: string[] = [CONST.CURRENCY.EUR, CONST.CURRENCY.GBP, CONST.CURRENCY.CAD, CONST.CURRENCY.AUD];
/**
* We can pass stepToOpen in the URL to force which step to show.
* Mainly needed when user finished the flow in verifying state, and Ops ask them to modify some fields from a specific step.
*/
function getStepToOpenFromRouteParams(route: PlatformStackRouteProp<ReimbursementAccountNavigatorParamList, typeof SCREENS.REIMBURSEMENT_ACCOUNT_ROOT>): TBankAccountStep | '' {
switch (route.params.stepToOpen) {
case ROUTE_NAMES.NEW:
return CONST.BANK_ACCOUNT.STEP.BANK_ACCOUNT;
case ROUTE_NAMES.COMPANY:
return CONST.BANK_ACCOUNT.STEP.COMPANY;
case ROUTE_NAMES.PERSONAL_INFORMATION:
return CONST.BANK_ACCOUNT.STEP.REQUESTOR;
case ROUTE_NAMES.BENEFICIAL_OWNERS:
return CONST.BANK_ACCOUNT.STEP.BENEFICIAL_OWNERS;
case ROUTE_NAMES.CONTRACT:
return CONST.BANK_ACCOUNT.STEP.ACH_CONTRACT;
case ROUTE_NAMES.VALIDATE:
return CONST.BANK_ACCOUNT.STEP.VALIDATION;
case ROUTE_NAMES.ENABLE:
return CONST.BANK_ACCOUNT.STEP.ENABLE;
default:
return '';
}
}
function getRouteForCurrentStep(currentStep: TBankAccountStep): ValueOf<typeof ROUTE_NAMES> {
switch (currentStep) {
case CONST.BANK_ACCOUNT.STEP.COMPANY:
return ROUTE_NAMES.COMPANY;
case CONST.BANK_ACCOUNT.STEP.REQUESTOR:
return ROUTE_NAMES.PERSONAL_INFORMATION;
case CONST.BANK_ACCOUNT.STEP.BENEFICIAL_OWNERS:
return ROUTE_NAMES.BENEFICIAL_OWNERS;
case CONST.BANK_ACCOUNT.STEP.ACH_CONTRACT:
return ROUTE_NAMES.CONTRACT;
case CONST.BANK_ACCOUNT.STEP.VALIDATION:
return ROUTE_NAMES.VALIDATE;
case CONST.BANK_ACCOUNT.STEP.ENABLE:
return ROUTE_NAMES.ENABLE;
case CONST.BANK_ACCOUNT.STEP.BANK_ACCOUNT:
default:
return ROUTE_NAMES.NEW;
}
}
/**
* Returns selected bank account fields based on field names provided.
*/
function getFieldsForStep(step: TBankAccountStep): InputID[] {
switch (step) {
case CONST.BANK_ACCOUNT.STEP.BANK_ACCOUNT:
return ['routingNumber', 'accountNumber', 'bankName', 'plaidAccountID', 'plaidAccessToken', 'isSavings'];
case CONST.BANK_ACCOUNT.STEP.COMPANY:
return [
'companyName',
'addressStreet',
'addressZipCode',
'addressCity',
'addressState',
'companyPhone',
'website',
'companyTaxID',
'incorporationType',
'incorporationDate',
'incorporationState',
];
case CONST.BANK_ACCOUNT.STEP.REQUESTOR:
return ['firstName', 'lastName', 'dob', 'ssnLast4', 'requestorAddressStreet', 'requestorAddressCity', 'requestorAddressState', 'requestorAddressZipCode'];
default:
return [];
}
}
function ReimbursementAccountPage({route, policy, isLoadingPolicy}: ReimbursementAccountPageProps) {
const session = useSession();
const [reimbursementAccount] = useOnyx(ONYXKEYS.REIMBURSEMENT_ACCOUNT);
const [plaidLinkToken = ''] = useOnyx(ONYXKEYS.PLAID_LINK_TOKEN);
const [plaidCurrentEvent = ''] = useOnyx(ONYXKEYS.PLAID_CURRENT_EVENT);
const [onfidoToken = ''] = useOnyx(ONYXKEYS.ONFIDO_TOKEN);
const [isLoadingApp = false] = useOnyx(ONYXKEYS.IS_LOADING_APP);
const [account] = useOnyx(ONYXKEYS.ACCOUNT);
const [isDebugModeEnabled] = useOnyx(ONYXKEYS.USER, {selector: (user) => !!user?.isDebugModeEnabled});
const [isValidateCodeActionModalVisible, setIsValidateCodeActionModalVisible] = useState(false);
const policyName = policy?.name ?? '';
const policyIDParam = route.params?.policyID ?? '-1';
const styles = useThemeStyles();
const {translate} = useLocalize();
const {isOffline} = useNetwork();
const requestorStepRef = useRef(null);
const prevReimbursementAccount = usePrevious(reimbursementAccount);
const prevIsOffline = usePrevious(isOffline);
const {isDevelopment} = useEnvironment();
/**
The SetupWithdrawalAccount flow allows us to continue the flow from various points depending on where the
user left off. This view will refer to the achData as the single source of truth to determine which route to
display. We can also specify a specific route to navigate to via route params when the component first
mounts which will set the achData.currentStep after the account data is fetched and overwrite the logical
next step.
*/
const achData = reimbursementAccount?.achData;
const isPreviousPolicy = policyIDParam === achData?.policyID;
// eslint-disable-next-line @typescript-eslint/prefer-nullish-coalescing
const currentStep = !isPreviousPolicy ? CONST.BANK_ACCOUNT.STEP.BANK_ACCOUNT : achData?.currentStep || CONST.BANK_ACCOUNT.STEP.BANK_ACCOUNT;
const [nonUSDBankAccountStep, setNonUSDBankAccountStep] = useState<string>(CONST.NON_USD_BANK_ACCOUNT.STEP.COUNTRY);
function getBankAccountFields(fieldNames: InputID[]): Partial<ACHDataReimbursementAccount> {
return {
...lodashPick(reimbursementAccount?.achData, ...fieldNames),
};
}
/**
* Returns true if a VBBA exists in any state other than OPEN or LOCKED
*/
function hasInProgressVBBA(): boolean {
return !!achData?.bankAccountID && !!achData?.state && achData?.state !== BankAccount.STATE.OPEN && achData?.state !== BankAccount.STATE.LOCKED;
}
/*
* Calculates the state used to show the "Continue with setup" view. If a bank account setup is already in progress and
* no specific further step was passed in the url we'll show the workspace bank account reset modal if the user wishes to start over
*/
function getShouldShowContinueSetupButtonInitialValue(): boolean {
if (!hasInProgressVBBA()) {
// Since there is no VBBA in progress, we won't need to show the component ContinueBankAccountSetup
return false;
}
return achData?.state === BankAccount.STATE.PENDING || [CONST.BANK_ACCOUNT.STEP.BANK_ACCOUNT, ''].includes(getStepToOpenFromRouteParams(route));
}
/**
When this page is first opened, `reimbursementAccount` prop might not yet be fully loaded from Onyx.
Calculating `shouldShowContinueSetupButton` immediately on initial render doesn't make sense as
it relies on incomplete data. Thus, we should wait to calculate it until we have received
the full `reimbursementAccount` data from the server. This logic is handled within the useEffect hook,
which acts similarly to `componentDidUpdate` when the `reimbursementAccount` dependency changes.
*/
const [hasACHDataBeenLoaded, setHasACHDataBeenLoaded] = useState(reimbursementAccount !== CONST.REIMBURSEMENT_ACCOUNT.DEFAULT_DATA && isPreviousPolicy);
const [shouldShowContinueSetupButton, setShouldShowContinueSetupButton] = useState(() => getShouldShowContinueSetupButtonInitialValue());
const handleNextNonUSDBankAccountStep = () => {
switch (nonUSDBankAccountStep) {
case CONST.NON_USD_BANK_ACCOUNT.STEP.COUNTRY:
setNonUSDBankAccountStep(CONST.NON_USD_BANK_ACCOUNT.STEP.BANK_INFO);
break;
case CONST.NON_USD_BANK_ACCOUNT.STEP.BANK_INFO:
setNonUSDBankAccountStep(CONST.NON_USD_BANK_ACCOUNT.STEP.BUSINESS_INFO);
break;
case CONST.NON_USD_BANK_ACCOUNT.STEP.BUSINESS_INFO:
setNonUSDBankAccountStep(CONST.NON_USD_BANK_ACCOUNT.STEP.BENEFICIAL_OWNER_INFO);
break;
case CONST.NON_USD_BANK_ACCOUNT.STEP.BENEFICIAL_OWNER_INFO:
setNonUSDBankAccountStep(CONST.NON_USD_BANK_ACCOUNT.STEP.SIGNER_INFO);
break;
case CONST.NON_USD_BANK_ACCOUNT.STEP.SIGNER_INFO:
setNonUSDBankAccountStep(CONST.NON_USD_BANK_ACCOUNT.STEP.AGREEMENTS);
break;
case CONST.NON_USD_BANK_ACCOUNT.STEP.AGREEMENTS:
setNonUSDBankAccountStep(CONST.NON_USD_BANK_ACCOUNT.STEP.FINISH);
break;
default:
return null;
}
};
const nonUSDBankAccountsGoBack = () => {
switch (nonUSDBankAccountStep) {
case CONST.NON_USD_BANK_ACCOUNT.STEP.COUNTRY:
Navigation.goBack();
break;
case CONST.NON_USD_BANK_ACCOUNT.STEP.BANK_INFO:
setNonUSDBankAccountStep(CONST.NON_USD_BANK_ACCOUNT.STEP.COUNTRY);
break;
case CONST.NON_USD_BANK_ACCOUNT.STEP.BUSINESS_INFO:
setNonUSDBankAccountStep(CONST.NON_USD_BANK_ACCOUNT.STEP.BANK_INFO);
break;
case CONST.NON_USD_BANK_ACCOUNT.STEP.BENEFICIAL_OWNER_INFO:
setNonUSDBankAccountStep(CONST.NON_USD_BANK_ACCOUNT.STEP.BUSINESS_INFO);
break;
case CONST.NON_USD_BANK_ACCOUNT.STEP.SIGNER_INFO:
setNonUSDBankAccountStep(CONST.NON_USD_BANK_ACCOUNT.STEP.BENEFICIAL_OWNER_INFO);
break;
case CONST.NON_USD_BANK_ACCOUNT.STEP.AGREEMENTS:
setNonUSDBankAccountStep(CONST.NON_USD_BANK_ACCOUNT.STEP.SIGNER_INFO);
break;
default:
return null;
}
};
/**
* Retrieve verified business bank account currently being set up.
*/
function fetchData() {
// We can specify a step to navigate to by using route params when the component mounts.
// We want to use the same stepToOpen variable when the network state changes because we can be redirected to a different step when the account refreshes.
const stepToOpen = getStepToOpenFromRouteParams(route);
const subStep = isPreviousPolicy ? achData?.subStep ?? '' : '';
const localCurrentStep = isPreviousPolicy ? achData?.currentStep ?? '' : '';
BankAccounts.openReimbursementAccountPage(stepToOpen, subStep, localCurrentStep, policyIDParam);
}
useBeforeRemove(() => setIsValidateCodeActionModalVisible(false));
useEffect(() => {
if (isPreviousPolicy) {
return;
}
BankAccounts.setReimbursementAccountLoading(true);
ReimbursementAccount.clearReimbursementAccountDraft();
// If the step to open is empty, we want to clear the sub step, so the connect option view is shown to the user
const isStepToOpenEmpty = getStepToOpenFromRouteParams(route) === '';
if (isStepToOpenEmpty) {
BankAccounts.setBankAccountSubStep(null);
BankAccounts.setPlaidEvent(null);
}
fetchData();
// eslint-disable-next-line react-compiler/react-compiler, react-hooks/exhaustive-deps
}, []); // The empty dependency array ensures this runs only once after the component mounts.
useEffect(
() => {
// Check for network change from offline to online
if (prevIsOffline && !isOffline && prevReimbursementAccount && prevReimbursementAccount.pendingAction !== CONST.RED_BRICK_ROAD_PENDING_ACTION.DELETE) {
fetchData();
}
if (!hasACHDataBeenLoaded) {
if (reimbursementAccount !== CONST.REIMBURSEMENT_ACCOUNT.DEFAULT_DATA && reimbursementAccount?.isLoading === false) {
setHasACHDataBeenLoaded(true);
}
return;
}
if (
prevReimbursementAccount &&
prevReimbursementAccount.pendingAction === CONST.RED_BRICK_ROAD_PENDING_ACTION.DELETE &&
reimbursementAccount?.pendingAction !== prevReimbursementAccount.pendingAction
) {
setShouldShowContinueSetupButton(hasInProgressVBBA());
}
if (shouldShowContinueSetupButton) {
return;
}
const currentStepRouteParam = getStepToOpenFromRouteParams(route);
if (currentStepRouteParam === currentStep) {
// If the user is connecting online with plaid, reset any bank account errors so we don't persist old data from a potential previous connection
if (currentStep === CONST.BANK_ACCOUNT.STEP.BANK_ACCOUNT && achData?.subStep === CONST.BANK_ACCOUNT.SETUP_TYPE.PLAID) {
BankAccounts.hideBankAccountErrors();
}
// The route is showing the correct step, no need to update the route param or clear errors.
return;
}
// Update the data that is returned from back-end to draft value
const draftStep = reimbursementAccount?.draftStep;
if (draftStep) {
BankAccounts.updateReimbursementAccountDraft(getBankAccountFields(getFieldsForStep(draftStep)));
}
if (currentStepRouteParam !== '') {
// When we click "Connect bank account", we load the page without the current step param, if there
// was an error when we tried to disconnect or start over, we want the user to be able to see the error,
// so we don't clear it. We only want to clear the errors if we are moving between steps.
BankAccounts.hideBankAccountErrors();
}
Navigation.setParams({stepToOpen: getRouteForCurrentStep(currentStep)});
},
// eslint-disable-next-line react-compiler/react-compiler, react-hooks/exhaustive-deps
[isOffline, reimbursementAccount, route, hasACHDataBeenLoaded, shouldShowContinueSetupButton],
);
const setManualStep = () => {
BankAccounts.setBankAccountSubStep(CONST.BANK_ACCOUNT.SETUP_TYPE.MANUAL).then(() => {
setShouldShowContinueSetupButton(false);
});
};
const goBack = () => {
const subStep = achData?.subStep;
const shouldShowOnfido = onfidoToken && !achData?.isOnfidoSetupComplete;
switch (currentStep) {
case CONST.BANK_ACCOUNT.STEP.BANK_ACCOUNT:
if (hasInProgressVBBA()) {
setShouldShowContinueSetupButton(true);
}
if (subStep) {
BankAccounts.setBankAccountSubStep(null);
BankAccounts.setPlaidEvent(null);
} else {
Navigation.goBack();
}
break;
case CONST.BANK_ACCOUNT.STEP.COMPANY:
BankAccounts.clearOnfidoToken();
BankAccounts.goToWithdrawalAccountSetupStep(CONST.BANK_ACCOUNT.STEP.REQUESTOR);
break;
case CONST.BANK_ACCOUNT.STEP.REQUESTOR:
if (shouldShowOnfido) {
BankAccounts.clearOnfidoToken();
} else {
BankAccounts.goToWithdrawalAccountSetupStep(CONST.BANK_ACCOUNT.STEP.BANK_ACCOUNT);
}
break;
case CONST.BANK_ACCOUNT.STEP.BENEFICIAL_OWNERS:
BankAccounts.goToWithdrawalAccountSetupStep(CONST.BANK_ACCOUNT.STEP.COMPANY);
break;
case CONST.BANK_ACCOUNT.STEP.ACH_CONTRACT:
BankAccounts.goToWithdrawalAccountSetupStep(CONST.BANK_ACCOUNT.STEP.BENEFICIAL_OWNERS);
break;
case CONST.BANK_ACCOUNT.STEP.VALIDATION:
if ([BankAccount.STATE.VERIFYING, BankAccount.STATE.SETUP].some((value) => value === achData?.state)) {
BankAccounts.goToWithdrawalAccountSetupStep(CONST.BANK_ACCOUNT.STEP.ACH_CONTRACT);
} else if (!isOffline && achData?.state === BankAccount.STATE.PENDING) {
setShouldShowContinueSetupButton(true);
} else {
Navigation.goBack();
}
break;
default:
Navigation.goBack();
}
};
const isLoading = (!!isLoadingApp || !!account?.isLoading || reimbursementAccount?.isLoading) && (!plaidCurrentEvent || plaidCurrentEvent === CONST.BANK_ACCOUNT.PLAID.EVENTS_NAME.EXIT);
const shouldShowOfflineLoader = !(
isOffline &&
[
CONST.BANK_ACCOUNT.STEP.BANK_ACCOUNT,
CONST.BANK_ACCOUNT.STEP.COMPANY,
CONST.BANK_ACCOUNT.STEP.REQUESTOR,
CONST.BANK_ACCOUNT.STEP.BENEFICIAL_OWNERS,
CONST.BANK_ACCOUNT.STEP.ACH_CONTRACT,
].some((value) => value === currentStep)
);
if (isLoadingPolicy) {
return <FullScreenLoadingIndicator />;
}
// Show loading indicator when page is first time being opened and props.reimbursementAccount yet to be loaded from the server
// or when data is being loaded. Don't show the loading indicator if we're offline and restarted the bank account setup process
// On Android, when we open the app from the background, Onfido activity gets destroyed, so we need to reopen it.
// eslint-disable-next-line react-compiler/react-compiler
if (
(!hasACHDataBeenLoaded || isLoading) &&
shouldShowOfflineLoader &&
(shouldReopenOnfido || !requestorStepRef?.current) &&
!(currentStep === CONST.BANK_ACCOUNT.STEP.BANK_ACCOUNT && isValidateCodeActionModalVisible)
) {
return <ReimbursementAccountLoadingIndicator onBackButtonPress={goBack} />;
}
if (!isLoading && (isEmptyObject(policy) || !PolicyUtils.isPolicyAdmin(policy))) {
return (
<ScreenWrapper testID={ReimbursementAccountPage.displayName}>
<FullPageNotFoundView
shouldShow
onBackButtonPress={PolicyUtils.goBackFromInvalidPolicy}
onLinkPress={PolicyUtils.goBackFromInvalidPolicy}
subtitleKey={isEmptyObject(policy) ? undefined : 'workspace.common.notAuthorized'}
/>
</ScreenWrapper>
);
}
let errorText;
const userHasPhonePrimaryEmail = Str.endsWith(session?.email ?? '', CONST.SMS.DOMAIN);
const throttledDate = reimbursementAccount?.throttledDate ?? '';
const policyCurrency = policy?.outputCurrency ?? '';
// TODO once nonUSD flow is complete update the flag below to reflect all supported currencies, this will be updated in - https://github.com/Expensify/App/issues/50912
const hasUnsupportedCurrency = policyCurrency !== CONST.CURRENCY.USD;
// TODO remove isDevelopment and isDebugModeEnabled flags once nonUSD flow is complete, this will be updated in - https://github.com/Expensify/App/issues/50912
const hasForeignCurrency = SUPPORTED_FOREIGN_CURRENCIES.includes(policyCurrency) && (isDevelopment || isDebugModeEnabled);
if (userHasPhonePrimaryEmail) {
errorText = translate('bankAccount.hasPhoneLoginError');
} else if (throttledDate) {
errorText = translate('bankAccount.hasBeenThrottledError');
} else if (hasUnsupportedCurrency) {
if (hasForeignCurrency) {
switch (nonUSDBankAccountStep) {
case CONST.NON_USD_BANK_ACCOUNT.STEP.COUNTRY:
return (
<Country
onBackButtonPress={nonUSDBankAccountsGoBack}
onSubmit={handleNextNonUSDBankAccountStep}
/>
);
case CONST.NON_USD_BANK_ACCOUNT.STEP.BANK_INFO:
return (
<BankInfo
onBackButtonPress={nonUSDBankAccountsGoBack}
onSubmit={handleNextNonUSDBankAccountStep}
/>
);
case CONST.NON_USD_BANK_ACCOUNT.STEP.BUSINESS_INFO:
return (
<BusinessInfo
onBackButtonPress={nonUSDBankAccountsGoBack}
onSubmit={handleNextNonUSDBankAccountStep}
/>
);
case CONST.NON_USD_BANK_ACCOUNT.STEP.BENEFICIAL_OWNER_INFO:
return (
<BeneficialOwnerInfo
onBackButtonPress={nonUSDBankAccountsGoBack}
onSubmit={handleNextNonUSDBankAccountStep}
/>
);
case CONST.NON_USD_BANK_ACCOUNT.STEP.SIGNER_INFO:
return (
<SignerInfo
onBackButtonPress={nonUSDBankAccountsGoBack}
onSubmit={handleNextNonUSDBankAccountStep}
/>
);
case CONST.NON_USD_BANK_ACCOUNT.STEP.AGREEMENTS:
return (
<Agreements
onBackButtonPress={nonUSDBankAccountsGoBack}
onSubmit={handleNextNonUSDBankAccountStep}
/>
);
case CONST.NON_USD_BANK_ACCOUNT.STEP.FINISH:
return <Finish />;
default:
return null;
}
}
errorText = translate('bankAccount.hasCurrencyError');
}
if (errorText) {
return (
<ScreenWrapper testID={ReimbursementAccountPage.displayName}>
<HeaderWithBackButton
title={translate('workspace.common.connectBankAccount')}
subtitle={policyName}
onBackButtonPress={() => Navigation.goBack()}
/>
<View style={[styles.m5, styles.mv3, styles.flex1]}>
<Text>{errorText}</Text>
</View>
</ScreenWrapper>
);
}
if (shouldShowContinueSetupButton) {
return (
<ContinueBankAccountSetup
reimbursementAccount={reimbursementAccount}
onContinuePress={setManualStep}
policyName={policyName}
onBackButtonPress={Navigation.goBack}
/>
);
}
switch (currentStep) {
case CONST.BANK_ACCOUNT.STEP.BANK_ACCOUNT:
return (
<BankAccountStep
reimbursementAccount={reimbursementAccount}
onBackButtonPress={goBack}
receivedRedirectURI={getPlaidOAuthReceivedRedirectURI()}
plaidLinkOAuthToken={plaidLinkToken}
policyName={policyName}
policyID={policyIDParam}
isValidateCodeActionModalVisible={isValidateCodeActionModalVisible}
toggleValidateCodeActionModal={setIsValidateCodeActionModalVisible}
/>
);
case CONST.BANK_ACCOUNT.STEP.REQUESTOR:
return (
<RequestorStep
ref={requestorStepRef}
shouldShowOnfido={!!(onfidoToken && !achData?.isOnfidoSetupComplete)}
onBackButtonPress={goBack}
/>
);
case CONST.BANK_ACCOUNT.STEP.COMPANY:
return <CompanyStep onBackButtonPress={goBack} />;
case CONST.BANK_ACCOUNT.STEP.BENEFICIAL_OWNERS:
return <BeneficialOwnersStep onBackButtonPress={goBack} />;
case CONST.BANK_ACCOUNT.STEP.ACH_CONTRACT:
return <ACHContractStep onBackButtonPress={goBack} />;
case CONST.BANK_ACCOUNT.STEP.VALIDATION:
return <ConnectBankAccount onBackButtonPress={goBack} />;
case CONST.BANK_ACCOUNT.STEP.ENABLE:
return (
<EnableBankAccount
reimbursementAccount={reimbursementAccount}
onBackButtonPress={goBack}
/>
);
default:
return null;
}
}
ReimbursementAccountPage.displayName = 'ReimbursementAccountPage';
export default withPolicy(ReimbursementAccountPage);