Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Form Provider Refactor] AddressForm and AddressPage #32276

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 18 additions & 10 deletions src/components/AddressForm.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ import useThemeStyles from '@styles/useThemeStyles';
import CONST from '@src/CONST';
import AddressSearch from './AddressSearch';
import CountrySelector from './CountrySelector';
import Form from './Form';
import FormProvider from './Form/FormProvider';
import InputWrapper from './Form/InputWrapper';
import StatePicker from './StatePicker';
import TextInput from './TextInput';

Expand Down Expand Up @@ -115,7 +116,7 @@ function AddressForm({city, country, formID, onAddressChanged, onSubmit, shouldS
}, []);

return (
<Form
<FormProvider
style={[styles.flexGrow1, styles.mh5]}
formID={formID}
validate={validator}
Expand All @@ -124,7 +125,8 @@ function AddressForm({city, country, formID, onAddressChanged, onSubmit, shouldS
enabledWhenOffline
>
<View>
<AddressSearch
<InputWrapper
InputComponent={AddressSearch}
inputID="addressLine1"
label={translate('common.addressLine', {lineNumber: 1})}
onValueChange={(data, key) => {
Expand All @@ -146,7 +148,8 @@ function AddressForm({city, country, formID, onAddressChanged, onSubmit, shouldS
/>
</View>
<View style={styles.formSpaceVertical} />
<TextInput
<InputWrapper
InputComponent={TextInput}
inputID="addressLine2"
label={translate('common.addressLine', {lineNumber: 2})}
aria-label={translate('common.addressLine', {lineNumber: 2})}
Expand All @@ -158,7 +161,8 @@ function AddressForm({city, country, formID, onAddressChanged, onSubmit, shouldS
/>
<View style={styles.formSpaceVertical} />
<View style={styles.mhn5}>
<CountrySelector
<InputWrapper
InputComponent={CountrySelector}
inputID="country"
value={country}
shouldSaveDraft={shouldSaveDraft}
Expand All @@ -167,15 +171,17 @@ function AddressForm({city, country, formID, onAddressChanged, onSubmit, shouldS
<View style={styles.formSpaceVertical} />
{isUSAForm ? (
<View style={styles.mhn5}>
<StatePicker
<InputWrapper
InputComponent={StatePicker}
inputID="state"
defaultValue={state}
onValueChange={onAddressChanged}
shouldSaveDraft={shouldSaveDraft}
/>
</View>
) : (
<TextInput
<InputWrapper
InputComponent={TextInput}
inputID="state"
label={translate('common.stateOrProvince')}
aria-label={translate('common.stateOrProvince')}
Expand All @@ -188,7 +194,8 @@ function AddressForm({city, country, formID, onAddressChanged, onSubmit, shouldS
/>
)}
<View style={styles.formSpaceVertical} />
<TextInput
<InputWrapper
InputComponent={TextInput}
inputID="city"
label={translate('common.city')}
aria-label={translate('common.city')}
Expand All @@ -200,7 +207,8 @@ function AddressForm({city, country, formID, onAddressChanged, onSubmit, shouldS
shouldSaveDraft={shouldSaveDraft}
/>
<View style={styles.formSpaceVertical} />
<TextInput
<InputWrapper
InputComponent={TextInput}
inputID="zipPostCode"
label={translate('common.zipPostCode')}
aria-label={translate('common.zipPostCode')}
Expand All @@ -212,7 +220,7 @@ function AddressForm({city, country, formID, onAddressChanged, onSubmit, shouldS
onValueChange={onAddressChanged}
shouldSaveDraft={shouldSaveDraft}
/>
</Form>
</FormProvider>
);
}

Expand Down
3 changes: 2 additions & 1 deletion src/components/CountrySelector.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import useThemeStyles from '@styles/useThemeStyles';
import ROUTES from '@src/ROUTES';
import FormHelpMessage from './FormHelpMessage';
import MenuItemWithTopDescription from './MenuItemWithTopDescription';
import refPropTypes from './refPropTypes';

const propTypes = {
/** Form error text. e.g when no country is selected */
Expand All @@ -23,7 +24,7 @@ const propTypes = {
inputID: PropTypes.string.isRequired,

/** React ref being forwarded to the MenuItemWithTopDescription */
forwardedRef: PropTypes.func,
forwardedRef: refPropTypes,
};

const defaultProps = {
Expand Down
Loading