-
Notifications
You must be signed in to change notification settings - Fork 2.9k
/
AddPayPalMePage.js
115 lines (108 loc) · 5.69 KB
/
AddPayPalMePage.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
import React, {useRef, useState, useCallback} from 'react';
import {View, Linking} from 'react-native';
import _ from 'underscore';
import CONST from '../../../CONST';
import ROUTES from '../../../ROUTES';
import HeaderWithBackButton from '../../../components/HeaderWithBackButton';
import TextLink from '../../../components/TextLink';
import Text from '../../../components/Text';
import ScreenWrapper from '../../../components/ScreenWrapper';
import Navigation from '../../../libs/Navigation/Navigation';
import styles from '../../../styles/styles';
import withLocalize, {withLocalizePropTypes} from '../../../components/withLocalize';
import Button from '../../../components/Button';
import FixedFooter from '../../../components/FixedFooter';
import Growl from '../../../libs/Growl';
import TextInput from '../../../components/TextInput';
import * as ValidationUtils from '../../../libs/ValidationUtils';
import * as User from '../../../libs/actions/User';
import Icon from '../../../components/Icon';
import * as Expensicons from '../../../components/Icon/Expensicons';
import variables from '../../../styles/variables';
import PressableWithoutFeedback from '../../../components/Pressable/PressableWithoutFeedback';
function AddPayPalMePage(props) {
const [payPalMeUsername, setPayPalMeUsername] = useState('');
const [payPalMeUsernameError, setPayPalMeUsernameError] = useState(false);
const payPalMeInput = useRef(null);
const growlMessageOnSave = props.translate('addPayPalMePage.growlMessageOnSave');
/**
* Sets the payPalMe username and error data for the current user
*/
const setPayPalMeData = useCallback(() => {
if (!ValidationUtils.isValidPaypalUsername(payPalMeUsername)) {
setPayPalMeUsernameError(true);
return;
}
setPayPalMeUsernameError(false);
User.addPaypalMeAddress(payPalMeUsername);
Growl.show(growlMessageOnSave, CONST.GROWL.SUCCESS, 3000);
Navigation.navigate(ROUTES.SETTINGS_PAYMENTS);
}, [payPalMeUsername, growlMessageOnSave]);
return (
<ScreenWrapper onEntryTransitionEnd={() => payPalMeInput.current && payPalMeInput.current.focus()}>
<HeaderWithBackButton
title={props.translate('common.payPalMe')}
onBackButtonPress={() => Navigation.goBack(ROUTES.SETTINGS_PAYMENTS)}
/>
<View style={[styles.flex1, styles.p5]}>
<View style={[styles.flex1]}>
<Text style={[styles.mb4]}>{props.translate('addPayPalMePage.enterYourUsernameToGetPaidViaPayPal')}</Text>
<TextInput
ref={payPalMeInput}
label={props.translate('addPayPalMePage.payPalMe')}
autoCompleteType="off"
autoCorrect={false}
value={payPalMeUsername}
placeholder={props.translate('addPayPalMePage.yourPayPalUsername')}
onChangeText={(text) => {
setPayPalMeUsername(text);
setPayPalMeUsernameError(false);
}}
returnKeyType="done"
hasError={payPalMeUsernameError}
errorText={payPalMeUsernameError ? props.translate('addPayPalMePage.formatError') : ''}
/>
<View style={[styles.mt3, styles.flexRow, styles.justifyContentBetween, styles.alignSelfStart]}>
<Text style={[styles.textMicro, styles.flexRow]}>{props.translate('addPayPalMePage.checkListOf')}</Text>
<PressableWithoutFeedback
shouldUseAutoHitSlop={false}
accessibilityRole={CONST.ACCESSIBILITY_ROLE.LINK}
accessibilityLabel={props.translate('addPayPalMePage.supportedCurrencies')}
onPress={() => Linking.openURL('https://developer.paypal.com/docs/reports/reference/paypal-supported-currencies')}
>
<View style={[styles.flexRow, styles.cursorPointer]}>
<TextLink
// eslint-disable-next-line max-len
href="https://developer.paypal.com/docs/reports/reference/paypal-supported-currencies"
style={[styles.textMicro]}
>
{props.translate('addPayPalMePage.supportedCurrencies')}
</TextLink>
<View style={[styles.ml1]}>
<Icon
src={Expensicons.NewWindow}
height={variables.iconSizeExtraSmall}
width={variables.iconSizeExtraSmall}
/>
</View>
</View>
</PressableWithoutFeedback>
</View>
</View>
</View>
<FixedFooter>
<Button
success
onPress={setPayPalMeData}
pressOnEnter
style={[styles.mt3]}
isDisabled={_.isEmpty(payPalMeUsername.trim())}
text={props.translate('addPayPalMePage.addPayPalAccount')}
/>
</FixedFooter>
</ScreenWrapper>
);
}
AddPayPalMePage.propTypes = {...withLocalizePropTypes};
AddPayPalMePage.displayName = 'AddPayPalMePage';
export default withLocalize(AddPayPalMePage);