-
Notifications
You must be signed in to change notification settings - Fork 3k
/
Copy pathConfirmation.tsx
186 lines (173 loc) · 7.56 KB
/
Confirmation.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
import React, {useCallback, useState} from 'react';
import {useOnyx} from 'react-native-onyx';
import CheckboxWithLabel from '@components/CheckboxWithLabel';
import FormProvider from '@components/Form/FormProvider';
import InputWrapper from '@components/Form/InputWrapper';
import type {FormInputErrors, FormOnyxValues} from '@components/Form/types';
import FormHelpMessage from '@components/FormHelpMessage';
import MenuItemWithTopDescription from '@components/MenuItemWithTopDescription';
import ScrollView from '@components/ScrollView';
import Text from '@components/Text';
import TextLink from '@components/TextLink';
import useLocalize from '@hooks/useLocalize';
import useThemeStyles from '@hooks/useThemeStyles';
import type {CustomSubStepProps} from '@pages/settings/Wallet/InternationalDepositAccount/types';
import * as BankAccounts from '@userActions/BankAccounts';
import CONST from '@src/CONST';
import ONYXKEYS from '@src/ONYXKEYS';
const STEP_INDEXES = CONST.CORPAY_FIELDS.INDEXES.MAPPING;
function TermsAndConditionsLabel() {
const {translate} = useLocalize();
return (
<Text>
{translate('common.iAcceptThe')}
<TextLink href={CONST.OLD_DOT_PUBLIC_URLS.TERMS_URL}>{`${translate('common.addCardTermsOfService')}`}</TextLink>
</Text>
);
}
function Confirmation({onNext, onMove, formValues, fieldsMap}: CustomSubStepProps) {
const {translate} = useLocalize();
const styles = useThemeStyles();
const [isSubmitting, setIsSubmitting] = useState(false);
const [error, setError] = useState('');
const [corpayFields] = useOnyx(ONYXKEYS.CORPAY_FIELDS);
const getDataAndGoToNextStep = (values: FormOnyxValues<typeof ONYXKEYS.FORMS.INTERNATIONAL_BANK_ACCOUNT_FORM>) => {
setError('');
setIsSubmitting(true);
BankAccounts.createCorpayBankAccountForWalletFlow(
{...formValues, ...values},
corpayFields?.classification ?? '',
corpayFields?.destinationCountry ?? '',
corpayFields?.preferredMethod ?? '',
).then((response) => {
setIsSubmitting(false);
if (response?.jsonCode) {
if (response.jsonCode === CONST.JSON_CODE.SUCCESS) {
onNext();
} else {
setError(response.message ?? '');
}
}
});
};
const summaryItems = [
{
description: translate('common.country'),
title: formValues.bankCountry,
shouldShowRightIcon: true,
onPress: () => {
onMove(STEP_INDEXES.COUNTRY_SELECTOR);
},
},
{
description: translate('common.currency'),
title: formValues.bankCurrency,
shouldShowRightIcon: true,
onPress: () => {
onMove(STEP_INDEXES.BANK_ACCOUNT_DETAILS);
},
},
];
// eslint-disable-next-line guard-for-in
for (const fieldName in fieldsMap[CONST.CORPAY_FIELDS.STEPS_NAME.BANK_ACCOUNT_DETAILS]) {
summaryItems.push({
description:
fieldsMap[CONST.CORPAY_FIELDS.STEPS_NAME.BANK_ACCOUNT_DETAILS][fieldName].label +
(fieldsMap[CONST.CORPAY_FIELDS.STEPS_NAME.BANK_ACCOUNT_DETAILS][fieldName].isRequired ? '' : ` (${translate('common.optional')})`),
title: formValues[fieldName],
shouldShowRightIcon: true,
onPress: () => {
onMove(STEP_INDEXES.BANK_ACCOUNT_DETAILS);
},
});
}
// eslint-disable-next-line guard-for-in
for (const fieldName in fieldsMap[CONST.CORPAY_FIELDS.STEPS_NAME.ACCOUNT_TYPE]) {
summaryItems.push({
description:
fieldsMap[CONST.CORPAY_FIELDS.STEPS_NAME.ACCOUNT_TYPE][fieldName].label +
(fieldsMap[CONST.CORPAY_FIELDS.STEPS_NAME.ACCOUNT_TYPE][fieldName].isRequired ? '' : ` (${translate('common.optional')})`),
title: formValues[fieldName],
shouldShowRightIcon: true,
onPress: () => {
onMove(STEP_INDEXES.ACCOUNT_TYPE);
},
});
}
// eslint-disable-next-line guard-for-in
for (const fieldName in fieldsMap[CONST.CORPAY_FIELDS.STEPS_NAME.BANK_INFORMATION]) {
summaryItems.push({
description:
fieldsMap[CONST.CORPAY_FIELDS.STEPS_NAME.BANK_INFORMATION][fieldName].label +
(fieldsMap[CONST.CORPAY_FIELDS.STEPS_NAME.BANK_INFORMATION][fieldName].isRequired ? '' : ` (${translate('common.optional')})`),
title: formValues[fieldName],
shouldShowRightIcon: true,
onPress: () => {
onMove(STEP_INDEXES.BANK_INFORMATION);
},
});
}
// eslint-disable-next-line guard-for-in
for (const fieldName in fieldsMap[CONST.CORPAY_FIELDS.STEPS_NAME.ACCOUNT_HOLDER_INFORMATION]) {
summaryItems.push({
description:
fieldsMap[CONST.CORPAY_FIELDS.STEPS_NAME.ACCOUNT_HOLDER_INFORMATION][fieldName].label +
(fieldsMap[CONST.CORPAY_FIELDS.STEPS_NAME.ACCOUNT_HOLDER_INFORMATION][fieldName].isRequired ? '' : ` (${translate('common.optional')})`),
title: formValues[fieldName],
shouldShowRightIcon: true,
onPress: () => {
onMove(STEP_INDEXES.ACCOUNT_HOLDER_INFORMATION);
},
});
}
const validate = useCallback(
(values: FormOnyxValues<typeof ONYXKEYS.FORMS.INTERNATIONAL_BANK_ACCOUNT_FORM>): FormInputErrors<typeof ONYXKEYS.FORMS.INTERNATIONAL_BANK_ACCOUNT_FORM> => {
const errors: FormInputErrors<typeof ONYXKEYS.FORMS.INTERNATIONAL_BANK_ACCOUNT_FORM> = {};
if (!values.acceptTerms) {
errors.acceptTerms = translate('common.error.acceptTerms');
}
return errors;
},
[translate],
);
return (
<ScrollView contentContainerStyle={styles.flexGrow1}>
<Text style={[styles.textHeadlineLineHeightXXL, styles.ph5, styles.mb3]}>{translate('personalInfoStep.letsDoubleCheck')}</Text>
{summaryItems.map(({description, title, shouldShowRightIcon, onPress}) => (
<MenuItemWithTopDescription
key={`${title}_${description}`}
description={description}
title={title}
shouldShowRightIcon={shouldShowRightIcon}
onPress={onPress}
/>
))}
<FormProvider
formID={ONYXKEYS.FORMS.INTERNATIONAL_BANK_ACCOUNT_FORM}
validate={validate}
onSubmit={getDataAndGoToNextStep}
scrollContextEnabled
submitButtonText={translate('common.confirm')}
style={[styles.mh5, styles.flexGrow1]}
enabledWhenOffline={false}
isLoading={isSubmitting}
shouldHideFixErrorsAlert
>
<InputWrapper
InputComponent={CheckboxWithLabel}
aria-label={`${translate('common.iAcceptThe')} ${translate('common.addCardTermsOfService')}`}
inputID="acceptTerms"
LabelComponent={TermsAndConditionsLabel}
style={[styles.mt3]}
/>
<FormHelpMessage
style={[styles.mt3, styles.mbn1]}
isError
message={error}
/>
</FormProvider>
</ScrollView>
);
}
Confirmation.displayName = 'Confirmation';
export default Confirmation;