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] AdditionalDetailsStep and AddressForm #30568

3 changes: 2 additions & 1 deletion src/components/CheckboxWithLabel.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import variables from '@styles/variables';
import Checkbox from './Checkbox';
import FormHelpMessage from './FormHelpMessage';
import PressableWithFeedback from './Pressable/PressableWithFeedback';
import refPropTypes from './refPropTypes';
import Text from './Text';

/**
Expand Down Expand Up @@ -54,7 +55,7 @@ const propTypes = {
defaultValue: PropTypes.bool,

/** React ref being forwarded to the Checkbox input */
forwardedRef: PropTypes.func,
forwardedRef: refPropTypes,

/** The ID used to uniquely identify the input in a Form */
/* eslint-disable-next-line react/no-unused-prop-types */
Expand Down
2 changes: 1 addition & 1 deletion src/components/Form/FormProvider.js
Original file line number Diff line number Diff line change
Expand Up @@ -317,7 +317,7 @@ function FormProvider({validate, formID, shouldValidateOnBlur, shouldValidateOnC
errors={errors}
enabledWhenOffline={enabledWhenOffline}
>
{children}
{_.isFunction(children) ? children({inputValues}) : children}
</FormWrapper>
</FormContext.Provider>
);
Expand Down
23 changes: 14 additions & 9 deletions src/pages/EnablePayments/AdditionalDetailsStep.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,10 @@ import React from 'react';
import {View} from 'react-native';
import {withOnyx} from 'react-native-onyx';
import _ from 'underscore';
import DatePicker from '@components/DatePicker';
import Form from '@components/Form';
import FormProvider from '@components/Form/FormProvider';
import InputWrapper from '@components/Form/InputWrapper';
import HeaderWithBackButton from '@components/HeaderWithBackButton';
import NewDatePicker from '@components/NewDatePicker';
import ScreenWrapper from '@components/ScreenWrapper';
import Text from '@components/Text';
import TextInput from '@components/TextInput';
Expand Down Expand Up @@ -177,15 +178,16 @@ function AdditionalDetailsStep({walletAdditionalDetails, translate, currentUserP
{translate('additionalDetailsStep.helpLink')}
</TextLink>
</View>
<Form
<FormProvider
formID={ONYXKEYS.WALLET_ADDITIONAL_DETAILS}
validate={validate}
onSubmit={activateWallet}
scrollContextEnabled
submitButtonText={translate('common.saveAndContinue')}
style={[styles.mh5, styles.flexGrow1]}
>
<TextInput
<InputWrapper
InputComponent={TextInput}
inputID="legalFirstName"
containerStyles={[styles.mt4]}
label={translate(fieldNameTranslationKeys.legalFirstName)}
Expand All @@ -194,7 +196,8 @@ function AdditionalDetailsStep({walletAdditionalDetails, translate, currentUserP
defaultValue={PersonalDetails.extractFirstAndLastNameFromAvailableDetails(currentUserPersonalDetails).firstName}
shouldSaveDraft
/>
<TextInput
<InputWrapper
InputComponent={TextInput}
inputID="legalLastName"
containerStyles={[styles.mt4]}
label={translate(fieldNameTranslationKeys.legalLastName)}
Expand All @@ -214,7 +217,8 @@ function AdditionalDetailsStep({walletAdditionalDetails, translate, currentUserP
streetTranslationKey={fieldNameTranslationKeys.addressStreet}
shouldSaveDraft
/>
<TextInput
<InputWrapper
InputComponent={TextInput}
inputID="phoneNumber"
containerStyles={[styles.mt4]}
inputMode={CONST.INPUT_MODE.TEL}
Expand All @@ -225,7 +229,7 @@ function AdditionalDetailsStep({walletAdditionalDetails, translate, currentUserP
placeholder={translate('common.phoneNumberPlaceholder')}
shouldSaveDraft
/>
<DatePicker
<NewDatePicker
inputID="dob"
containerStyles={[styles.mt4]}
label={translate(fieldNameTranslationKeys.dob)}
Expand All @@ -234,7 +238,8 @@ function AdditionalDetailsStep({walletAdditionalDetails, translate, currentUserP
maxDate={maxDate}
shouldSaveDraft
/>
<TextInput
<InputWrapper
InputComponent={TextInput}
inputID="ssn"
containerStyles={[styles.mt4]}
label={translate(fieldNameTranslationKeys[shouldAskForFullSSN ? 'ssnFull9' : 'ssn'])}
Expand All @@ -243,7 +248,7 @@ function AdditionalDetailsStep({walletAdditionalDetails, translate, currentUserP
maxLength={shouldAskForFullSSN ? 9 : 4}
inputMode={CONST.INPUT_MODE.NUMERIC}
/>
</Form>
</FormProvider>
</View>
</>
);
Expand Down
19 changes: 12 additions & 7 deletions src/pages/ReimbursementAccount/ACHContractStep.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@ import React, {useState} from 'react';
import {View} from 'react-native';
import _ from 'underscore';
import CheckboxWithLabel from '@components/CheckboxWithLabel';
import Form from '@components/Form';
import FormProvider from '@components/Form/FormProvider';
import InputWrapper from '@components/Form/InputWrapper';
import HeaderWithBackButton from '@components/HeaderWithBackButton';
import ScreenWrapper from '@components/ScreenWrapper';
import Text from '@components/Text';
Expand Down Expand Up @@ -156,7 +157,7 @@ function ACHContractStep(props) {
shouldShowGetAssistanceButton
guidesCallTaskID={CONST.GUIDES_CALL_TASK_IDS.WORKSPACE_BANK_ACCOUNT}
/>
<Form
<FormProvider
formID={ONYXKEYS.REIMBURSEMENT_ACCOUNT}
validate={validate}
onSubmit={submit}
Expand All @@ -168,7 +169,8 @@ function ACHContractStep(props) {
<Text style={[styles.mb5]}>
<Text>{props.translate('beneficialOwnersStep.checkAllThatApply')}</Text>
</Text>
<CheckboxWithLabel
<InputWrapper
InputComponent={CheckboxWithLabel}
accessibilityLabel={props.translate('beneficialOwnersStep.iOwnMoreThan25Percent')}
inputID="ownsMoreThan25Percent"
style={[styles.mb2]}
Expand All @@ -189,7 +191,8 @@ function ACHContractStep(props) {
defaultValue={props.getDefaultStateForField('ownsMoreThan25Percent', false)}
shouldSaveDraft
/>
<CheckboxWithLabel
<InputWrapper
InputComponent={CheckboxWithLabel}
accessibilityLabel={props.translate('beneficialOwnersStep.someoneOwnsMoreThan25Percent')}
inputID="hasOtherBeneficialOwners"
style={[styles.mb2]}
Expand Down Expand Up @@ -255,7 +258,8 @@ function ACHContractStep(props) {
</View>
)}
<Text style={[styles.mv5]}>{props.translate('beneficialOwnersStep.agreement')}</Text>
<CheckboxWithLabel
<InputWrapper
InputComponent={CheckboxWithLabel}
accessibilityLabel={`${props.translate('common.iAcceptThe')} ${props.translate('beneficialOwnersStep.termsAndConditions')}`}
inputID="acceptTermsAndConditions"
style={[styles.mt4]}
Expand All @@ -268,7 +272,8 @@ function ACHContractStep(props) {
defaultValue={props.getDefaultStateForField('acceptTermsAndConditions', false)}
shouldSaveDraft
/>
<CheckboxWithLabel
<InputWrapper
InputComponent={CheckboxWithLabel}
accessibilityLabel={props.translate('beneficialOwnersStep.certifyTrueAndAccurate')}
inputID="certifyTrueInformation"
style={[styles.mt4]}
Expand All @@ -278,7 +283,7 @@ function ACHContractStep(props) {
/>
</>
)}
</Form>
</FormProvider>
</ScreenWrapper>
);
}
Expand Down
13 changes: 9 additions & 4 deletions src/pages/ReimbursementAccount/AddressForm.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import PropTypes from 'prop-types';
import React from 'react';
import {View} from 'react-native';
import AddressSearch from '@components/AddressSearch';
import InputWrapper from '@components/Form/InputWrapper';
import StatePicker from '@components/StatePicker';
import TextInput from '@components/TextInput';
import styles from '@styles/styles';
Expand Down Expand Up @@ -95,7 +96,8 @@ function AddressForm(props) {
return (
<>
<View>
<AddressSearch
<InputWrapper
InputComponent={AddressSearch}
inputID={props.inputKeys.street}
shouldSaveDraft={props.shouldSaveDraft}
label={props.translate(props.streetTranslationKey)}
Expand All @@ -110,7 +112,8 @@ function AddressForm(props) {
isLimitedToUSA
/>
</View>
<TextInput
<InputWrapper
InputComponent={TextInput}
inputID={props.inputKeys.city}
shouldSaveDraft={props.shouldSaveDraft}
label={props.translate('common.city')}
Expand All @@ -124,7 +127,8 @@ function AddressForm(props) {
/>

<View style={[styles.mt4, styles.mhn5]}>
<StatePicker
<InputWrapper
InputComponent={StatePicker}
inputID={props.inputKeys.state}
shouldSaveDraft={props.shouldSaveDraft}
value={props.values.state}
Expand All @@ -133,7 +137,8 @@ function AddressForm(props) {
errorText={props.errors.state ? props.translate('bankAccount.error.addressState') : ''}
/>
</View>
<TextInput
<InputWrapper
InputComponent={TextInput}
inputID={props.inputKeys.zipCode}
shouldSaveDraft={props.shouldSaveDraft}
label={props.translate('common.zip')}
Expand Down
32 changes: 20 additions & 12 deletions src/pages/ReimbursementAccount/CompanyStep.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,10 @@ import {View} from 'react-native';
import {withOnyx} from 'react-native-onyx';
import _ from 'underscore';
import CheckboxWithLabel from '@components/CheckboxWithLabel';
import DatePicker from '@components/DatePicker';
import Form from '@components/Form';
import FormProvider from '@components/Form/FormProvider';
import InputWrapper from '@components/Form/InputWrapper';
import HeaderWithBackButton from '@components/HeaderWithBackButton';
import NewDatePicker from '@components/NewDatePicker';
import Picker from '@components/Picker';
import ScreenWrapper from '@components/ScreenWrapper';
import StatePicker from '@components/StatePicker';
Expand Down Expand Up @@ -151,7 +152,7 @@ function CompanyStep({reimbursementAccount, reimbursementAccountDraft, getDefaul
guidesCallTaskID={CONST.GUIDES_CALL_TASK_IDS.WORKSPACE_BANK_ACCOUNT}
onBackButtonPress={onBackButtonPress}
/>
<Form
<FormProvider
formID={ONYXKEYS.REIMBURSEMENT_ACCOUNT}
validate={validate}
onSubmit={submit}
Expand All @@ -160,7 +161,8 @@ function CompanyStep({reimbursementAccount, reimbursementAccountDraft, getDefaul
style={[styles.mh5, styles.flexGrow1]}
>
<Text>{translate('companyStep.subtitle')}</Text>
<TextInput
<InputWrapper
InputComponent={TextInput}
label={translate('companyStep.legalBusinessName')}
accessibilityLabel={translate('companyStep.legalBusinessName')}
role={CONST.ACCESSIBILITY_ROLE.TEXT}
Expand Down Expand Up @@ -188,7 +190,8 @@ function CompanyStep({reimbursementAccount, reimbursementAccountDraft, getDefaul
shouldSaveDraft
streetTranslationKey="common.companyAddress"
/>
<TextInput
<InputWrapper
InputComponent={TextInput}
inputID="companyPhone"
label={translate('common.phoneNumber')}
accessibilityLabel={translate('common.phoneNumber')}
Expand All @@ -199,7 +202,8 @@ function CompanyStep({reimbursementAccount, reimbursementAccountDraft, getDefaul
defaultValue={getDefaultStateForField('companyPhone')}
shouldSaveDraft
/>
<TextInput
<InputWrapper
InputComponent={TextInput}
inputID="website"
label={translate('companyStep.companyWebsite')}
accessibilityLabel={translate('companyStep.companyWebsite')}
Expand All @@ -210,7 +214,8 @@ function CompanyStep({reimbursementAccount, reimbursementAccountDraft, getDefaul
hint={translate('common.websiteExample')}
inputMode={CONST.INPUT_MODE.URL}
/>
<TextInput
<InputWrapper
InputComponent={TextInput}
inputID="companyTaxID"
label={translate('companyStep.taxIDNumber')}
accessibilityLabel={translate('companyStep.taxIDNumber')}
Expand All @@ -224,7 +229,8 @@ function CompanyStep({reimbursementAccount, reimbursementAccountDraft, getDefaul
shouldUseDefaultValue={shouldDisableCompanyTaxID}
/>
<View style={styles.mt4}>
<Picker
<InputWrapper
InputComponent={Picker}
inputID="incorporationType"
label={translate('companyStep.companyType')}
items={_.map(_.keys(CONST.INCORPORATION_TYPES), (key) => ({value: key, label: translate(`companyStep.incorporationTypes.${key}`)}))}
Expand All @@ -234,7 +240,7 @@ function CompanyStep({reimbursementAccount, reimbursementAccountDraft, getDefaul
/>
</View>
<View style={styles.mt4}>
<DatePicker
<NewDatePicker
inputID="incorporationDate"
label={translate('companyStep.incorporationDate')}
placeholder={translate('companyStep.incorporationDatePlaceholder')}
Expand All @@ -243,14 +249,16 @@ function CompanyStep({reimbursementAccount, reimbursementAccountDraft, getDefaul
/>
</View>
<View style={[styles.mt4, styles.mhn5]}>
<StatePicker
<InputWrapper
InputComponent={StatePicker}
inputID="incorporationState"
label={translate('companyStep.incorporationState')}
defaultValue={getDefaultStateForField('incorporationState')}
shouldSaveDraft
/>
</View>
<CheckboxWithLabel
<InputWrapper
InputComponent={CheckboxWithLabel}
accessibilityLabel={`${translate('companyStep.confirmCompanyIsNot')} ${translate('companyStep.listOfRestrictedBusinesses')}`}
inputID="hasNoConnectionToCannabis"
defaultValue={getDefaultStateForField('hasNoConnectionToCannabis', false)}
Expand All @@ -268,7 +276,7 @@ function CompanyStep({reimbursementAccount, reimbursementAccountDraft, getDefaul
style={[styles.mt4]}
shouldSaveDraft
/>
</Form>
</FormProvider>
</ScreenWrapper>
);
}
Expand Down
14 changes: 9 additions & 5 deletions src/pages/ReimbursementAccount/IdentityForm.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@ import PropTypes from 'prop-types';
import React from 'react';
import {View} from 'react-native';
import _ from 'underscore';
import DatePicker from '@components/DatePicker';
import InputWrapper from '@components/Form/InputWrapper';
import NewDatePicker from '@components/NewDatePicker';
import TextInput from '@components/TextInput';
import styles from '@styles/styles';
import CONST from '@src/CONST';
Expand Down Expand Up @@ -141,7 +142,8 @@ function IdentityForm(props) {
<View style={props.style}>
<View style={[styles.flexRow]}>
<View style={[styles.flex2, styles.mr2]}>
<TextInput
<InputWrapper
InputComponent={TextInput}
inputID={props.inputKeys.firstName}
shouldSaveDraft={props.shouldSaveDraft}
label={`${props.translate('common.firstName')}`}
Expand All @@ -154,7 +156,8 @@ function IdentityForm(props) {
/>
</View>
<View style={[styles.flex2]}>
<TextInput
<InputWrapper
InputComponent={TextInput}
inputID={props.inputKeys.lastName}
shouldSaveDraft={props.shouldSaveDraft}
label={`${props.translate('common.lastName')}`}
Expand All @@ -167,7 +170,7 @@ function IdentityForm(props) {
/>
</View>
</View>
<DatePicker
<NewDatePicker
inputID={props.inputKeys.dob}
shouldSaveDraft={props.shouldSaveDraft}
label={`${props.translate('common.dob')}`}
Expand All @@ -179,7 +182,8 @@ function IdentityForm(props) {
minDate={minDate}
maxDate={maxDate}
/>
<TextInput
<InputWrapper
InputComponent={TextInput}
inputID={props.inputKeys.ssnLast4}
shouldSaveDraft={props.shouldSaveDraft}
label={`${props.translate('common.ssnLast4')}`}
Expand Down
Loading
Loading