Skip to content
Merged
Show file tree
Hide file tree
Changes from 8 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
16 changes: 8 additions & 8 deletions src/CONST/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8080,14 +8080,14 @@ const CONST = {
] as string[],
SPECIAL_LIST_REGION_KEYS: ['bankRegion', 'accountHolderRegion'] as string[],
SPECIAL_LIST_ADDRESS_KEYS: ['bankAddressLine1', 'accountHolderAddress1'] as string[],
STEPS_NAME: {
COUNTRY_SELECTOR: 'CountrySelector',
BANK_ACCOUNT_DETAILS: 'BankAccountDetails',
ACCOUNT_TYPE: 'AccountType',
BANK_INFORMATION: 'BankInformation',
ACCOUNT_HOLDER_INFORMATION: 'AccountHolderInformation',
CONFIRMATION: 'Confirmation',
SUCCESS: 'Success',
PAGE_NAME: {
COUNTRY: 'country',
ACCOUNT_DETAILS: 'account-details',
ACCOUNT_TYPE: 'account-type',
BANK_INFORMATION: 'bank-information',
ACCOUNT_HOLDER_DETAILS: 'account-holder-details',
CONFIRM: 'confirm',
SUCCESS: 'success',
},
INDEXES: {
MAPPING: {
Expand Down
13 changes: 9 additions & 4 deletions src/ROUTES.ts
Original file line number Diff line number Diff line change
Expand Up @@ -422,10 +422,15 @@ const ROUTES = {
},
SETTINGS_ADD_DEBIT_CARD: 'settings/wallet/add-debit-card',
SETTINGS_ADD_BANK_ACCOUNT: {
route: 'settings/wallet/add-bank-account',

// eslint-disable-next-line no-restricted-syntax -- Legacy route generation
getRoute: (backTo?: string) => getUrlWithBackToParam('settings/wallet/add-bank-account', backTo),
route: 'settings/wallet/add-bank-account/:subPage?/:action?',
getRoute: (backTo?: string, subPage?: string, action?: 'edit') => {
if (!subPage) {
// eslint-disable-next-line no-restricted-syntax -- Legacy route generation
return getUrlWithBackToParam('settings/wallet/add-bank-account', backTo);
}
// eslint-disable-next-line no-restricted-syntax -- Legacy route generation
return getUrlWithBackToParam(`settings/wallet/add-bank-account/${subPage}${action ? `/${action}` : ''}`, backTo);
},
},
SETTINGS_ADD_BANK_ACCOUNT_VERIFY_ACCOUNT: {
route: `settings/wallet/add-bank-account/${VERIFY_ACCOUNT}`,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -434,7 +434,7 @@ const SettingsModalStackNavigator = createModalStackNavigator<SettingsNavigatorP
[SCREENS.SETTINGS.ADD_BANK_ACCOUNT]: () => require<ReactComponentModule>('../../../../pages/settings/Wallet/InternationalDepositAccount').default,
[SCREENS.SETTINGS.ADD_US_BANK_ACCOUNT]: () => require<ReactComponentModule>('../../../../pages/AddPersonalBankAccountPage').default,
[SCREENS.SETTINGS.ADD_US_BANK_ACCOUNT_ENTRY_POINT]: () =>
require<ReactComponentModule>('../../../../pages/settings/Wallet/InternationalDepositAccount/substeps/AccountFlowEntryPoint').default,
require<ReactComponentModule>('../../../../pages/settings/Wallet/InternationalDepositAccount/subPages/AccountFlowEntryPoint').default,
[SCREENS.SETTINGS.ADD_BANK_ACCOUNT_SELECT_COUNTRY_VERIFY_ACCOUNT]: () =>
require<ReactComponentModule>('../../../../pages/settings/Wallet/InternationalDepositAccount/CountrySelectionVerifyAccountPage').default,
[SCREENS.SETTINGS.BANK_ACCOUNT_PURPOSE]: () => require<ReactComponentModule>('../../../../pages/settings/Wallet/BankAccountPurposePage').default,
Expand Down
2 changes: 2 additions & 0 deletions src/libs/Navigation/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -220,6 +220,8 @@ type SettingsNavigatorParamList = {
[SCREENS.SETTINGS.ADD_BANK_ACCOUNT]: {
// eslint-disable-next-line no-restricted-syntax -- `backTo` usages in this file are legacy. Do not add new `backTo` params to screens. See contributingGuides/NAVIGATION.md
backTo?: Routes;
subPage?: string;
action?: 'edit';
};
[SCREENS.SETTINGS.ADD_BANK_ACCOUNT_VERIFY_ACCOUNT]: {
// TODO will be removed once dynamic routes are implemented https://github.com/Expensify/App/issues/73825
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import {useRoute} from '@react-navigation/native';
import React, {useCallback, useMemo} from 'react';
import type {OnyxEntry} from 'react-native-onyx';
import FullScreenLoadingIndicator from '@components/FullscreenLoadingIndicator';
Expand All @@ -6,26 +7,29 @@ import ScreenWrapper from '@components/ScreenWrapper';
import useAndroidBackButtonHandler from '@hooks/useAndroidBackButtonHandler';
import useLocalize from '@hooks/useLocalize';
import useRootNavigationState from '@hooks/useRootNavigationState';
import useSubStep from '@hooks/useSubStep';
import useSubPage from '@hooks/useSubPage';
import {clearDraftValues} from '@libs/actions/FormActions';
import {isFullScreenName} from '@libs/Navigation/helpers/isNavigatorName';
import Navigation from '@libs/Navigation/Navigation';
import type {PlatformStackRouteProp} from '@libs/Navigation/PlatformStackNavigation/types';
import type {SettingsNavigatorParamList} from '@libs/Navigation/types';
import CONST from '@src/CONST';
import NAVIGATORS from '@src/NAVIGATORS';
import ONYXKEYS from '@src/ONYXKEYS';
import type {Route} from '@src/ROUTES';
import ROUTES from '@src/ROUTES';
import type SCREENS from '@src/SCREENS';
import type {InternationalBankAccountForm} from '@src/types/form';
import type {BankAccountList, CorpayFields, PrivatePersonalDetails} from '@src/types/onyx';
import {isEmptyObject} from '@src/types/utils/EmptyObject';
import AccountHolderInformation from './substeps/AccountHolderInformation';
import AccountType from './substeps/AccountType';
import BankAccountDetails from './substeps/BankAccountDetails';
import BankInformation from './substeps/BankInformation';
import Confirmation from './substeps/Confirmation';
import CountrySelection from './substeps/CountrySelection';
import Success from './substeps/Success';
import type CustomSubStepProps from './types';
import AccountHolderInformation from './subPages/AccountHolderInformation';
import AccountType from './subPages/AccountType';
import BankAccountDetails from './subPages/BankAccountDetails';
import BankInformation from './subPages/BankInformation';
import Confirmation from './subPages/Confirmation';
import CountrySelection from './subPages/CountrySelection';
import Success from './subPages/Success';
import type CustomSubPageProps from './types';
import {getFieldsMap, getInitialPersonalDetailsValues, getInitialSubstep, getSubstepValues, testValidation} from './utils';

type InternationalDepositAccountContentProps = {
Expand All @@ -38,15 +42,23 @@ type InternationalDepositAccountContentProps = {
backTo?: Route;
};

const formSteps = [CountrySelection, BankAccountDetails, AccountType, BankInformation, AccountHolderInformation, Confirmation, Success];

function getSkippedSteps(skipAccountTypeStep: boolean, skipAccountHolderInformationStep: boolean) {
const pages = [
{pageName: CONST.CORPAY_FIELDS.PAGE_NAME.COUNTRY, component: CountrySelection},
{pageName: CONST.CORPAY_FIELDS.PAGE_NAME.ACCOUNT_DETAILS, component: BankAccountDetails},
{pageName: CONST.CORPAY_FIELDS.PAGE_NAME.ACCOUNT_TYPE, component: AccountType},
{pageName: CONST.CORPAY_FIELDS.PAGE_NAME.BANK_INFORMATION, component: BankInformation},
{pageName: CONST.CORPAY_FIELDS.PAGE_NAME.ACCOUNT_HOLDER_DETAILS, component: AccountHolderInformation},
{pageName: CONST.CORPAY_FIELDS.PAGE_NAME.CONFIRM, component: Confirmation},
{pageName: CONST.CORPAY_FIELDS.PAGE_NAME.SUCCESS, component: Success},
];

function getSkippedPages(skipAccountTypeStep: boolean, skipAccountHolderInformationStep: boolean) {
const skippedSteps = [];
if (skipAccountTypeStep) {
skippedSteps.push(CONST.CORPAY_FIELDS.INDEXES.MAPPING.ACCOUNT_TYPE);
skippedSteps.push(CONST.CORPAY_FIELDS.PAGE_NAME.ACCOUNT_TYPE);
}
if (skipAccountHolderInformationStep) {
skippedSteps.push(CONST.CORPAY_FIELDS.INDEXES.MAPPING.ACCOUNT_HOLDER_INFORMATION);
skippedSteps.push(CONST.CORPAY_FIELDS.PAGE_NAME.ACCOUNT_HOLDER_DETAILS);
}
return skippedSteps;
}
Expand All @@ -73,13 +85,14 @@ function InternationalDepositAccountContent({

const startFrom = useMemo(() => getInitialSubstep(values, fieldsMap), [fieldsMap, values]);

const skipAccountTypeStep = isEmptyObject(fieldsMap[CONST.CORPAY_FIELDS.STEPS_NAME.ACCOUNT_TYPE]);
const skipAccountTypeStep = isEmptyObject(fieldsMap[CONST.CORPAY_FIELDS.PAGE_NAME.ACCOUNT_TYPE]);

const skipAccountHolderInformationStep = testValidation(initialAccountHolderDetailsValues, fieldsMap[CONST.CORPAY_FIELDS.STEPS_NAME.ACCOUNT_HOLDER_INFORMATION]);
const skipAccountHolderInformationStep = testValidation(initialAccountHolderDetailsValues, fieldsMap[CONST.CORPAY_FIELDS.PAGE_NAME.ACCOUNT_HOLDER_DETAILS]);

const skippedSteps = getSkippedSteps(skipAccountTypeStep, skipAccountHolderInformationStep);
const skippedPages = getSkippedPages(skipAccountTypeStep, skipAccountHolderInformationStep);

const topmostFullScreenRoute = useRootNavigationState((state) => state?.routes.findLast((route) => isFullScreenName(route.name)));
const route = useRoute<PlatformStackRouteProp<SettingsNavigatorParamList, typeof SCREENS.SETTINGS.ADD_BANK_ACCOUNT>>();
const topmostFullScreenRoute = useRootNavigationState((state) => state?.routes.findLast((r) => isFullScreenName(r.name)));

const goBack = useCallback(
(shouldIgnoreBackToParam = false) => {
Expand Down Expand Up @@ -107,42 +120,50 @@ function InternationalDepositAccountContent({
goBack(backTo?.includes(ROUTES.SETTINGS_BANK_ACCOUNT_PURPOSE));
}, [goBack, backTo]);

const {componentToRender: SubStep, isEditing, nextScreen, prevScreen, screenIndex, moveTo, resetScreenIndex} =
// eslint-disable-next-line @typescript-eslint/no-deprecated
useSubStep<CustomSubStepProps>({bodyContent: formSteps, startFrom, onFinished: handleFinishStep, skipSteps: skippedSteps});
const {CurrentPage, isEditing, nextPage, prevPage, pageIndex, moveTo, isRedirecting} = useSubPage<CustomSubPageProps>({
pages,
startFrom,
onFinished: handleFinishStep,
skipPages: skippedPages,
buildRoute: (pageName, action) => ROUTES.SETTINGS_ADD_BANK_ACCOUNT.getRoute(route.params?.backTo, pageName, action),
});

const goBackToConfirmStep = () => {
Navigation.goBack(ROUTES.SETTINGS_ADD_BANK_ACCOUNT.getRoute(route.params?.backTo, CONST.CORPAY_FIELDS.PAGE_NAME.CONFIRM, undefined));
};

const handleBackButtonPress = () => {
if (isEditing) {
resetScreenIndex(CONST.CORPAY_FIELDS.INDEXES.MAPPING.CONFIRMATION);
goBackToConfirmStep();
return true;
}

// Clicking back on the first screen should dismiss the modal
if (screenIndex === CONST.CORPAY_FIELDS.INDEXES.MAPPING.COUNTRY_SELECTOR) {
if (pageIndex === CONST.CORPAY_FIELDS.INDEXES.MAPPING.COUNTRY_SELECTOR) {
clearDraftValues(ONYXKEYS.FORMS.INTERNATIONAL_BANK_ACCOUNT_FORM);
goBack();
return true;
}

// Clicking back on the success screen should dismiss the modal
if (screenIndex === CONST.CORPAY_FIELDS.INDEXES.MAPPING.SUCCESS) {
if (pageIndex === CONST.CORPAY_FIELDS.INDEXES.MAPPING.SUCCESS) {
clearDraftValues(ONYXKEYS.FORMS.INTERNATIONAL_BANK_ACCOUNT_FORM);
goBack();
return true;
}
prevScreen();
prevPage();
return true;
};

useAndroidBackButtonHandler(handleBackButtonPress);

const handleNextScreen = useCallback(() => {
if (isEditing) {
resetScreenIndex(CONST.CORPAY_FIELDS.INDEXES.MAPPING.CONFIRMATION);
goBackToConfirmStep();
return;
}
nextScreen();
}, [resetScreenIndex, isEditing, nextScreen]);
nextPage();
}, [isEditing, goBackToConfirmStep, nextPage]);

if (isAccountLoading) {
return <FullScreenLoadingIndicator />;
Expand All @@ -152,21 +173,25 @@ function InternationalDepositAccountContent({
<ScreenWrapper
shouldEnableMaxHeight
testID="InternationalDepositAccountContent"
shouldShowOfflineIndicatorInWideScreen={screenIndex === CONST.CORPAY_FIELDS.INDEXES.MAPPING.CONFIRMATION}
shouldShowOfflineIndicatorInWideScreen={pageIndex === CONST.CORPAY_FIELDS.INDEXES.MAPPING.CONFIRMATION}
>
<HeaderWithBackButton
title={translate('bankAccount.addBankAccount')}
onBackButtonPress={handleBackButtonPress}
/>
<SubStep
isEditing={isEditing}
onNext={handleNextScreen}
onMove={moveTo}
screenIndex={screenIndex}
resetScreenIndex={resetScreenIndex}
formValues={values}
fieldsMap={fieldsMap}
/>
{isRedirecting ? (
<FullScreenLoadingIndicator />
) : (
<>
<HeaderWithBackButton
title={translate('bankAccount.addBankAccount')}
onBackButtonPress={handleBackButtonPress}
/>
<CurrentPage
isEditing={isEditing}
onNext={handleNextScreen}
onMove={moveTo}
formValues={values}
fieldsMap={fieldsMap}
/>
</>
)}
</ScreenWrapper>
);
}
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import ValuePicker from '@components/ValuePicker';
import useInternationalBankAccountFormSubmit from '@hooks/useInternationalBankAccountFormSubmit';
import useLocalize from '@hooks/useLocalize';
import useThemeStyles from '@hooks/useThemeStyles';
import type CustomSubStepProps from '@pages/settings/Wallet/InternationalDepositAccount/types';
import type CustomSubPageProps from '@pages/settings/Wallet/InternationalDepositAccount/types';
import {getValidationErrors} from '@pages/settings/Wallet/InternationalDepositAccount/utils';
import Text from '@src/components/Text';
import CONST from '@src/CONST';
Expand Down Expand Up @@ -41,19 +41,19 @@ function getItems(field: CorpayFormField) {
return (field.links?.[0]?.content.regions ?? []).map(({name, code}) => ({value: code, label: name}));
}

function AccountHolderInformation({isEditing, onNext, formValues, fieldsMap}: CustomSubStepProps) {
function AccountHolderInformation({isEditing, onNext, formValues, fieldsMap}: CustomSubPageProps) {
const {translate} = useLocalize();
const styles = useThemeStyles();

const handleSubmit = useInternationalBankAccountFormSubmit({
fieldIds: Object.keys(fieldsMap[CONST.CORPAY_FIELDS.STEPS_NAME.ACCOUNT_HOLDER_INFORMATION]),
fieldIds: Object.keys(fieldsMap[CONST.CORPAY_FIELDS.PAGE_NAME.ACCOUNT_HOLDER_DETAILS]),
onNext,
shouldSaveDraft: isEditing,
});

const validate = useCallback(
(values: FormOnyxValues<typeof ONYXKEYS.FORMS.INTERNATIONAL_BANK_ACCOUNT_FORM>): FormInputErrors<typeof ONYXKEYS.FORMS.INTERNATIONAL_BANK_ACCOUNT_FORM> => {
return getValidationErrors(values, fieldsMap[CONST.CORPAY_FIELDS.STEPS_NAME.ACCOUNT_HOLDER_INFORMATION], translate);
return getValidationErrors(values, fieldsMap[CONST.CORPAY_FIELDS.PAGE_NAME.ACCOUNT_HOLDER_DETAILS], translate);
},
[fieldsMap, translate],
);
Expand Down Expand Up @@ -89,7 +89,7 @@ function AccountHolderInformation({isEditing, onNext, formValues, fieldsMap}: Cu
>
<View style={styles.ph5}>
<Text style={[styles.textHeadlineLineHeightXXL, styles.mb6]}>{translate('addPersonalBankAccount.accountHolderInformationStepHeader')}</Text>
{Object.values(fieldsMap[CONST.CORPAY_FIELDS.STEPS_NAME.ACCOUNT_HOLDER_INFORMATION])
{Object.values(fieldsMap[CONST.CORPAY_FIELDS.PAGE_NAME.ACCOUNT_HOLDER_DETAILS])
.sort((a, b) => CONST.CORPAY_FIELDS.ACCOUNT_HOLDER_FIELDS.indexOf(a.id) - CONST.CORPAY_FIELDS.ACCOUNT_HOLDER_FIELDS.indexOf(b.id))
.map((field, index) => (
<View
Expand All @@ -108,11 +108,11 @@ function AccountHolderInformation({isEditing, onNext, formValues, fieldsMap}: Cu
value={field.id === CONST.CORPAY_FIELDS.ACCOUNT_HOLDER_COUNTRY_KEY ? formValues.bankCountry : undefined}
shouldSaveDraft={!isEditing}
renamedInputKeys={{
street: isEmptyObject(fieldsMap[CONST.CORPAY_FIELDS.STEPS_NAME.ACCOUNT_HOLDER_INFORMATION]?.accountHolderAddress1) ? '' : 'accountHolderAddress1',
street2: isEmptyObject(fieldsMap[CONST.CORPAY_FIELDS.STEPS_NAME.ACCOUNT_HOLDER_INFORMATION]?.accountHolderAddress2) ? '' : 'accountHolderAddress2',
city: isEmptyObject(fieldsMap[CONST.CORPAY_FIELDS.STEPS_NAME.ACCOUNT_HOLDER_INFORMATION]?.accountHolderCity) ? '' : 'accountHolderCity',
street: isEmptyObject(fieldsMap[CONST.CORPAY_FIELDS.PAGE_NAME.ACCOUNT_HOLDER_DETAILS]?.accountHolderAddress1) ? '' : 'accountHolderAddress1',
street2: isEmptyObject(fieldsMap[CONST.CORPAY_FIELDS.PAGE_NAME.ACCOUNT_HOLDER_DETAILS]?.accountHolderAddress2) ? '' : 'accountHolderAddress2',
city: isEmptyObject(fieldsMap[CONST.CORPAY_FIELDS.PAGE_NAME.ACCOUNT_HOLDER_DETAILS]?.accountHolderCity) ? '' : 'accountHolderCity',
state: '',
zipCode: isEmptyObject(fieldsMap[CONST.CORPAY_FIELDS.STEPS_NAME.ACCOUNT_HOLDER_INFORMATION]?.accountHolderPostal) ? '' : 'accountHolderPostal',
zipCode: isEmptyObject(fieldsMap[CONST.CORPAY_FIELDS.PAGE_NAME.ACCOUNT_HOLDER_DETAILS]?.accountHolderPostal) ? '' : 'accountHolderPostal',
country: '',
lat: '',
lng: '',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,20 +8,20 @@ import useInternationalBankAccountFormSubmit from '@hooks/useInternationalBankAc
import useLocalize from '@hooks/useLocalize';
import useThemeStyles from '@hooks/useThemeStyles';
import {setDraftValues} from '@libs/actions/FormActions';
import type CustomSubStepProps from '@pages/settings/Wallet/InternationalDepositAccount/types';
import type CustomSubPageProps from '@pages/settings/Wallet/InternationalDepositAccount/types';
import Text from '@src/components/Text';
import CONST from '@src/CONST';
import ONYXKEYS from '@src/ONYXKEYS';

function AccountType({isEditing, onNext, fieldsMap}: CustomSubStepProps) {
function AccountType({isEditing, onNext, fieldsMap}: CustomSubPageProps) {
const {translate} = useLocalize();
const styles = useThemeStyles();
const formRef = useRef<FormRef>(null);

const fieldData = fieldsMap[CONST.CORPAY_FIELDS.STEPS_NAME.ACCOUNT_TYPE]?.[CONST.CORPAY_FIELDS.ACCOUNT_TYPE_KEY] ?? {};
const fieldData = fieldsMap[CONST.CORPAY_FIELDS.PAGE_NAME.ACCOUNT_TYPE]?.[CONST.CORPAY_FIELDS.ACCOUNT_TYPE_KEY] ?? {};

const handleSubmit = useInternationalBankAccountFormSubmit({
fieldIds: Object.keys(fieldsMap[CONST.CORPAY_FIELDS.STEPS_NAME.ACCOUNT_TYPE]),
fieldIds: Object.keys(fieldsMap[CONST.CORPAY_FIELDS.PAGE_NAME.ACCOUNT_TYPE]),
onNext,
shouldSaveDraft: isEditing,
});
Expand Down
Loading
Loading