Skip to content

Commit

Permalink
Merge pull request #51981 from CyberAndrii/51961-fix-crash-on-Connect…
Browse files Browse the repository at this point in the history
…-bank-account-page

Fix crash on Connect bank account page
  • Loading branch information
Julesssss authored Nov 5, 2024
2 parents 6778419 + 4ae18ab commit d01138a
Showing 1 changed file with 10 additions and 10 deletions.
20 changes: 10 additions & 10 deletions src/pages/ReimbursementAccount/ReimbursementAccountPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -170,16 +170,6 @@ function ReimbursementAccountPage({route, policy}: ReimbursementAccountPageProps
const currentStep = !isPreviousPolicy ? CONST.BANK_ACCOUNT.STEP.BANK_ACCOUNT : achData?.currentStep || CONST.BANK_ACCOUNT.STEP.BANK_ACCOUNT;
const [nonUSDBankAccountStep, setNonUSDBankAccountStep] = useState<string>(CONST.NON_USD_BANK_ACCOUNT.STEP.COUNTRY);

/**
When this page is first opened, `reimbursementAccount` prop might not yet be fully loaded from Onyx.
Calculating `shouldShowContinueSetupButton` immediately on initial render doesn't make sense as
it relies on incomplete data. Thus, we should wait to calculate it until we have received
the full `reimbursementAccount` data from the server. This logic is handled within the useEffect hook,
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 {
...lodashPick(reimbursementAccount?.achData, ...fieldNames),
Expand All @@ -205,6 +195,16 @@ function ReimbursementAccountPage({route, policy}: ReimbursementAccountPageProps
return achData?.state === BankAccount.STATE.PENDING || [CONST.BANK_ACCOUNT.STEP.BANK_ACCOUNT, ''].includes(getStepToOpenFromRouteParams(route));
}

/**
When this page is first opened, `reimbursementAccount` prop might not yet be fully loaded from Onyx.
Calculating `shouldShowContinueSetupButton` immediately on initial render doesn't make sense as
it relies on incomplete data. Thus, we should wait to calculate it until we have received
the full `reimbursementAccount` data from the server. This logic is handled within the useEffect hook,
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());

const handleNextNonUSDBankAccountStep = () => {
switch (nonUSDBankAccountStep) {
case CONST.NON_USD_BANK_ACCOUNT.STEP.COUNTRY:
Expand Down

0 comments on commit d01138a

Please sign in to comment.