-
Notifications
You must be signed in to change notification settings - Fork 3k
/
resetFreePlanBankAccount.ts
146 lines (141 loc) · 6.45 KB
/
resetFreePlanBankAccount.ts
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
import type {OnyxCollection, OnyxEntry} from 'react-native-onyx';
import Onyx from 'react-native-onyx';
import * as API from '@libs/API';
import {WRITE_COMMANDS} from '@libs/API/types';
import CONST from '@src/CONST';
import ONYXKEYS from '@src/ONYXKEYS';
import INPUT_IDS from '@src/types/form/ReimbursementAccountForm';
import type * as OnyxTypes from '@src/types/onyx';
let allPolicies: OnyxCollection<OnyxTypes.Policy>;
Onyx.connect({
key: ONYXKEYS.COLLECTION.POLICY,
waitForCollectionCallback: true,
callback: (value) => (allPolicies = value),
});
/**
* Reset user's reimbursement account. This will delete the bank account.
*/
function resetFreePlanBankAccount(bankAccountID: number | undefined, session: OnyxEntry<OnyxTypes.Session>, policyID: string) {
if (!bankAccountID) {
throw new Error('Missing bankAccountID when attempting to reset free plan bank account');
}
if (!session?.email) {
throw new Error('Missing credentials when attempting to reset free plan bank account');
}
const policy = allPolicies?.[`${ONYXKEYS.COLLECTION.POLICY}${policyID}`] ?? ({} as OnyxTypes.Policy);
API.write(
WRITE_COMMANDS.RESTART_BANK_ACCOUNT_SETUP,
{
bankAccountID,
ownerEmail: session.email,
policyID,
},
{
optimisticData: [
{
onyxMethod: Onyx.METHOD.MERGE,
key: ONYXKEYS.REIMBURSEMENT_ACCOUNT,
value: {
shouldShowResetModal: false,
isLoading: true,
pendingAction: CONST.RED_BRICK_ROAD_PENDING_ACTION.DELETE,
achData: null,
},
},
{
onyxMethod: Onyx.METHOD.MERGE,
key: `${ONYXKEYS.COLLECTION.POLICY}${policyID}`,
value: {
achAccount: null,
},
},
],
successData: [
{
onyxMethod: Onyx.METHOD.SET,
key: ONYXKEYS.ONFIDO_TOKEN,
value: '',
},
{
onyxMethod: Onyx.METHOD.SET,
key: ONYXKEYS.ONFIDO_APPLICANT_ID,
value: '',
},
{
onyxMethod: Onyx.METHOD.SET,
key: ONYXKEYS.PLAID_DATA,
value: CONST.PLAID.DEFAULT_DATA,
},
{
onyxMethod: Onyx.METHOD.SET,
key: ONYXKEYS.PLAID_LINK_TOKEN,
value: '',
},
{
onyxMethod: Onyx.METHOD.SET,
key: ONYXKEYS.REIMBURSEMENT_ACCOUNT,
value: CONST.REIMBURSEMENT_ACCOUNT.DEFAULT_DATA,
},
{
onyxMethod: Onyx.METHOD.SET,
key: ONYXKEYS.FORMS.REIMBURSEMENT_ACCOUNT_FORM_DRAFT,
value: {
[INPUT_IDS.BENEFICIAL_OWNER_INFO_STEP.OWNS_MORE_THAN_25_PERCENT]: false,
[INPUT_IDS.BENEFICIAL_OWNER_INFO_STEP.HAS_OTHER_BENEFICIAL_OWNERS]: false,
[INPUT_IDS.BENEFICIAL_OWNER_INFO_STEP.BENEFICIAL_OWNERS]: '',
[INPUT_IDS.BANK_INFO_STEP.ACCOUNT_NUMBER]: '',
[INPUT_IDS.BANK_INFO_STEP.ROUTING_NUMBER]: '',
[INPUT_IDS.BANK_INFO_STEP.PLAID_ACCOUNT_ID]: '',
[INPUT_IDS.BANK_INFO_STEP.PLAID_MASK]: '',
[INPUT_IDS.BUSINESS_INFO_STEP.COMPANY_NAME]: '',
[INPUT_IDS.BUSINESS_INFO_STEP.STREET]: '',
[INPUT_IDS.BUSINESS_INFO_STEP.CITY]: '',
[INPUT_IDS.BUSINESS_INFO_STEP.STATE]: '',
[INPUT_IDS.BUSINESS_INFO_STEP.ZIP_CODE]: '',
[INPUT_IDS.BUSINESS_INFO_STEP.COMPANY_PHONE]: '',
[INPUT_IDS.BUSINESS_INFO_STEP.COMPANY_WEBSITE]: undefined,
[INPUT_IDS.BUSINESS_INFO_STEP.COMPANY_TAX_ID]: '',
[INPUT_IDS.BUSINESS_INFO_STEP.INCORPORATION_TYPE]: '',
[INPUT_IDS.BUSINESS_INFO_STEP.INCORPORATION_DATE]: '',
[INPUT_IDS.BUSINESS_INFO_STEP.INCORPORATION_STATE]: '',
[INPUT_IDS.BUSINESS_INFO_STEP.HAS_NO_CONNECTION_TO_CANNABIS]: false,
[INPUT_IDS.PERSONAL_INFO_STEP.FIRST_NAME]: '',
[INPUT_IDS.PERSONAL_INFO_STEP.LAST_NAME]: '',
[INPUT_IDS.PERSONAL_INFO_STEP.STREET]: '',
[INPUT_IDS.PERSONAL_INFO_STEP.CITY]: '',
[INPUT_IDS.PERSONAL_INFO_STEP.STATE]: '',
[INPUT_IDS.PERSONAL_INFO_STEP.ZIP_CODE]: '',
[INPUT_IDS.PERSONAL_INFO_STEP.IS_ONFIDO_SETUP_COMPLETE]: false,
[INPUT_IDS.PERSONAL_INFO_STEP.DOB]: '',
[INPUT_IDS.PERSONAL_INFO_STEP.SSN_LAST_4]: '',
[INPUT_IDS.COMPLETE_VERIFICATION.ACCEPT_TERMS_AND_CONDITIONS]: false,
[INPUT_IDS.COMPLETE_VERIFICATION.CERTIFY_TRUE_INFORMATION]: false,
[INPUT_IDS.COMPLETE_VERIFICATION.IS_AUTHORIZED_TO_USE_BANK_ACCOUNT]: false,
[INPUT_IDS.BANK_INFO_STEP.IS_SAVINGS]: false,
[INPUT_IDS.BANK_INFO_STEP.BANK_NAME]: '',
[INPUT_IDS.BANK_INFO_STEP.PLAID_ACCESS_TOKEN]: '',
[INPUT_IDS.BANK_INFO_STEP.SELECTED_PLAID_ACCOUNT_ID]: '',
[INPUT_IDS.AMOUNT1]: '',
[INPUT_IDS.AMOUNT2]: '',
[INPUT_IDS.AMOUNT3]: '',
},
},
],
failureData: [
{
onyxMethod: Onyx.METHOD.MERGE,
key: ONYXKEYS.REIMBURSEMENT_ACCOUNT,
value: {isLoading: false, pendingAction: null},
},
{
onyxMethod: Onyx.METHOD.MERGE,
key: `${ONYXKEYS.COLLECTION.POLICY}${policyID}`,
value: {
achAccount: policy?.achAccount,
},
},
],
},
);
}
export default resetFreePlanBankAccount;