-
Notifications
You must be signed in to change notification settings - Fork 2.9k
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
feat: Step 4 UI #52384
feat: Step 4 UI #52384
Changes from 9 commits
471adcf
3d17ff4
1b3d6d5
d402ec6
0254d5a
da53fea
1f0eb91
dcf7808
79df2d6
92264c5
56bb3b9
8a55c93
5996997
fa9a839
3f76c3a
ef61fd2
f218f1e
c5f7843
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
import React, {useMemo, useState} from 'react'; | ||
import FormProvider from '@components/Form/FormProvider'; | ||
import type {Choice} from '@components/RadioButtons'; | ||
import RadioButtons from '@components/RadioButtons'; | ||
import Text from '@components/Text'; | ||
import useLocalize from '@hooks/useLocalize'; | ||
import useThemeStyles from '@hooks/useThemeStyles'; | ||
import ONYXKEYS from '@src/ONYXKEYS'; | ||
|
||
type BeneficialOwnerCheckProps = { | ||
/** The title of the question */ | ||
title: string; | ||
|
||
/** The default value of the radio button */ | ||
defaultValue: boolean; | ||
|
||
/** Callback when the value is selected */ | ||
onSelectedValue: (value: boolean) => void; | ||
}; | ||
|
||
function BeneficialOwnerCheck({title, onSelectedValue, defaultValue}: BeneficialOwnerCheckProps) { | ||
const {translate} = useLocalize(); | ||
const styles = useThemeStyles(); | ||
const [value, setValue] = useState(defaultValue); | ||
|
||
const handleSubmit = () => { | ||
onSelectedValue(value); | ||
}; | ||
const handleSelectValue = (newValue: string) => setValue(newValue === 'true'); | ||
const options = useMemo<Choice[]>( | ||
() => [ | ||
{ | ||
label: translate('common.yes'), | ||
value: 'true', | ||
}, | ||
{ | ||
label: translate('common.no'), | ||
value: 'false', | ||
}, | ||
], | ||
[translate], | ||
); | ||
|
||
return ( | ||
<FormProvider | ||
formID={ONYXKEYS.FORMS.REIMBURSEMENT_ACCOUNT_FORM} | ||
submitButtonText={translate('common.confirm')} | ||
onSubmit={handleSubmit} | ||
style={[styles.mh5, styles.flexGrow1]} | ||
> | ||
<Text style={[styles.textHeadlineLineHeightXXL]}>{title}</Text> | ||
<Text style={[styles.pv3, styles.textSupporting]}>{translate('ownershipInfoStep.regulationsRequire')}</Text> | ||
<RadioButtons | ||
items={options} | ||
onPress={handleSelectValue} | ||
defaultCheckedValue={defaultValue.toString()} | ||
radioButtonStyle={[styles.mb6]} | ||
/> | ||
</FormProvider> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We have a common component called There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I've replaced my component with this step and refactored other places as well - I believe that extra wrapper was unecessary. Ive used There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thanks, let me test |
||
); | ||
} | ||
|
||
BeneficialOwnerCheck.displayName = 'BeneficialOwnerCheck'; | ||
|
||
export default BeneficialOwnerCheck; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
import React, {useMemo, useState} from 'react'; | ||
import {useOnyx} from 'react-native-onyx'; | ||
import AddressStep from '@components/SubStepForms/AddressStep'; | ||
import useLocalize from '@hooks/useLocalize'; | ||
import useReimbursementAccountStepFormSubmit from '@hooks/useReimbursementAccountStepFormSubmit'; | ||
import type {SubStepProps} from '@hooks/useSubStep/types'; | ||
import CONST from '@src/CONST'; | ||
import type {Country} from '@src/CONST'; | ||
import ONYXKEYS from '@src/ONYXKEYS'; | ||
|
||
type NameProps = SubStepProps & {isUserEnteringHisOwnData: boolean; ownerBeingModifiedID: string}; | ||
|
||
const {STREET, CITY, STATE, ZIP_CODE, COUNTRY, PREFIX} = CONST.NON_USD_BANK_ACCOUNT.BENEFICIAL_OWNER_INFO_STEP.BENEFICIAL_OWNER_DATA; | ||
|
||
function Address({onNext, isEditing, onMove, isUserEnteringHisOwnData, ownerBeingModifiedID}: NameProps) { | ||
const {translate} = useLocalize(); | ||
const [reimbursementAccountDraft] = useOnyx(ONYXKEYS.FORMS.REIMBURSEMENT_ACCOUNT_FORM_DRAFT); | ||
|
||
const countryInputKey: `beneficialOwner_${string}_${string}` = `${PREFIX}_${ownerBeingModifiedID}_${COUNTRY}`; | ||
const inputKeys = { | ||
street: `${PREFIX}_${ownerBeingModifiedID}_${STREET}`, | ||
city: `${PREFIX}_${ownerBeingModifiedID}_${CITY}`, | ||
state: `${PREFIX}_${ownerBeingModifiedID}_${STATE}`, | ||
zipCode: `${PREFIX}_${ownerBeingModifiedID}_${ZIP_CODE}`, | ||
country: countryInputKey, | ||
} as const; | ||
|
||
const defaultValues = { | ||
street: reimbursementAccountDraft?.[inputKeys.street] ?? '', | ||
city: reimbursementAccountDraft?.[inputKeys.city] ?? '', | ||
state: reimbursementAccountDraft?.[inputKeys.state] ?? '', | ||
zipCode: reimbursementAccountDraft?.[inputKeys.zipCode] ?? '', | ||
country: (reimbursementAccountDraft?.[inputKeys.country] ?? '') as Country | '', | ||
}; | ||
|
||
const formTitle = translate(isUserEnteringHisOwnData ? 'ownershipInfoStep.whatsYourAddress' : 'ownershipInfoStep.whatsTheOwnersAddress'); | ||
|
||
// Has to be stored in state and updated on country change due to the fact that we can't relay on onyxValues when user is editing the form (draft values are not being saved in that case) | ||
const [shouldDisplayStateSelector, setShouldDisplayStateSelector] = useState<boolean>( | ||
defaultValues.country === CONST.COUNTRY.US || defaultValues.country === CONST.COUNTRY.CA || defaultValues.country === '', | ||
); | ||
|
||
const stepFieldsWithState = useMemo( | ||
() => [inputKeys.street, inputKeys.city, inputKeys.state, inputKeys.zipCode, countryInputKey], | ||
[countryInputKey, inputKeys.city, inputKeys.state, inputKeys.street, inputKeys.zipCode], | ||
); | ||
const stepFieldsWithoutState = useMemo( | ||
() => [inputKeys.street, inputKeys.city, inputKeys.zipCode, countryInputKey], | ||
[countryInputKey, inputKeys.city, inputKeys.street, inputKeys.zipCode], | ||
); | ||
|
||
const stepFields = shouldDisplayStateSelector ? stepFieldsWithState : stepFieldsWithoutState; | ||
|
||
const handleCountryChange = (country: unknown) => { | ||
if (typeof country !== 'string' || country === '') { | ||
return; | ||
} | ||
setShouldDisplayStateSelector(country === CONST.COUNTRY.US || country === CONST.COUNTRY.CA); | ||
}; | ||
|
||
const handleSubmit = useReimbursementAccountStepFormSubmit({ | ||
fieldIds: stepFields, | ||
onNext, | ||
shouldSaveDraft: isEditing, | ||
}); | ||
|
||
return ( | ||
<AddressStep<typeof ONYXKEYS.FORMS.REIMBURSEMENT_ACCOUNT_FORM> | ||
isEditing={isEditing} | ||
onNext={onNext} | ||
onMove={onMove} | ||
formID={ONYXKEYS.FORMS.REIMBURSEMENT_ACCOUNT_FORM} | ||
formTitle={formTitle} | ||
formPOBoxDisclaimer={translate('common.noPO')} | ||
onSubmit={handleSubmit} | ||
stepFields={stepFields} | ||
inputFieldsIDs={inputKeys} | ||
defaultValues={defaultValues} | ||
onCountryChange={handleCountryChange} | ||
shouldDisplayStateSelector={shouldDisplayStateSelector} | ||
shouldDisplayCountrySelector | ||
/> | ||
); | ||
} | ||
|
||
Address.displayName = 'Address'; | ||
|
||
export default Address; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
https://expensify.slack.com/archives/C01GTK53T8Q/p1731423389064609
Getting a confirmation for the translation