Skip to content

Commit

Permalink
Merge pull request Expensify#51857 from DylanDylann/revert-51315-impr…
Browse files Browse the repository at this point in the history
…ove-bank-account-flow
  • Loading branch information
mountiny authored Nov 1, 2024
2 parents bfce277 + cacee3b commit fa5007e
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 15 deletions.
18 changes: 6 additions & 12 deletions src/pages/ReimbursementAccount/ReimbursementAccountPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import type {RouteProp} from '@react-navigation/native';
import type {StackScreenProps} from '@react-navigation/stack';
import {Str} from 'expensify-common';
import lodashPick from 'lodash/pick';
import React, {useCallback, useEffect, useRef, useState} from 'react';
import React, {useEffect, useRef, useState} from 'react';
import {View} from 'react-native';
import {useOnyx} from 'react-native-onyx';
import type {ValueOf} from 'type-fest';
Expand Down Expand Up @@ -178,6 +178,7 @@ function ReimbursementAccountPage({route, policy}: ReimbursementAccountPageProps
which acts similarly to `componentDidUpdate` when the `reimbursementAccount` dependency changes.
*/
const [hasACHDataBeenLoaded, setHasACHDataBeenLoaded] = useState(reimbursementAccount !== CONST.REIMBURSEMENT_ACCOUNT.DEFAULT_DATA && isPreviousPolicy);
const [shouldShowContinueSetupButton, setShouldShowContinueSetupButton] = useState(getShouldShowContinueSetupButtonInitialValue());

function getBankAccountFields(fieldNames: InputID[]): Partial<ACHDataReimbursementAccount> {
return {
Expand All @@ -188,28 +189,21 @@ function ReimbursementAccountPage({route, policy}: ReimbursementAccountPageProps
/**
* Returns true if a VBBA exists in any state other than OPEN or LOCKED
*/
const hasInProgressVBBA = useCallback(() => {
function hasInProgressVBBA(): boolean {
return !!achData?.bankAccountID && !!achData?.state && achData?.state !== BankAccount.STATE.OPEN && achData?.state !== BankAccount.STATE.LOCKED;
}, [achData?.bankAccountID, achData?.state]);
}

/*
* Calculates the state used to show the "Continue with setup" view. If a bank account setup is already in progress and
* no specific further step was passed in the url we'll show the workspace bank account reset modal if the user wishes to start over
*/
const getShouldShowContinueSetupButtonInitialValue = useCallback(() => {
function getShouldShowContinueSetupButtonInitialValue(): boolean {
if (!hasInProgressVBBA()) {
// Since there is no VBBA in progress, we won't need to show the component ContinueBankAccountSetup
return false;
}
return achData?.state === BankAccount.STATE.PENDING || [CONST.BANK_ACCOUNT.STEP.BANK_ACCOUNT, ''].includes(getStepToOpenFromRouteParams(route));
}, [achData?.state, hasInProgressVBBA, route]);

const [shouldShowContinueSetupButton, setShouldShowContinueSetupButton] = useState(getShouldShowContinueSetupButtonInitialValue());

useEffect(() => {
setShouldShowContinueSetupButton(getShouldShowContinueSetupButtonInitialValue());
setHasACHDataBeenLoaded(reimbursementAccount !== CONST.REIMBURSEMENT_ACCOUNT.DEFAULT_DATA && isPreviousPolicy);
}, [achData, getShouldShowContinueSetupButtonInitialValue, isPreviousPolicy, reimbursementAccount]);
}

const handleNextNonUSDBankAccountStep = () => {
switch (nonUSDBankAccountStep) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import CONST from '@src/CONST';
import ONYXKEYS from '@src/ONYXKEYS';
import ROUTES from '@src/ROUTES';
import type SCREENS from '@src/SCREENS';
import {isEmptyObject} from '@src/types/utils/EmptyObject';

const expensifyCardFeatures: FeatureListItem[] = [
{
Expand Down Expand Up @@ -54,15 +55,15 @@ function WorkspaceExpensifyCardPageEmptyState({route, policy}: WorkspaceExpensif
const eligibleBankAccounts = CardUtils.getEligibleBankAccountsForCard(bankAccountList ?? {});

const reimbursementAccountStatus = reimbursementAccount?.achData?.state ?? '';
const isSetupUnfinished = !eligibleBankAccounts.length && reimbursementAccountStatus && reimbursementAccountStatus !== CONST.BANK_ACCOUNT.STATE.OPEN;
const isSetupUnfinished = isEmptyObject(bankAccountList) && reimbursementAccountStatus && reimbursementAccountStatus !== CONST.BANK_ACCOUNT.STATE.OPEN;

const startFlow = useCallback(() => {
if (!eligibleBankAccounts.length) {
if (!eligibleBankAccounts.length || isSetupUnfinished) {
Navigation.navigate(ROUTES.BANK_ACCOUNT_WITH_STEP_TO_OPEN.getRoute('new', policy?.id, ROUTES.WORKSPACE_EXPENSIFY_CARD.getRoute(policy?.id ?? '-1')));
} else {
Navigation.navigate(ROUTES.WORKSPACE_EXPENSIFY_CARD_BANK_ACCOUNT.getRoute(policy?.id ?? '-1'));
}
}, [eligibleBankAccounts.length, policy?.id]);
}, [eligibleBankAccounts.length, isSetupUnfinished, policy?.id]);

const confirmCurrencyChangeAndHideModal = useCallback(() => {
if (!policy) {
Expand Down

0 comments on commit fa5007e

Please sign in to comment.