-
Notifications
You must be signed in to change notification settings - Fork 3k
/
Copy pathAddressForm.js
122 lines (108 loc) · 4.09 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
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
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 CONST from '../../CONST';
import StatePicker from '../../components/StatePicker';
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,
/** 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),
/** The map for inputID of the inputs */
inputKeys: PropTypes.shape({
street: PropTypes.string,
city: PropTypes.string,
state: PropTypes.string,
zipCode: PropTypes.string,
}),
/** Saves a draft of the input value when used in a form */
shouldSaveDraft: PropTypes.bool,
/** Returns translated string for given locale and phrase */
translate: PropTypes.func.isRequired,
};
const defaultProps = {
values: {
street: undefined,
city: undefined,
state: undefined,
zipCode: undefined,
},
errors: {},
inputKeys: {
street: '',
city: '',
state: '',
zipCode: '',
},
shouldSaveDraft: false,
onFieldChange: () => {},
};
const AddressForm = props => (
<>
<View>
<AddressSearch
inputID={props.inputKeys.street}
shouldSaveDraft={props.shouldSaveDraft}
label={props.translate(props.streetTranslationKey)}
containerStyles={[styles.mt4]}
value={props.values.street}
onInputChange={props.onFieldChange}
errorText={props.errors.street ? props.translate('bankAccount.error.addressStreet') : ''}
hint={props.translate('common.noPO')}
renamedInputKeys={props.inputKeys}
/>
</View>
<View style={[styles.flexRow, styles.mt4]}>
<View style={[styles.flex2, styles.mr2]}>
<TextInput
inputID={props.inputKeys.city}
shouldSaveDraft={props.shouldSaveDraft}
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
inputID={props.inputKeys.state}
shouldSaveDraft={props.shouldSaveDraft}
value={props.values.state}
onInputChange={value => props.onFieldChange({state: value})}
errorText={props.errors.state ? props.translate('bankAccount.error.addressState') : ''}
/>
</View>
</View>
<TextInput
inputID={props.inputKeys.zipCode}
shouldSaveDraft={props.shouldSaveDraft}
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 AddressForm;