-
Notifications
You must be signed in to change notification settings - Fork 3.1k
/
Copy pathBankAccountManualStep.js
144 lines (135 loc) · 6.21 KB
/
BankAccountManualStep.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
import React from 'react';
import {Image, View} from 'react-native';
import {withOnyx} from 'react-native-onyx';
import HeaderWithCloseButton from '../../components/HeaderWithCloseButton';
import CONST from '../../CONST';
import * as BankAccounts from '../../libs/actions/BankAccounts';
import Navigation from '../../libs/Navigation/Navigation';
import Text from '../../components/Text';
import TextInput from '../../components/TextInput';
import styles from '../../styles/styles';
import CheckboxWithLabel from '../../components/CheckboxWithLabel';
import TextLink from '../../components/TextLink';
import withLocalize, {withLocalizePropTypes} from '../../components/withLocalize';
import * as ValidationUtils from '../../libs/ValidationUtils';
import compose from '../../libs/compose';
import ONYXKEYS from '../../ONYXKEYS';
import exampleCheckImage from './exampleCheckImage';
import Form from '../../components/Form';
import * as ReimbursementAccountUtils from '../../libs/ReimbursementAccountUtils';
const propTypes = {
...withLocalizePropTypes,
};
class BankAccountManualStep extends React.Component {
constructor(props) {
super(props);
this.submit = this.submit.bind(this);
this.validate = this.validate.bind(this);
}
/**
* @param {Object} values - form input values passed by the Form component
* @returns {Object}
*/
validate(values) {
const errorFields = {};
const routingNumber = values.routingNumber && values.routingNumber.trim();
if (
!values.accountNumber
|| (!CONST.BANK_ACCOUNT.REGEX.US_ACCOUNT_NUMBER.test(values.accountNumber.trim()) && !CONST.BANK_ACCOUNT.REGEX.MASKED_US_ACCOUNT_NUMBER.test(values.accountNumber.trim()))
) {
errorFields.accountNumber = this.props.translate('bankAccount.error.accountNumber');
}
if (!routingNumber || !CONST.BANK_ACCOUNT.REGEX.SWIFT_BIC.test(routingNumber) || !ValidationUtils.isValidRoutingNumber(routingNumber)) {
errorFields.routingNumber = this.props.translate('bankAccount.error.routingNumber');
}
if (!values.acceptedTerms) {
errorFields.acceptedTerms = this.props.translate('common.error.acceptedTerms');
}
return errorFields;
}
submit(values) {
BankAccounts.connectBankAccountManually(
ReimbursementAccountUtils.getDefaultStateForField(this.props, 'bankAccountID', 0),
values.accountNumber,
values.routingNumber,
ReimbursementAccountUtils.getDefaultStateForField(this.props, 'plaidMask'),
);
}
render() {
const shouldDisableInputs = Boolean(ReimbursementAccountUtils.getDefaultStateForField(this.props, 'bankAccountID'));
return (
<>
<HeaderWithCloseButton
title={this.props.translate('workspace.common.bankAccount')}
stepCounter={{step: 1, total: 5}}
shouldShowGetAssistanceButton
guidesCallTaskID={CONST.GUIDES_CALL_TASK_IDS.WORKSPACE_BANK_ACCOUNT}
shouldShowBackButton
onBackButtonPress={() => BankAccounts.setBankAccountSubStep(null)}
onCloseButtonPress={Navigation.dismissModal}
/>
<Form
formID={ONYXKEYS.FORMS.REIMBURSEMENT_ACCOUNT_FORM}
onSubmit={this.submit}
validate={this.validate}
submitButtonText={this.props.translate('common.saveAndContinue')}
style={[styles.mh5, styles.flexGrow1]}
>
<Text style={[styles.mb5]}>
{this.props.translate('bankAccount.checkHelpLine')}
</Text>
<Image
resizeMode="contain"
style={[styles.exampleCheckImage, styles.mb5]}
source={exampleCheckImage(this.props.preferredLocale)}
/>
<TextInput
inputID="routingNumber"
label={this.props.translate('bankAccount.routingNumber')}
defaultValue={ReimbursementAccountUtils.getDefaultStateForField(this.props, 'routingNumber', '')}
keyboardType={CONST.KEYBOARD_TYPE.NUMBER_PAD}
disabled={shouldDisableInputs}
shouldSaveDraft
/>
<TextInput
inputID="accountNumber"
containerStyles={[styles.mt4]}
label={this.props.translate('bankAccount.accountNumber')}
defaultValue={ReimbursementAccountUtils.getDefaultStateForField(this.props, 'accountNumber', '')}
keyboardType={CONST.KEYBOARD_TYPE.NUMBER_PAD}
disabled={shouldDisableInputs}
shouldSaveDraft
/>
<CheckboxWithLabel
style={styles.mt4}
inputID="acceptedTerms"
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>
)}
defaultValue={ReimbursementAccountUtils.getDefaultStateForField(this.props, 'acceptTerms', false)}
/>
</Form>
</>
);
}
}
BankAccountManualStep.propTypes = propTypes;
export default compose(
withLocalize,
withOnyx({
// Needed to retrieve errorFields
reimbursementAccount: {
key: ONYXKEYS.REIMBURSEMENT_ACCOUNT,
},
reimbursementAccountDraft: {
key: ONYXKEYS.REIMBURSEMENT_ACCOUNT_DRAFT,
},
}),
)(BankAccountManualStep);