From 0cc7f26dfe7aee4ad503baab264f14cb41bcc8ed Mon Sep 17 00:00:00 2001 From: mkzie2 Date: Mon, 24 Mar 2025 14:06:57 +0700 Subject: [PATCH 1/2] add opitmistic data for addPersonalBankAccount --- src/libs/actions/BankAccounts.ts | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/src/libs/actions/BankAccounts.ts b/src/libs/actions/BankAccounts.ts index f3f6fb576a873..94efd2312068a 100644 --- a/src/libs/actions/BankAccounts.ts +++ b/src/libs/actions/BankAccounts.ts @@ -28,6 +28,7 @@ import type PlaidBankAccount from '@src/types/onyx/PlaidBankAccount'; import type {BankAccountStep, ReimbursementAccountStep, ReimbursementAccountSubStep} from '@src/types/onyx/ReimbursementAccount'; import type {OnyxData} from '@src/types/onyx/Request'; import {setBankAccountSubStep} from './ReimbursementAccount'; +import { getCurrentUserEmail } from './Report'; export { goToWithdrawalAccountSetupStep, @@ -260,6 +261,19 @@ function addPersonalBankAccount(account: PlaidBankAccount, policyID?: string, so currentStep: CONST.WALLET.STEP.ADDITIONAL_DETAILS, }, }, + { + onyxMethod: Onyx.METHOD.MERGE, + key: `${ONYXKEYS.COLLECTION.POLICY}${policyID}`, + value: { + achAccount: { + addressName: account.addressName, + accountNumber: account.accountNumber, + routingNumber: account.routingNumber, + bank: account.bankName, + reimburser: getCurrentUserEmail(), + } + } + } ], failureData: [ { From 0409a87413b799ea79e16f34c88bf5795ee5aedf Mon Sep 17 00:00:00 2001 From: mkzie2 Date: Mon, 24 Mar 2025 15:07:21 +0700 Subject: [PATCH 2/2] convert data to achAccount data --- src/libs/actions/BankAccounts.ts | 39 ++++++++++++------- .../ConnectedVerifiedBankAccount.tsx | 5 +++ 2 files changed, 30 insertions(+), 14 deletions(-) diff --git a/src/libs/actions/BankAccounts.ts b/src/libs/actions/BankAccounts.ts index 94efd2312068a..958452a80d738 100644 --- a/src/libs/actions/BankAccounts.ts +++ b/src/libs/actions/BankAccounts.ts @@ -1,4 +1,5 @@ import Onyx from 'react-native-onyx'; +import type {OnyxEntry} from 'react-native-onyx'; import type {FormInputErrors, FormOnyxValues} from '@components/Form/types'; import type {OnfidoDataWithApplicantID} from '@components/Onfido/types'; import * as API from '@libs/API'; @@ -17,6 +18,7 @@ import {READ_COMMANDS, SIDE_EFFECT_REQUEST_COMMANDS, WRITE_COMMANDS} from '@libs import {getMicroSecondOnyxErrorWithTranslationKey} from '@libs/ErrorUtils'; import {translateLocal} from '@libs/Localize'; import Navigation from '@libs/Navigation/Navigation'; +import {getPolicy} from '@libs/PolicyUtils'; import CONST from '@src/CONST'; import type {Country} from '@src/CONST'; import ONYXKEYS from '@src/ONYXKEYS'; @@ -26,9 +28,10 @@ import type {InternationalBankAccountForm, PersonalBankAccountForm} from '@src/t import type {ACHContractStepProps, BeneficialOwnersStepProps, CompanyStepProps, ReimbursementAccountForm, RequestorStepProps} from '@src/types/form/ReimbursementAccountForm'; import type PlaidBankAccount from '@src/types/onyx/PlaidBankAccount'; import type {BankAccountStep, ReimbursementAccountStep, ReimbursementAccountSubStep} from '@src/types/onyx/ReimbursementAccount'; +import type ReimbursementAccount from '@src/types/onyx/ReimbursementAccount'; import type {OnyxData} from '@src/types/onyx/Request'; import {setBankAccountSubStep} from './ReimbursementAccount'; -import { getCurrentUserEmail } from './Report'; +import {getCurrentUserEmail} from './Report'; export { goToWithdrawalAccountSetupStep, @@ -261,19 +264,6 @@ function addPersonalBankAccount(account: PlaidBankAccount, policyID?: string, so currentStep: CONST.WALLET.STEP.ADDITIONAL_DETAILS, }, }, - { - onyxMethod: Onyx.METHOD.MERGE, - key: `${ONYXKEYS.COLLECTION.POLICY}${policyID}`, - value: { - achAccount: { - addressName: account.addressName, - accountNumber: account.accountNumber, - routingNumber: account.routingNumber, - bank: account.bankName, - reimburser: getCurrentUserEmail(), - } - } - } ], failureData: [ { @@ -380,6 +370,26 @@ function validateBankAccount(bankAccountID: number, validateCode: string, policy API.write(WRITE_COMMANDS.VALIDATE_BANK_ACCOUNT_WITH_TRANSACTIONS, parameters, onyxData); } +function convertReimbursementAccountDataToAchAccountData(reimbursementAccount: OnyxEntry) { + const achData = reimbursementAccount?.achData; + const policy = getPolicy(achData?.policyID); + if (!achData || policy?.achAccount?.bankAccountID) { + return; + } + + Onyx.merge(`${ONYXKEYS.COLLECTION.POLICY}${achData?.policyID}`, { + achAccount: { + bankAccountID: achData?.bankAccountID, + bankName: achData?.bankName, + reimburser: policy?.achAccount?.reimburser ?? getCurrentUserEmail(), + accountNumber: achData.accountNumber, + routingNumber: achData.routingNumber, + addressName: achData.addressName, + }, + reimbursementChoice: CONST.POLICY.REIMBURSEMENT_CHOICES.REIMBURSEMENT_YES, + }); +} + function getCorpayBankAccountFields(country: string, currency: string) { const parameters = { countryISO: country, @@ -863,6 +873,7 @@ export { saveCorpayOnboardingBeneficialOwners, clearReimbursementAccountSaveCorpayOnboardingBeneficialOwners, clearCorpayBankAccountFields, + convertReimbursementAccountDataToAchAccountData, }; export type {BusinessAddress, PersonalAddress}; diff --git a/src/pages/ReimbursementAccount/ConnectedVerifiedBankAccount.tsx b/src/pages/ReimbursementAccount/ConnectedVerifiedBankAccount.tsx index f70c27bdbcd2a..099e3182ca516 100644 --- a/src/pages/ReimbursementAccount/ConnectedVerifiedBankAccount.tsx +++ b/src/pages/ReimbursementAccount/ConnectedVerifiedBankAccount.tsx @@ -10,8 +10,10 @@ import ScreenWrapper from '@components/ScreenWrapper'; import ScrollView from '@components/ScrollView'; import Section from '@components/Section'; import Text from '@components/Text'; +import useBeforeRemove from '@hooks/useBeforeRemove'; import useLocalize from '@hooks/useLocalize'; import useThemeStyles from '@hooks/useThemeStyles'; +import {convertReimbursementAccountDataToAchAccountData} from '@libs/actions/BankAccounts'; import WorkspaceResetBankAccountModal from '@pages/workspace/WorkspaceResetBankAccountModal'; import {requestResetBankAccount, resetReimbursementAccount} from '@userActions/ReimbursementAccount'; import type {ReimbursementAccount} from '@src/types/onyx'; @@ -58,6 +60,9 @@ function ConnectedVerifiedBankAccount({ const pendingAction = reimbursementAccount?.pendingAction; const shouldShowResetModal = reimbursementAccount?.shouldShowResetModal ?? false; + useBeforeRemove(() => { + convertReimbursementAccountDataToAchAccountData(reimbursementAccount); + }); return (