diff --git a/src/libs/actions/BankAccounts.ts b/src/libs/actions/BankAccounts.ts index bf57b2b0b94be..59c93f9e280f6 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'; @@ -19,6 +20,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'; @@ -28,8 +30,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'; export { goToWithdrawalAccountSetupStep, @@ -357,6 +361,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, @@ -922,4 +946,5 @@ export { clearCorpayBankAccountFields, finishCorpayBankAccountOnboarding, clearReimbursementAccountFinishCorpayBankAccountOnboarding, + convertReimbursementAccountDataToAchAccountData, }; diff --git a/src/pages/ReimbursementAccount/ConnectedVerifiedBankAccount.tsx b/src/pages/ReimbursementAccount/ConnectedVerifiedBankAccount.tsx index 7094068ac0cd4..cae926345764c 100644 --- a/src/pages/ReimbursementAccount/ConnectedVerifiedBankAccount.tsx +++ b/src/pages/ReimbursementAccount/ConnectedVerifiedBankAccount.tsx @@ -10,9 +10,11 @@ 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 useResponsiveLayout from '@hooks/useResponsiveLayout'; 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'; @@ -60,6 +62,9 @@ function ConnectedVerifiedBankAccount({ const pendingAction = reimbursementAccount?.pendingAction; const shouldShowResetModal = reimbursementAccount?.shouldShowResetModal ?? false; + useBeforeRemove(() => { + convertReimbursementAccountDataToAchAccountData(reimbursementAccount); + }); return (