-
Notifications
You must be signed in to change notification settings - Fork 3k
/
AddressForm.js
94 lines (82 loc) · 3.23 KB
/
AddressForm.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
import React from 'react';
import {View} from 'react-native';
import PropTypes from 'prop-types';
import TextInput from '../../components/TextInput';
import AddressSearch from '../../components/AddressSearch';
import styles from '../../styles/styles';
import withLocalize, {withLocalizePropTypes} from '../../components/withLocalize';
import CONST from '../../CONST';
import StatePicker from '../../components/StatePicker';
import Text from '../../components/Text';
const propTypes = {
/** Translate key for Street name */
streetTranslationKey: PropTypes.string.isRequired,
/** Callback fired when a field changes. Passes args as {[fieldName]: val} */
onFieldChange: PropTypes.func.isRequired,
/** Form values */
values: PropTypes.shape({
/** Address street field */
street: PropTypes.string,
/** Address city field */
city: PropTypes.string,
/** Address state field */
state: PropTypes.string,
/** Address zip code field */
zipCode: PropTypes.string,
}),
/** Any errors that can arise from form validation */
errors: PropTypes.objectOf(PropTypes.bool),
...withLocalizePropTypes,
};
const defaultProps = {
values: {
street: '',
city: '',
state: '',
zipCode: '',
},
errors: {},
};
const AddressForm = props => (
<>
<AddressSearch
label={props.translate(props.streetTranslationKey)}
containerStyles={[styles.mt4]}
value={props.values.street}
onInputChange={props.onFieldChange}
errorText={props.errors.street ? props.translate('bankAccount.error.addressStreet') : ''}
/>
<Text style={[styles.mutedTextLabel, styles.mt1]}>{props.translate('common.noPO')}</Text>
<View style={[styles.flexRow, styles.mt4]}>
<View style={[styles.flex2, styles.mr2]}>
<TextInput
label={props.translate('common.city')}
value={props.values.city}
onChangeText={value => props.onFieldChange({city: value})}
errorText={props.errors.city ? props.translate('bankAccount.error.addressCity') : ''}
/>
</View>
<View style={[styles.flex1]}>
<StatePicker
value={props.values.state}
onChange={value => props.onFieldChange({state: value})}
errorText={props.errors.state ? props.translate('bankAccount.error.addressState') : ''}
hasError={Boolean(props.errors.state)}
/>
</View>
</View>
<TextInput
label={props.translate('common.zip')}
containerStyles={[styles.mt4]}
keyboardType={CONST.KEYBOARD_TYPE.NUMBER_PAD}
value={props.values.zipCode}
onChangeText={value => props.onFieldChange({zipCode: value})}
errorText={props.errors.zipCode ? props.translate('bankAccount.error.zipCode') : ''}
maxLength={CONST.BANK_ACCOUNT.MAX_LENGTH.ZIP_CODE}
/>
</>
);
AddressForm.propTypes = propTypes;
AddressForm.defaultProps = defaultProps;
AddressForm.displayName = 'AddressForm';
export default withLocalize(AddressForm);