-
Notifications
You must be signed in to change notification settings - Fork 2.9k
/
ReimbursementAccountPage.js
183 lines (163 loc) · 6.32 KB
/
ReimbursementAccountPage.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
import moment from 'moment';
import lodashGet from 'lodash/get';
import React from 'react';
import {withOnyx} from 'react-native-onyx';
import Str from 'expensify-common/lib/str';
import {View, Text} from 'react-native';
import PropTypes from 'prop-types';
import ScreenWrapper from '../../components/ScreenWrapper';
import {fetchFreePlanVerifiedBankAccount} from '../../libs/actions/BankAccounts';
import ONYXKEYS from '../../ONYXKEYS';
import FullScreenLoadingIndicator from '../../components/FullscreenLoadingIndicator';
import Permissions from '../../libs/Permissions';
import Navigation from '../../libs/Navigation/Navigation';
import CONST from '../../CONST';
import withLocalize, {withLocalizePropTypes} from '../../components/withLocalize';
import compose from '../../libs/compose';
import styles from '../../styles/styles';
import KeyboardAvoidingView from '../../components/KeyboardAvoidingView';
// Steps
import BankAccountStep from './BankAccountStep';
import CompanyStep from './CompanyStep';
import RequestorStep from './RequestorStep';
import ValidationStep from './ValidationStep';
import BeneficialOwnersStep from './BeneficialOwnersStep';
const propTypes = {
/** List of betas */
betas: PropTypes.arrayOf(PropTypes.string).isRequired,
/** ACH data for the withdrawal account actively being set up */
reimbursementAccount: PropTypes.shape({
/** Whether we are loading the data via the API */
loading: PropTypes.bool,
/** A date that indicates the user has been throttled */
throttledDate: PropTypes.string,
/** Additional data for the account in setup */
achData: PropTypes.shape({
/** Step of the setup flow that we are on. Determines which view is presented. */
currentStep: PropTypes.string,
}),
}),
/** Current session for the user */
session: PropTypes.shape({
/** User login */
email: PropTypes.string,
}).isRequired,
/** Route object from navigation */
route: PropTypes.shape({
/** Params that are passed into the route */
params: PropTypes.shape({
/** A step to navigate to if we need to drop the user into a specific point in the flow */
stepToOpen: PropTypes.string,
}),
}),
...withLocalizePropTypes,
};
const defaultProps = {
reimbursementAccount: {
loading: true,
},
route: {
params: {
stepToOpen: '',
},
},
};
class ReimbursementAccountPage extends React.Component {
componentDidMount() {
fetchFreePlanVerifiedBankAccount();
}
/**
* @returns {String}
*/
getStepToOpenFromRouteParams() {
switch (lodashGet(this.props.route, ['params', 'stepToOpen'])) {
case 'new':
return CONST.BANK_ACCOUNT.STEP.BANK_ACCOUNT;
case 'company':
return CONST.BANK_ACCOUNT.STEP.COMPANY;
case 'requestor':
return CONST.BANK_ACCOUNT.STEP.REQUESTOR;
case 'contract':
return CONST.BANK_ACCOUNT.STEP.ACH_CONTRACT;
case 'validate':
return CONST.BANK_ACCOUNT.STEP.VALIDATION;
default:
return '';
}
}
render() {
if (!Permissions.canUseFreePlan(this.props.betas)) {
console.debug('Not showing new bank account page because user is not on free plan beta');
Navigation.dismissModal();
return null;
}
if (this.props.reimbursementAccount.loading) {
return <FullScreenLoadingIndicator visible />;
}
const userHasPhonePrimaryEmail = Str.endsWith(this.props.session.email, CONST.SMS.DOMAIN);
if (userHasPhonePrimaryEmail) {
return (
<View style={[styles.m5]}>
<Text>{this.props.translate('bankAccount.hasPhoneLoginError')}</Text>
</View>
);
}
const throttledDate = lodashGet(this.props, 'reimbursementAccount.throttledDate');
if (throttledDate) {
const throttledEnd = moment().add(24, 'hours');
if (moment() < throttledEnd) {
return (
<View style={[styles.m5]}>
<Text>
{this.props.translate('bankAccount.hasBeenThrottledError', {
fromNow: throttledEnd.fromNow(),
})}
</Text>
</View>
);
}
}
// We grab the currentStep from the achData to determine which view to display. The SetupWithdrawalAccount flow
// allows us to continue the flow from various points depending on where the user left off. We can also
// specify a specific step to navigate to by using route params.
const achData = lodashGet(this.props, 'reimbursementAccount.achData', {});
const currentStep = achData.currentStep || CONST.BANK_ACCOUNT.STEP.BANK_ACCOUNT;
return (
<ScreenWrapper>
<KeyboardAvoidingView>
{currentStep === CONST.BANK_ACCOUNT.STEP.BANK_ACCOUNT && (
<BankAccountStep achData={achData} />
)}
{currentStep === CONST.BANK_ACCOUNT.STEP.COMPANY && (
<CompanyStep achData={achData} />
)}
{currentStep === CONST.BANK_ACCOUNT.STEP.REQUESTOR && (
<RequestorStep />
)}
{currentStep === CONST.BANK_ACCOUNT.STEP.ACH_CONTRACT && (
<BeneficialOwnersStep companyName={achData.companyName} />
)}
{currentStep === CONST.BANK_ACCOUNT.STEP.VALIDATION && (
<ValidationStep />
)}
</KeyboardAvoidingView>
</ScreenWrapper>
);
}
}
ReimbursementAccountPage.propTypes = propTypes;
ReimbursementAccountPage.defaultProps = defaultProps;
export default compose(
withOnyx({
reimbursementAccount: {
key: ONYXKEYS.REIMBURSEMENT_ACCOUNT,
},
session: {
key: ONYXKEYS.SESSION,
},
betas: {
key: ONYXKEYS.BETAS,
},
}),
withLocalize,
)(ReimbursementAccountPage);