-
Notifications
You must be signed in to change notification settings - Fork 3k
/
Copy pathWorkspaceBankAccountPage.js
140 lines (125 loc) · 5.1 KB
/
WorkspaceBankAccountPage.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
import lodashGet from 'lodash/get';
import React from 'react';
import {ScrollView} from 'react-native';
import {withOnyx} from 'react-native-onyx';
import HeaderWithCloseButton from '../../components/HeaderWithCloseButton';
import * as Expensicons from '../../components/Icon/Expensicons';
import * as Illustrations from '../../components/Icon/Illustrations';
import ScreenWrapper from '../../components/ScreenWrapper';
import Text from '../../components/Text';
import withLocalize, {withLocalizePropTypes} from '../../components/withLocalize';
import * as BankAccounts from '../../libs/actions/BankAccounts';
import compose from '../../libs/compose';
import BankAccount from '../../libs/models/BankAccount';
import Navigation from '../../libs/Navigation/Navigation';
import ONYXKEYS from '../../ONYXKEYS';
import ROUTES from '../../ROUTES';
import reimbursementAccountPropTypes from '../ReimbursementAccount/reimbursementAccountPropTypes';
import Section from '../../components/Section';
import WorkspaceResetBankAccountModal from './WorkspaceResetBankAccountModal';
import styles from '../../styles/styles';
import CONST from '../../CONST';
const propTypes = {
/** ACH data for the withdrawal account actively being set up */
reimbursementAccount: reimbursementAccountPropTypes,
...withLocalizePropTypes,
};
const defaultProps = {
reimbursementAccount: {
loading: true,
},
};
class WorkspaceBankAccountPage extends React.Component {
constructor(props) {
super(props);
this.onScreenFocus = this.onScreenFocus.bind(this);
this.getShouldShowPage = this.getShouldShowPage.bind(this);
this.navigateToBankAccountRoute = this.navigateToBankAccountRoute.bind(this);
}
componentDidMount() {
this.unsubscribe = this.props.navigation.addListener('focus', this.onScreenFocus);
}
componentWillUnmount() {
if (!this.unsubscribe) {
return;
}
this.unsubscribe();
}
/**
* When we are returning to this screen we want to check if we should go back or show the alternate view with "Continue with setup" button.
*/
onScreenFocus() {
if (this.getShouldShowPage()) {
return;
}
this.props.navigation.goBack();
}
/**
* If we have an open bank account or no bank account at all then we will immediately redirect the user to /bank-account to display the next step
*
* @returns {Boolean}
*/
getShouldShowPage() {
const state = lodashGet(this.props.reimbursementAccount, 'achData.state');
return lodashGet(this.props.reimbursementAccount, 'achData.bankAccountID') && state !== BankAccount.STATE.OPEN;
}
/**
* Navigate to the bank account route
*/
navigateToBankAccountRoute() {
Navigation.navigate(ROUTES.getBankAccountRoute());
}
render() {
if (!this.getShouldShowPage()) {
this.navigateToBankAccountRoute();
return null;
}
return (
<ScreenWrapper>
<HeaderWithCloseButton
title={this.props.translate('workspace.common.bankAccount')}
onCloseButtonPress={Navigation.dismissModal}
onBackButtonPress={() => Navigation.navigate(ROUTES.getWorkspaceInitialRoute(this.props.route.params.policyID))}
shouldShowGetAssistanceButton
guidesCallTaskID={CONST.GUIDES_CALL_TASK_IDS.WORKSPACE_BANK_ACCOUNT}
shouldShowBackButton
/>
<ScrollView style={styles.flex1}>
<Section
title={this.props.translate('workspace.bankAccount.almostDone')}
icon={Illustrations.BankArrowPink}
menuItems={[
{
title: this.props.translate('workspace.bankAccount.continueWithSetup'),
icon: Expensicons.Bank,
onPress: this.navigateToBankAccountRoute,
shouldShowRightIcon: true,
},
{
title: this.props.translate('workspace.bankAccount.startOver'),
icon: Expensicons.RotateLeft,
onPress: BankAccounts.requestResetFreePlanBankAccount,
shouldShowRightIcon: true,
},
]}
>
<Text>
{this.props.translate('workspace.bankAccount.youreAlmostDone')}
</Text>
</Section>
</ScrollView>
<WorkspaceResetBankAccountModal />
</ScreenWrapper>
);
}
}
WorkspaceBankAccountPage.propTypes = propTypes;
WorkspaceBankAccountPage.defaultProps = defaultProps;
export default compose(
withLocalize,
withOnyx({
reimbursementAccount: {
key: ONYXKEYS.REIMBURSEMENT_ACCOUNT,
},
}),
)(WorkspaceBankAccountPage);