-
Notifications
You must be signed in to change notification settings - Fork 3k
/
Copy pathBankAccountStep.js
324 lines (307 loc) · 15.4 KB
/
BankAccountStep.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
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
import _ from 'underscore';
import React from 'react';
import {View, Image} from 'react-native';
import PropTypes from 'prop-types';
import {withOnyx} from 'react-native-onyx';
import HeaderWithCloseButton from '../../components/HeaderWithCloseButton';
import MenuItem from '../../components/MenuItem';
import {
Paycheck, Bank, Lock,
} from '../../components/Icon/Expensicons';
import styles from '../../styles/styles';
import TextLink from '../../components/TextLink';
import Button from '../../components/Button';
import Icon from '../../components/Icon';
import colors from '../../styles/colors';
import Navigation from '../../libs/Navigation/Navigation';
import CONST from '../../CONST';
import AddPlaidBankAccount from '../../components/AddPlaidBankAccount';
import CheckboxWithLabel from '../../components/CheckboxWithLabel';
import withLocalize, {withLocalizePropTypes} from '../../components/withLocalize';
import exampleCheckImage from '../../../assets/images/example-check-image.png';
import Text from '../../components/Text';
import ExpensiTextInput from '../../components/ExpensiTextInput';
import {
goToWithdrawalAccountSetupStep,
hideBankAccountErrors,
setupWithdrawalAccount,
} from '../../libs/actions/BankAccounts';
import ConfirmModal from '../../components/ConfirmModal';
import ONYXKEYS from '../../ONYXKEYS';
import compose from '../../libs/compose';
const propTypes = {
/** Bank account currently in setup */
reimbursementAccount: PropTypes.shape({
/** Error set when handling the API response */
error: PropTypes.string,
/** The existing owners for if the bank account is already owned */
existingOwners: PropTypes.arrayOf(PropTypes.string),
}).isRequired,
...withLocalizePropTypes,
};
class BankAccountStep extends React.Component {
constructor(props) {
super(props);
this.toggleTerms = this.toggleTerms.bind(this);
this.addManualAccount = this.addManualAccount.bind(this);
this.addPlaidAccount = this.addPlaidAccount.bind(this);
this.state = {
// One of CONST.BANK_ACCOUNT.SETUP_TYPE
bankAccountAddMethod: props.achData.subStep || undefined,
hasAcceptedTerms: props.achData.acceptTerms || true,
routingNumber: props.achData.routingNumber || '',
accountNumber: props.achData.accountNumber || '',
};
}
toggleTerms() {
this.setState(prevState => ({
hasAcceptedTerms: !prevState.hasAcceptedTerms,
}));
}
/**
* @returns {Boolean}
*/
canSubmitManually() {
return this.state.hasAcceptedTerms
// These are taken from BankCountry.js in Web-Secure
&& CONST.BANK_ACCOUNT.REGEX.IBAN.test(this.state.accountNumber.trim())
&& CONST.BANK_ACCOUNT.REGEX.SWIFT_BIC.test(this.state.routingNumber.trim());
}
addManualAccount() {
setupWithdrawalAccount({
acceptTerms: this.state.hasAcceptedTerms,
accountNumber: this.state.accountNumber,
routingNumber: this.state.routingNumber,
setupType: CONST.BANK_ACCOUNT.SETUP_TYPE.MANUAL,
// Note: These are hardcoded as we're not supporting AU bank accounts for the free plan
country: CONST.COUNTRY.US,
currency: CONST.CURRENCY.USD,
fieldsType: CONST.BANK_ACCOUNT.FIELDS_TYPE.LOCAL,
});
}
/**
* @param {Object} params
* @param {String} params.password
* @param {Object} params.account
* @param {String} params.account.bankName
* @param {Boolean} params.account.isSavings
* @param {String} params.account.addressName
* @param {String} params.account.ownershipType
* @param {String} params.account.accountNumber
* @param {String} params.account.routingNumber
* @param {String} params.account.plaidAccountID
*/
addPlaidAccount(params) {
setupWithdrawalAccount({
acceptTerms: true,
setupType: CONST.BANK_ACCOUNT.SETUP_TYPE.PLAID,
// Params passed via the Plaid callback when an account is selected
password: params.password,
plaidAccessToken: params.plaidLinkToken,
accountNumber: params.account.accountNumber,
routingNumber: params.account.routingNumber,
plaidAccountID: params.account.plaidAccountID,
ownershipType: params.account.ownershipType,
isSavings: params.account.isSavings,
bankName: params.account.bankName,
addressName: params.account.addressName,
// Note: These are hardcoded as we're not supporting AU bank accounts for the free plan
country: CONST.COUNTRY.US,
currency: CONST.CURRENCY.USD,
fieldsType: CONST.BANK_ACCOUNT.FIELDS_TYPE.LOCAL,
});
}
render() {
// Disable bank account fields once they've been added in db so they can't be changed
const isFromPlaid = this.props.achData.setupType === CONST.BANK_ACCOUNT.SETUP_TYPE.PLAID;
const shouldDisableInputs = Boolean(this.props.achData.bankAccountID) || isFromPlaid;
const existingOwners = this.props.reimbursementAccount.existingOwners;
const error = this.props.reimbursementAccount.error;
const isExistingOwnersErrorVisible = Boolean(error && existingOwners);
return (
<View style={[styles.flex1, styles.justifyContentBetween]}>
<HeaderWithCloseButton
title={this.props.translate('bankAccount.addBankAccount')}
onCloseButtonPress={Navigation.dismissModal}
onBackButtonPress={() => this.setState({bankAccountAddMethod: undefined})}
shouldShowBackButton={!_.isUndefined(this.state.bankAccountAddMethod)}
/>
{!this.state.bankAccountAddMethod && (
<>
<View style={[styles.flex1]}>
<Text style={[styles.mh5, styles.mb5]}>
{this.props.translate('bankAccount.toGetStarted')}
</Text>
<MenuItem
icon={Bank}
title={this.props.translate('bankAccount.logIntoYourBank')}
onPress={() => {
this.setState({bankAccountAddMethod: CONST.BANK_ACCOUNT.SETUP_TYPE.PLAID});
}}
disabled={this.props.isPlaidDisabled}
shouldShowRightIcon
/>
{this.props.isPlaidDisabled && (
<Text style={[styles.formError, styles.mh5]}>
{this.props.translate('bankAccount.error.tooManyAttempts')}
</Text>
)}
<MenuItem
icon={Paycheck}
title={this.props.translate('bankAccount.connectManually')}
onPress={() => {
this.setState({bankAccountAddMethod: CONST.BANK_ACCOUNT.SETUP_TYPE.MANUAL});
}}
shouldShowRightIcon
/>
<View style={[styles.m5, styles.flexRow, styles.justifyContentBetween]}>
<TextLink href="https://use.expensify.com/privacy">
{this.props.translate('common.privacy')}
</TextLink>
<View style={[styles.flexRow, styles.alignItemsCenter]}>
<TextLink
// eslint-disable-next-line max-len
href="https://community.expensify.com/discussion/5677/deep-dive-how-expensify-protects-your-information/"
>
{this.props.translate('bankAccount.yourDataIsSecure')}
</TextLink>
<View style={[styles.ml1]}>
<Icon src={Lock} fill={colors.blue} />
</View>
</View>
</View>
</View>
</>
)}
{this.state.bankAccountAddMethod === CONST.BANK_ACCOUNT.SETUP_TYPE.PLAID && (
<AddPlaidBankAccount
text={this.props.translate('bankAccount.plaidBodyCopy')}
onSubmit={this.addPlaidAccount}
onExitPlaid={() => {
this.setState({bankAccountAddMethod: undefined});
}}
/>
)}
{this.state.bankAccountAddMethod === CONST.BANK_ACCOUNT.SETUP_TYPE.MANUAL && (
<>
<View style={[styles.m5, styles.flex1]}>
<Text style={[styles.mb5]}>
{this.props.translate('bankAccount.checkHelpLine')}
</Text>
<Image
resizeMode="contain"
style={[styles.exampleCheckImage, styles.mb5]}
source={exampleCheckImage}
/>
<ExpensiTextInput
placeholder={this.props.translate('bankAccount.routingNumber')}
keyboardType="number-pad"
value={this.state.routingNumber}
onChangeText={(routingNumber) => {
if (error === this.props.translate('bankAccount.error.routingNumber')) {
hideBankAccountErrors();
}
this.setState({routingNumber});
}}
disabled={shouldDisableInputs}
errorText={error === this.props.translate('bankAccount.error.routingNumber')
? error : ''}
/>
<ExpensiTextInput
placeholder={this.props.translate('bankAccount.accountNumber')}
keyboardType="number-pad"
value={this.state.accountNumber}
onChangeText={accountNumber => this.setState({accountNumber})}
disabled={shouldDisableInputs}
/>
<CheckboxWithLabel
style={[styles.mb4, styles.mt5]}
isChecked={this.state.hasAcceptedTerms}
onPress={this.toggleTerms}
LabelComponent={() => (
<View style={[styles.flexRow, styles.alignItemsCenter]}>
<Text>
{this.props.translate('common.iAcceptThe')}
</Text>
<TextLink href="https://use.expensify.com/terms">
{`Expensify ${this.props.translate('common.termsOfService')}`}
</TextLink>
</View>
)}
/>
</View>
<Button
success
text={this.props.translate('common.saveAndContinue')}
style={[styles.m5]}
isDisabled={!this.canSubmitManually()}
onPress={this.addManualAccount}
/>
</>
)}
<ConfirmModal
title={this.props.translate('bankAccount.error.existingOwners.unableToAddBankAccount')}
isVisible={isExistingOwnersErrorVisible}
onConfirm={hideBankAccountErrors}
shouldShowCancelButton={false}
prompt={(
<View>
<Text style={[styles.mb4]}>
<Text>
{this.props.translate('bankAccount.error.existingOwners.alreadyInUse')}
</Text>
{existingOwners && existingOwners.map((existingOwner, i) => {
let separator = ', ';
if (i === 0) {
separator = '';
} else if (i === existingOwners.length - 1) {
separator = ` ${this.props.translate('common.and')} `;
}
return (
<>
<Text>{separator}</Text>
<Text style={styles.textStrong}>{existingOwner}</Text>
{i === existingOwners.length - 1 && <Text>.</Text>}
</>
);
})}
</Text>
<Text style={[styles.mb4]}>
{this.props.translate('bankAccount.error.existingOwners.pleaseAskThemToShare')}
</Text>
<Text>
<Text>
{this.props.translate('bankAccount.error.existingOwners.alternatively')}
</Text>
<Text
style={styles.link}
onPress={() => goToWithdrawalAccountSetupStep(
CONST.BANK_ACCOUNT.STEP.COMPANY,
this.props.achData,
)}
>
{this.props.translate(
'bankAccount.error.existingOwners.setUpThisAccountByYourself',
)}
</Text>
<Text>
{this.props.translate('bankAccount.error.existingOwners.validationProcessAgain')}
</Text>
</Text>
</View>
)}
confirmText={this.props.translate('common.ok')}
/>
</View>
);
}
}
BankAccountStep.propTypes = propTypes;
export default compose(
withLocalize,
withOnyx({
reimbursementAccount: {
key: ONYXKEYS.REIMBURSEMENT_ACCOUNT,
},
}),
)(BankAccountStep);