forked from Expensify/App
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathAddressForm.js
157 lines (139 loc) · 5.38 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
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
156
157
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,
/** Default values */
defaultValues: 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,
}),
/** 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.shape({
street: PropTypes.bool,
city: PropTypes.bool,
state: PropTypes.bool,
zipCode: 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,
},
defaultValues: {
street: undefined,
city: undefined,
state: undefined,
zipCode: undefined,
},
errors: {},
inputKeys: {
street: '',
city: '',
state: '',
zipCode: '',
},
shouldSaveDraft: false,
onFieldChange: () => {},
};
function AddressForm(props) {
return (
<>
<View>
<AddressSearch
inputID={props.inputKeys.street}
shouldSaveDraft={props.shouldSaveDraft}
label={props.translate(props.streetTranslationKey)}
containerStyles={[styles.mt4]}
value={props.values.street}
defaultValue={props.defaultValues.street}
onInputChange={props.onFieldChange}
errorText={props.errors.street ? props.translate('bankAccount.error.addressStreet') : ''}
hint={props.translate('common.noPO')}
renamedInputKeys={props.inputKeys}
maxInputLength={CONST.FORM_CHARACTER_LIMIT}
/>
</View>
<TextInput
inputID={props.inputKeys.city}
shouldSaveDraft={props.shouldSaveDraft}
label={props.translate('common.city')}
accessibilityLabel={props.translate('common.city')}
accessibilityRole={CONST.ACCESSIBILITY_ROLE.TEXT}
value={props.values.city}
defaultValue={props.defaultValues.city}
onChangeText={(value) => props.onFieldChange({city: value})}
errorText={props.errors.city ? props.translate('bankAccount.error.addressCity') : ''}
containerStyles={[styles.mt4]}
/>
<View style={[styles.mt4, styles.mhn5]}>
<StatePicker
inputID={props.inputKeys.state}
shouldSaveDraft={props.shouldSaveDraft}
value={props.values.state}
defaultValue={props.defaultValues.state || ''}
onInputChange={(value) => props.onFieldChange({state: value})}
errorText={props.errors.state ? props.translate('bankAccount.error.addressState') : ''}
/>
</View>
<TextInput
inputID={props.inputKeys.zipCode}
shouldSaveDraft={props.shouldSaveDraft}
label={props.translate('common.zip')}
accessibilityLabel={props.translate('common.zip')}
accessibilityRole={CONST.ACCESSIBILITY_ROLE.TEXT}
keyboardType={CONST.KEYBOARD_TYPE.NUMBER_PAD}
value={props.values.zipCode}
defaultValue={props.defaultValues.zipCode}
onChangeText={(value) => props.onFieldChange({zipCode: value})}
errorText={props.errors.zipCode ? props.translate('bankAccount.error.zipCode') : ''}
maxLength={CONST.BANK_ACCOUNT.MAX_LENGTH.ZIP_CODE}
hint={props.translate('common.zipCodeExampleFormat', {zipSampleFormat: CONST.COUNTRY_ZIP_REGEX_DATA.US.samples})}
containerStyles={[styles.mt2]}
/>
</>
);
}
AddressForm.propTypes = propTypes;
AddressForm.defaultProps = defaultProps;
AddressForm.displayName = 'AddressForm';
export default AddressForm;