-
Notifications
You must be signed in to change notification settings - Fork 2.9k
/
BankAccountStep.tsx
218 lines (202 loc) · 9.75 KB
/
BankAccountStep.tsx
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
import React from 'react';
import {View} from 'react-native';
import type {OnyxEntry} from 'react-native-onyx';
import {withOnyx} from 'react-native-onyx';
import Button from '@components/Button';
import HeaderWithBackButton from '@components/HeaderWithBackButton';
import Icon from '@components/Icon';
import * as Expensicons from '@components/Icon/Expensicons';
import * as Illustrations from '@components/Icon/Illustrations';
import MenuItem from '@components/MenuItem';
import PressableWithoutFeedback from '@components/Pressable/PressableWithoutFeedback';
import ScreenWrapper from '@components/ScreenWrapper';
import ScrollView from '@components/ScrollView';
import Section from '@components/Section';
import Text from '@components/Text';
import TextLink from '@components/TextLink';
import useLocalize from '@hooks/useLocalize';
import useTheme from '@hooks/useTheme';
import useThemeStyles from '@hooks/useThemeStyles';
import getPlaidDesktopMessage from '@libs/getPlaidDesktopMessage';
import variables from '@styles/variables';
import * as BankAccounts from '@userActions/BankAccounts';
import * as Link from '@userActions/Link';
import * as ReimbursementAccount from '@userActions/ReimbursementAccount';
import * as Session from '@userActions/Session';
import CONFIG from '@src/CONFIG';
import CONST from '@src/CONST';
import ONYXKEYS from '@src/ONYXKEYS';
import ROUTES from '@src/ROUTES';
import type {ReimbursementAccountForm} from '@src/types/form/ReimbursementAccountForm';
import INPUT_IDS from '@src/types/form/ReimbursementAccountForm';
import type * as OnyxTypes from '@src/types/onyx';
import BankInfo from './BankInfo/BankInfo';
type BankAccountStepOnyxProps = {
/** Object with various information about the user */
user: OnyxEntry<OnyxTypes.User>;
/** If the plaid button has been disabled */
isPlaidDisabled: OnyxEntry<boolean>;
};
type BankAccountStepProps = BankAccountStepOnyxProps & {
/** The OAuth URI + stateID needed to re-initialize the PlaidLink after the user logs into their bank */
receivedRedirectURI?: string | null;
/** During the OAuth flow we need to use the plaidLink token that we initially connected with */
plaidLinkOAuthToken?: OnyxEntry<string>;
/* The workspace name */
policyName?: string;
/* The workspace ID */
policyID?: string;
/** The bank account currently in setup */
reimbursementAccount: OnyxEntry<OnyxTypes.ReimbursementAccount>;
/** Goes to the previous step */
onBackButtonPress: () => void;
};
const bankInfoStepKeys = INPUT_IDS.BANK_INFO_STEP;
function BankAccountStep({
plaidLinkOAuthToken = '',
policyID = '',
policyName = '',
user,
receivedRedirectURI,
reimbursementAccount,
onBackButtonPress,
isPlaidDisabled = false,
}: BankAccountStepProps) {
const theme = useTheme();
const styles = useThemeStyles();
const {translate} = useLocalize();
let subStep = reimbursementAccount?.achData?.subStep ?? '';
const shouldReinitializePlaidLink = plaidLinkOAuthToken && receivedRedirectURI && subStep !== CONST.BANK_ACCOUNT.SUBSTEP.MANUAL;
if (shouldReinitializePlaidLink) {
subStep = CONST.BANK_ACCOUNT.SETUP_TYPE.PLAID;
}
const plaidDesktopMessage = getPlaidDesktopMessage();
const bankAccountRoute = `${CONFIG.EXPENSIFY.NEW_EXPENSIFY_URL}${ROUTES.BANK_ACCOUNT_WITH_STEP_TO_OPEN.getRoute('new', policyID, ROUTES.WORKSPACE_INITIAL.getRoute(policyID))}`;
const removeExistingBankAccountDetails = () => {
const bankAccountData: Partial<ReimbursementAccountForm> = {
[bankInfoStepKeys.ROUTING_NUMBER]: '',
[bankInfoStepKeys.ACCOUNT_NUMBER]: '',
[bankInfoStepKeys.PLAID_MASK]: '',
[bankInfoStepKeys.IS_SAVINGS]: undefined,
[bankInfoStepKeys.BANK_NAME]: '',
[bankInfoStepKeys.PLAID_ACCOUNT_ID]: '',
[bankInfoStepKeys.PLAID_ACCESS_TOKEN]: '',
};
ReimbursementAccount.updateReimbursementAccountDraft(bankAccountData);
};
if (subStep === CONST.BANK_ACCOUNT.SETUP_TYPE.PLAID || subStep === CONST.BANK_ACCOUNT.SETUP_TYPE.MANUAL) {
return (
<BankInfo
onBackButtonPress={onBackButtonPress}
policyID={policyID}
/>
);
}
return (
<ScreenWrapper
includeSafeAreaPaddingBottom={false}
testID={BankAccountStep.displayName}
>
<View style={[styles.flex1, styles.justifyContentBetween]}>
<HeaderWithBackButton
title={translate('workspace.common.connectBankAccount')}
subtitle={policyName}
stepCounter={subStep ? {step: 1, total: 5} : undefined}
onBackButtonPress={onBackButtonPress}
shouldShowGetAssistanceButton
guidesCallTaskID={CONST.GUIDES_CALL_TASK_IDS.WORKSPACE_BANK_ACCOUNT}
/>
<ScrollView style={styles.flex1}>
<Section
icon={Illustrations.MoneyWings}
title={translate('workspace.bankAccount.streamlinePayments')}
>
<View style={styles.mv3}>
<Text>{translate('bankAccount.toGetStarted')}</Text>
</View>
{!!plaidDesktopMessage && (
<View style={[styles.mv3, styles.flexRow, styles.justifyContentBetween]}>
<TextLink href={bankAccountRoute}>{translate(plaidDesktopMessage)}</TextLink>
</View>
)}
<Button
icon={Expensicons.Bank}
iconStyles={[styles.customMarginButtonWithMenuItem]}
text={translate('bankAccount.connectOnlineWithPlaid')}
onPress={() => {
if (!!isPlaidDisabled || !user?.validated) {
return;
}
removeExistingBankAccountDetails();
BankAccounts.openPlaidView();
}}
isDisabled={!!isPlaidDisabled || !user?.validated}
style={[styles.mt4]}
shouldShowRightIcon
success
innerStyles={[styles.pr2, styles.pl4, styles.h13]}
/>
<View style={styles.mv3}>
<MenuItem
icon={Expensicons.Connect}
title={translate('bankAccount.connectManually')}
disabled={!user?.validated}
onPress={() => {
removeExistingBankAccountDetails();
BankAccounts.setBankAccountSubStep(CONST.BANK_ACCOUNT.SETUP_TYPE.MANUAL);
}}
shouldShowRightIcon
wrapperStyle={[styles.cardMenuItem]}
/>
</View>
</Section>
{!user?.validated && (
<View style={[styles.flexRow, styles.alignItemsCenter, styles.m4]}>
<Icon
src={Expensicons.Exclamation}
fill={theme.danger}
/>
<Text style={[styles.mutedTextLabel, styles.ml4, styles.flex1]}>
{translate('bankAccount.validateAccountError.phrase1')}
<TextLink
fontSize={variables.fontSizeLabel}
onPress={() => Session.signOutAndRedirectToSignIn()}
>
{translate('bankAccount.validateAccountError.phrase2')}
</TextLink>
.
</Text>
</View>
)}
<View style={[styles.mv0, styles.mh5, styles.flexRow, styles.justifyContentBetween]}>
<TextLink href={CONST.PRIVACY_URL}>{translate('common.privacy')}</TextLink>
<PressableWithoutFeedback
onPress={() => Link.openExternalLink('https://community.expensify.com/discussion/5677/deep-dive-how-expensify-protects-your-information/')}
style={[styles.flexRow, styles.alignItemsCenter]}
accessibilityLabel={translate('bankAccount.yourDataIsSecure')}
>
<TextLink href="https://community.expensify.com/discussion/5677/deep-dive-how-expensify-protects-your-information/">
{translate('bankAccount.yourDataIsSecure')}
</TextLink>
<View style={styles.ml1}>
<Icon
src={Expensicons.Lock}
fill={theme.link}
/>
</View>
</PressableWithoutFeedback>
</View>
</ScrollView>
</View>
</ScreenWrapper>
);
}
BankAccountStep.displayName = 'BankAccountStep';
export default withOnyx<BankAccountStepProps, BankAccountStepOnyxProps>({
user: {
key: ONYXKEYS.USER,
},
isPlaidDisabled: {
key: ONYXKEYS.IS_PLAID_DISABLED,
},
})(BankAccountStep);