-
Notifications
You must be signed in to change notification settings - Fork 3k
/
Copy pathAddPaymentMethodMenu.js
106 lines (94 loc) · 3.31 KB
/
AddPaymentMethodMenu.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
import React from 'react';
import PropTypes from 'prop-types';
import {withOnyx} from 'react-native-onyx';
import * as Expensicons from './Icon/Expensicons';
import withLocalize, {withLocalizePropTypes} from './withLocalize';
import compose from '../libs/compose';
import ONYXKEYS from '../ONYXKEYS';
import CONST from '../CONST';
import withWindowDimensions from './withWindowDimensions';
import Permissions from '../libs/Permissions';
import PopoverMenu from './PopoverMenu';
import refPropTypes from './refPropTypes';
import paypalMeDataPropTypes from './paypalMeDataPropTypes';
const propTypes = {
/** Should the component be visible? */
isVisible: PropTypes.bool.isRequired,
/** Callback to execute when the component closes. */
onClose: PropTypes.func.isRequired,
/** Anchor position for the AddPaymentMenu. */
anchorPosition: PropTypes.shape({
horizontal: PropTypes.number,
vertical: PropTypes.number,
}),
/** Account details for PayPal.Me */
payPalMeData: paypalMeDataPropTypes,
/** Should we show the Paypal option */
shouldShowPaypal: PropTypes.bool,
/** List of betas available to current user */
betas: PropTypes.arrayOf(PropTypes.string),
/** Popover anchor ref */
anchorRef: refPropTypes,
...withLocalizePropTypes,
};
const defaultProps = {
anchorPosition: {},
payPalMeData: {},
shouldShowPaypal: true,
betas: [],
anchorRef: () => {},
};
function AddPaymentMethodMenu(props) {
return (
<PopoverMenu
isVisible={props.isVisible}
onClose={props.onClose}
anchorPosition={props.anchorPosition}
anchorRef={props.anchorRef}
onItemSelected={props.onClose}
menuItems={[
{
text: props.translate('common.bankAccount'),
icon: Expensicons.Bank,
onSelected: () => {
props.onItemSelected(CONST.PAYMENT_METHODS.BANK_ACCOUNT);
},
},
...(Permissions.canUseWallet(props.betas)
? [
{
text: props.translate('common.debitCard'),
icon: Expensicons.CreditCard,
onSelected: () => props.onItemSelected(CONST.PAYMENT_METHODS.DEBIT_CARD),
},
]
: []),
...(props.shouldShowPaypal && !props.payPalMeData.description
? [
{
text: props.translate('common.payPalMe'),
icon: Expensicons.PayPal,
onSelected: () => props.onItemSelected(CONST.PAYMENT_METHODS.PAYPAL),
},
]
: []),
]}
withoutOverlay
/>
);
}
AddPaymentMethodMenu.propTypes = propTypes;
AddPaymentMethodMenu.defaultProps = defaultProps;
AddPaymentMethodMenu.displayName = 'AddPaymentMethodMenu';
export default compose(
withWindowDimensions,
withLocalize,
withOnyx({
payPalMeData: {
key: ONYXKEYS.PAYPAL,
},
betas: {
key: ONYXKEYS.BETAS,
},
}),
)(AddPaymentMethodMenu);