-
Notifications
You must be signed in to change notification settings - Fork 3k
/
Copy pathresetFreePlanBankAccount.js
75 lines (72 loc) · 2.66 KB
/
resetFreePlanBankAccount.js
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
import Onyx from 'react-native-onyx';
import CONST from '../../../CONST';
import ONYXKEYS from '../../../ONYXKEYS';
import * as store from './store';
import * as API from '../../API';
import * as PlaidDataProps from '../../../pages/ReimbursementAccount/plaidDataPropTypes';
import * as ReimbursementAccountProps from '../../../pages/ReimbursementAccount/reimbursementAccountPropTypes';
/**
* Reset user's reimbursement account. This will delete the bank account.
* @param {number} bankAccountID
*/
function resetFreePlanBankAccount(bankAccountID) {
if (!bankAccountID) {
throw new Error('Missing bankAccountID when attempting to reset free plan bank account');
}
if (!store.getCredentials() || !store.getCredentials().login) {
throw new Error('Missing credentials when attempting to reset free plan bank account');
}
API.write('RestartBankAccountSetup',
{
bankAccountID,
ownerEmail: store.getCredentials().login,
},
{
optimisticData: [
{
onyxMethod: Onyx.METHOD.MERGE,
key: ONYXKEYS.REIMBURSEMENT_ACCOUNT,
value: {
shouldShowResetModal: false,
isLoading: true,
pendingAction: CONST.RED_BRICK_ROAD_PENDING_ACTION.DELETE,
},
},
],
successData: [
{
onyxMethod: Onyx.METHOD.SET,
key: ONYXKEYS.ONFIDO_TOKEN,
value: '',
},
{
onyxMethod: Onyx.METHOD.SET,
key: ONYXKEYS.PLAID_DATA,
value: PlaidDataProps.plaidDataDefaultProps,
},
{
onyxMethod: Onyx.METHOD.SET,
key: ONYXKEYS.PLAID_LINK_TOKEN,
value: '',
},
{
onyxMethod: Onyx.METHOD.SET,
key: ONYXKEYS.REIMBURSEMENT_ACCOUNT,
value: ReimbursementAccountProps.reimbursementAccountDefaultProps,
},
{
onyxMethod: Onyx.METHOD.SET,
key: ONYXKEYS.REIMBURSEMENT_ACCOUNT_DRAFT,
value: {},
},
],
failureData: [
{
onyxMethod: Onyx.METHOD.MERGE,
key: ONYXKEYS.REIMBURSEMENT_ACCOUNT,
value: {isLoading: false, pendingAction: null},
},
],
});
}
export default resetFreePlanBankAccount;