-
Notifications
You must be signed in to change notification settings - Fork 3.7k
Feature/20459 sub steps refactor #51231
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
Merged
madmax330
merged 55 commits into
Expensify:main
from
burczu:feature/20459-sub-steps-refactor
Oct 29, 2024
Merged
Changes from all commits
Commits
Show all changes
55 commits
Select commit
Hold shift + click to select a range
e058da3
interactive step wrapper extended to match all use cases
burczu 5ed587c
refactor: using InteractiveStepWrapper wherever applies
burczu ee229c8
missing personal details refactor: using separate form providers
burczu 21a39de
missing personal details page final refactor
burczu d0b68c9
styling fixed
burczu 6c9be43
missing personal details adjusted to use interactive step wrapper
burczu 2b3b92b
handling draft and form correctly
burczu f9f8d2c
Merge branch 'main' into feature/20459-sub-steps-refactor
burczu 26cd6ae
common full name step component created
burczu 7e1c89e
switched to use common full name step component in reimbursement account
burczu 1f849db
switched to use common full name step component in enable payments page
burczu b47e29a
switched to use common full name step component in missing personal d…
burczu b262e8e
switched to use common full name step component in beneficial owners …
burczu ac3fdbe
common full name step moved to dedicated folder
burczu 6377b87
common date of birth step component added
burczu bae4112
common date of birth step used in the enable payments page
burczu 544754c
common date of birth step component used in missing personal details …
burczu 77fe445
common date of birth step component added to reimbursement account
burczu 23e579f
common date of birth component used in beneficial owner page
burczu bba1405
common address step component created
burczu 9ecd3e1
common address step component typings fixed and improved
burczu 29e2b09
common address step component used in beneficial owner page
burczu f3aa42c
common address step component used in enable payments page
burczu d4cece1
common address step component used in personal info page
burczu 3c283d5
switched to generic form id typing for common full name comp usages
burczu 3d1e3ba
prettier fix
burczu 09494cc
switched to generic form id typing for common date of birth comp usages
burczu 7c04b0e
common single field step component created
burczu ea46862
common single field step used for personal info page
burczu 1e99139
common single step component used in the beneficial owner page
burczu c8401d4
fix: defaultName changed to displayName
burczu edbf6a2
common single field step component used wherever possible
burczu 0977917
missing input mode added
burczu 8033f10
missing should show help links prop in date of birth comp fixed
burczu d141c3e
some cleanup
burczu 6085301
common confirmation step component created
burczu a3b2b18
enable payments page confirmation step component refactored
burczu 90311ef
common confirmation component used in missing pers details page
burczu d14c626
onfido links title fixed
burczu 88446cb
common confirmation step component used in beneficial owner page
burczu 436493c
common confirmation step component used in personal info page
burczu 8e66633
prettier cleanup
burczu 460a617
Merge branch 'main' into feature/20459-sub-steps-refactor
burczu 7033339
changes in interactive step sub-header reverted
burczu 401fa5f
prettier fix
burczu 3f27c15
unused hook removed
burczu 0136b74
unused form action methods removed
burczu a623536
unnecessary eslint comment removed
burczu ad2e71f
eslint errors fixed
burczu f7fa8f3
switched from withOnyx to useOnyx wherever necessary in changed files
burczu 7b6c991
prettier fixes
burczu 9eb3121
missing max length property handled in single field step component
burczu 0245768
missing key property added
burczu d9d1060
validation issue in the address common substep fixed
burczu 4b63495
Merge branch 'main' into feature/20459-sub-steps-refactor
burczu File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,111 @@ | ||
| import React, {useCallback} from 'react'; | ||
| import {View} from 'react-native'; | ||
| import FormProvider from '@components/Form/FormProvider'; | ||
| import type {FormInputErrors, FormOnyxKeys, FormOnyxValues, FormValue} from '@components/Form/types'; | ||
| import Text from '@components/Text'; | ||
| import useLocalize from '@hooks/useLocalize'; | ||
| import type {SubStepProps} from '@hooks/useSubStep/types'; | ||
| import useThemeStyles from '@hooks/useThemeStyles'; | ||
| import * as ValidationUtils from '@libs/ValidationUtils'; | ||
| import AddressFormFields from '@pages/ReimbursementAccount/AddressFormFields'; | ||
| import HelpLinks from '@pages/ReimbursementAccount/PersonalInfo/HelpLinks'; | ||
| import type {OnyxFormValuesMapping} from '@src/ONYXKEYS'; | ||
|
|
||
| type AddressValues = { | ||
| street: string; | ||
| city: string; | ||
| state: string; | ||
| zipCode: string; | ||
| }; | ||
|
|
||
| type AddressStepProps<TFormID extends keyof OnyxFormValuesMapping> = SubStepProps & { | ||
| /** The ID of the form */ | ||
| formID: TFormID; | ||
|
|
||
| /** The title of the form */ | ||
| formTitle: string; | ||
|
|
||
| /** The disclaimer informing that PO box is not allowed */ | ||
| formPOBoxDisclaimer?: string; | ||
|
|
||
| /** The validation function to call when the form is submitted */ | ||
| customValidate?: (values: FormOnyxValues<TFormID>) => FormInputErrors<TFormID>; | ||
|
|
||
| /** A function to call when the form is submitted */ | ||
| onSubmit: (values: FormOnyxValues<TFormID>) => void; | ||
|
|
||
| /** Fields list of the form */ | ||
| stepFields: Array<FormOnyxKeys<TFormID>>; | ||
|
|
||
| /* The IDs of the input fields */ | ||
| inputFieldsIDs: AddressValues; | ||
|
|
||
| /** The default values for the form */ | ||
| defaultValues: AddressValues; | ||
|
|
||
| /** Should show help links */ | ||
| shouldShowHelpLinks?: boolean; | ||
| }; | ||
|
|
||
| function AddressStep<TFormID extends keyof OnyxFormValuesMapping>({ | ||
| formID, | ||
| formTitle, | ||
| formPOBoxDisclaimer, | ||
| customValidate, | ||
| onSubmit, | ||
| stepFields, | ||
| inputFieldsIDs, | ||
| defaultValues, | ||
| shouldShowHelpLinks, | ||
| isEditing, | ||
| }: AddressStepProps<TFormID>) { | ||
| const {translate} = useLocalize(); | ||
| const styles = useThemeStyles(); | ||
|
|
||
| const validate = useCallback( | ||
| (values: FormOnyxValues<TFormID>): FormInputErrors<TFormID> => { | ||
| const errors = ValidationUtils.getFieldRequiredErrors(values, stepFields); | ||
|
|
||
| const street = values[inputFieldsIDs.street as keyof typeof values]; | ||
| if (street && !ValidationUtils.isValidAddress(street as FormValue)) { | ||
| // @ts-expect-error type mismatch to be fixed | ||
| errors[inputFieldsIDs.street] = translate('bankAccount.error.addressStreet'); | ||
| } | ||
|
|
||
| const zipCode = values[inputFieldsIDs.zipCode as keyof typeof values]; | ||
| if (zipCode && !ValidationUtils.isValidZipCode(zipCode as string)) { | ||
| // @ts-expect-error type mismatch to be fixed | ||
| errors[inputFieldsIDs.zipCode] = translate('bankAccount.error.zipCode'); | ||
| } | ||
|
|
||
| return errors; | ||
| }, | ||
| [inputFieldsIDs.street, inputFieldsIDs.zipCode, stepFields, translate], | ||
| ); | ||
|
|
||
| return ( | ||
| <FormProvider | ||
| formID={formID} | ||
| submitButtonText={translate(isEditing ? 'common.confirm' : 'common.next')} | ||
| validate={customValidate ?? validate} | ||
| onSubmit={onSubmit} | ||
| style={[styles.mh5, styles.flexGrow1]} | ||
| > | ||
| <View> | ||
| <Text style={[styles.textHeadlineLineHeightXXL, styles.mb3]}>{formTitle}</Text> | ||
| {formPOBoxDisclaimer && <Text style={[styles.textSupporting]}>{formPOBoxDisclaimer}</Text>} | ||
| <AddressFormFields | ||
| inputKeys={inputFieldsIDs} | ||
| streetTranslationKey="common.streetAddress" | ||
| defaultValues={defaultValues} | ||
| shouldSaveDraft={!isEditing} | ||
| /> | ||
| {shouldShowHelpLinks && <HelpLinks containerStyles={[styles.mt6]} />} | ||
| </View> | ||
| </FormProvider> | ||
| ); | ||
| } | ||
|
|
||
| AddressStep.displayName = 'AddressStep'; | ||
|
|
||
| export default AddressStep; | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,118 @@ | ||
| import React from 'react'; | ||
| import {View} from 'react-native'; | ||
| import Button from '@components/Button'; | ||
| import DotIndicatorMessage from '@components/DotIndicatorMessage'; | ||
| import MenuItemWithTopDescription from '@components/MenuItemWithTopDescription'; | ||
| import SafeAreaConsumer from '@components/SafeAreaConsumer'; | ||
| import ScrollView from '@components/ScrollView'; | ||
| import Text from '@components/Text'; | ||
| import TextLink from '@components/TextLink'; | ||
| import useLocalize from '@hooks/useLocalize'; | ||
| import useNetwork from '@hooks/useNetwork'; | ||
| import type {SubStepProps} from '@hooks/useSubStep/types'; | ||
| import useThemeStyles from '@hooks/useThemeStyles'; | ||
| import CONST from '@src/CONST'; | ||
|
|
||
| type SummaryItem = { | ||
| description: string; | ||
| title: string; | ||
| shouldShowRightIcon: boolean; | ||
| onPress: () => void; | ||
| }; | ||
|
|
||
| type ConfirmationStepProps = SubStepProps & { | ||
| /** The title of the step */ | ||
| pageTitle: string; | ||
|
|
||
| /** The summary items to display */ | ||
| summaryItems: SummaryItem[]; | ||
|
|
||
| /** Whether show additional section with Onfido terms etc. */ | ||
| showOnfidoLinks: boolean; | ||
|
|
||
| /** The title of the Onfido section */ | ||
| onfidoLinksTitle?: string; | ||
|
|
||
| /** Whether the data is loading */ | ||
| isLoading?: boolean; | ||
|
|
||
| /** The error message to display */ | ||
| error?: string; | ||
| }; | ||
|
|
||
| function ConfirmationStep({pageTitle, summaryItems, showOnfidoLinks, onfidoLinksTitle, isLoading, error, onNext}: ConfirmationStepProps) { | ||
| const {translate} = useLocalize(); | ||
| const styles = useThemeStyles(); | ||
| const {isOffline} = useNetwork(); | ||
|
|
||
| return ( | ||
| <SafeAreaConsumer> | ||
| {({safeAreaPaddingBottomStyle}) => ( | ||
| <ScrollView | ||
| style={styles.pt0} | ||
| contentContainerStyle={[styles.flexGrow1, safeAreaPaddingBottomStyle]} | ||
| > | ||
| <Text style={[styles.textHeadlineLineHeightXXL, styles.ph5, styles.mb3]}>{pageTitle}</Text> | ||
| {summaryItems.map(({description, title, shouldShowRightIcon, onPress}) => ( | ||
| <MenuItemWithTopDescription | ||
| key={`${title}_${description}`} | ||
| description={description} | ||
burczu marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| title={title} | ||
| shouldShowRightIcon={shouldShowRightIcon} | ||
| onPress={onPress} | ||
| /> | ||
| ))} | ||
|
|
||
| {showOnfidoLinks && ( | ||
| <Text style={[styles.mt3, styles.ph5, styles.textMicroSupporting]}> | ||
| {onfidoLinksTitle} | ||
| <TextLink | ||
| href={CONST.ONFIDO_FACIAL_SCAN_POLICY_URL} | ||
| style={[styles.textMicro]} | ||
| > | ||
| {translate('onfidoStep.facialScan')} | ||
| </TextLink> | ||
| {', '} | ||
| <TextLink | ||
| href={CONST.ONFIDO_PRIVACY_POLICY_URL} | ||
| style={[styles.textMicro]} | ||
| > | ||
| {translate('common.privacy')} | ||
| </TextLink> | ||
| {` ${translate('common.and')} `} | ||
| <TextLink | ||
| href={CONST.ONFIDO_TERMS_OF_SERVICE_URL} | ||
| style={[styles.textMicro]} | ||
| > | ||
| {translate('common.termsOfService')} | ||
| </TextLink> | ||
| </Text> | ||
| )} | ||
|
|
||
| <View style={[styles.ph5, styles.pb5, styles.flexGrow1, styles.justifyContentEnd]}> | ||
| {error && error.length > 0 && ( | ||
| <DotIndicatorMessage | ||
| textStyles={[styles.formError]} | ||
| type="error" | ||
| messages={{error}} | ||
| /> | ||
| )} | ||
| <Button | ||
| isDisabled={isOffline} | ||
| success | ||
| large | ||
| isLoading={isLoading} | ||
| style={[styles.w100]} | ||
| onPress={onNext} | ||
| text={translate('common.confirm')} | ||
| /> | ||
| </View> | ||
| </ScrollView> | ||
| )} | ||
| </SafeAreaConsumer> | ||
| ); | ||
| } | ||
|
|
||
| ConfirmationStep.displayName = 'ConfirmationStep'; | ||
|
|
||
| export default ConfirmationStep; | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.
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.
Personal information substeps should work offline, #57385