-
Notifications
You must be signed in to change notification settings - Fork 2.8k
/
WorkspaceOwnerPaymentCardForm.tsx
155 lines (142 loc) · 7.15 KB
/
WorkspaceOwnerPaymentCardForm.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
import React, {useCallback, useEffect, useState} from 'react';
import {View} from 'react-native';
import type {OnyxEntry} from 'react-native-onyx';
import PaymentCardForm from '@components/AddPaymentCard/PaymentCardForm';
import type {FormOnyxValues} from '@components/Form/types';
import Icon from '@components/Icon';
import * as Expensicons from '@components/Icon/Expensicons';
import * as Illustrations from '@components/Icon/Illustrations';
import Section, {CARD_LAYOUT} 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 * as CardUtils from '@libs/CardUtils';
import * as PaymentMethods from '@userActions/PaymentMethods';
import * as PolicyActions from '@userActions/Policy/Policy';
import CONST from '@src/CONST';
import type ONYXKEYS from '@src/ONYXKEYS';
import type * as OnyxTypes from '@src/types/onyx';
type WorkspaceOwnerPaymentCardFormProps = {
/** The policy */
policy: OnyxEntry<OnyxTypes.Policy>;
};
function WorkspaceOwnerPaymentCardForm({policy}: WorkspaceOwnerPaymentCardFormProps) {
const {translate} = useLocalize();
const theme = useTheme();
const styles = useThemeStyles();
const [shouldShowPaymentCardForm, setShouldShowPaymentCardForm] = useState(false);
const policyID = policy?.id ?? '-1';
const checkIfCanBeRendered = useCallback(() => {
const changeOwnerErrors = Object.keys(policy?.errorFields?.changeOwner ?? {});
if (changeOwnerErrors[0] !== CONST.POLICY.OWNERSHIP_ERRORS.NO_BILLING_CARD) {
setShouldShowPaymentCardForm(false);
}
setShouldShowPaymentCardForm(true);
}, [policy?.errorFields?.changeOwner]);
useEffect(
() => {
PaymentMethods.clearPaymentCardFormErrorAndSubmit();
checkIfCanBeRendered();
return () => {
PaymentMethods.clearPaymentCardFormErrorAndSubmit();
};
},
// eslint-disable-next-line react-compiler/react-compiler, react-hooks/exhaustive-deps
[],
);
useEffect(() => {
checkIfCanBeRendered();
}, [checkIfCanBeRendered]);
const addPaymentCard = useCallback(
(values: FormOnyxValues<typeof ONYXKEYS.FORMS.ADD_PAYMENT_CARD_FORM>) => {
const cardData = {
cardNumber: CardUtils.getMCardNumberString(values.cardNumber),
cardMonth: CardUtils.getMonthFromExpirationDateString(values.expirationDate),
cardYear: CardUtils.getYearFromExpirationDateString(values.expirationDate),
cardCVV: values.securityCode,
addressName: values.nameOnCard,
addressZip: values.addressZipCode,
currency: CONST.CURRENCY.USD,
};
PolicyActions.addBillingCardAndRequestPolicyOwnerChange(policyID, cardData);
},
[policyID],
);
return (
<PaymentCardForm
shouldShowPaymentCardForm={shouldShowPaymentCardForm}
addPaymentCard={addPaymentCard}
showCurrencyField
submitButtonText={translate('workspace.changeOwner.addPaymentCardButtonText')}
headerContent={<Text style={[styles.textHeadline, styles.mt3, styles.mb2, styles.ph5]}>{translate('workspace.changeOwner.addPaymentCardTitle')}</Text>}
footerContent={
<>
<Text style={[styles.textMicroSupporting, styles.mt5]}>
{translate('workspace.changeOwner.addPaymentCardReadAndAcceptTextPart1')}{' '}
<TextLink
style={[styles.textMicroSupporting, styles.link]}
href={CONST.TERMS_URL}
>
{translate('workspace.changeOwner.addPaymentCardTerms')}
</TextLink>{' '}
{translate('workspace.changeOwner.addPaymentCardAnd')}{' '}
<TextLink
style={[styles.textMicroSupporting, styles.link]}
href={CONST.PRIVACY_URL}
>
{translate('workspace.changeOwner.addPaymentCardPrivacy')}
</TextLink>{' '}
{translate('workspace.changeOwner.addPaymentCardReadAndAcceptTextPart2')}
</Text>
<Section
icon={Illustrations.ShieldYellow}
cardLayout={CARD_LAYOUT.ICON_ON_LEFT}
title={translate('requestorStep.isMyDataSafe')}
containerStyles={[styles.mh0, styles.mt5]}
>
<View style={[styles.mt4, styles.ph2, styles.pb2]}>
<Text style={[styles.searchInputStyle, styles.dFlex, styles.alignItemsCenter]}>
<Icon
src={Expensicons.Checkmark}
additionalStyles={[styles.mr3]}
fill={theme.iconSuccessFill}
/>
{translate('workspace.changeOwner.addPaymentCardPciCompliant')}
</Text>
<Text style={[styles.mt3, styles.searchInputStyle, styles.dFlex, styles.alignItemsCenter]}>
<Icon
src={Expensicons.Checkmark}
additionalStyles={[styles.mr3]}
fill={theme.iconSuccessFill}
/>
{translate('workspace.changeOwner.addPaymentCardBankLevelEncrypt')}
</Text>
<Text style={[styles.mt3, styles.searchInputStyle, styles.dFlex, styles.alignItemsCenter]}>
<Icon
src={Expensicons.Checkmark}
additionalStyles={[styles.mr3]}
fill={theme.iconSuccessFill}
/>
{translate('workspace.changeOwner.addPaymentCardRedundant')}
</Text>
</View>
<Text style={[styles.mt3, styles.searchInputStyle]}>
{translate('workspace.changeOwner.addPaymentCardLearnMore')}{' '}
<TextLink
style={[styles.searchInputStyle, styles.link]}
href={CONST.PERSONAL_DATA_PROTECTION_INFO_URL}
>
{translate('workspace.changeOwner.addPaymentCardSecurity')}
</TextLink>
.
</Text>
</Section>
</>
}
/>
);
}
WorkspaceOwnerPaymentCardForm.displayName = 'WorkspaceOwnerPaymentCardForm';
export default WorkspaceOwnerPaymentCardForm;