Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
28 changes: 26 additions & 2 deletions src/libs/actions/ReimbursementAccount/resetNonUSDBankAccount.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,40 @@
import Onyx from 'react-native-onyx';
import type {OnyxEntry} from 'react-native-onyx';
import type {OnyxEntry, OnyxUpdate} from 'react-native-onyx';
import * as API from '@libs/API';
import {WRITE_COMMANDS} from '@libs/API/types';
import CONST from '@src/CONST';
import ONYXKEYS from '@src/ONYXKEYS';
import type {ACHAccount} from '@src/types/onyx/Policy';

function resetNonUSDBankAccount(policyID: string | undefined, achAccount: OnyxEntry<ACHAccount>) {
function resetNonUSDBankAccount(policyID: string | undefined, achAccount: OnyxEntry<ACHAccount>, shouldResetLocally: boolean) {
if (!policyID) {
throw new Error('Missing policy when attempting to reset');
}

if (shouldResetLocally) {
const updateData = [
{
onyxMethod: Onyx.METHOD.SET,
key: ONYXKEYS.FORMS.REIMBURSEMENT_ACCOUNT_FORM_DRAFT,
value: null,
},
{
onyxMethod: Onyx.METHOD.MERGE,
key: `${ONYXKEYS.COLLECTION.POLICY}${policyID}`,
value: {
achAccount: null,
},
},
{
onyxMethod: Onyx.METHOD.SET,
key: ONYXKEYS.REIMBURSEMENT_ACCOUNT,
value: CONST.REIMBURSEMENT_ACCOUNT.DEFAULT_DATA,
},
];
Onyx.update(updateData as OnyxUpdate[]);
return;
}

API.write(
WRITE_COMMANDS.RESET_BANK_ACCOUNT_SETUP,
{policyID},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,7 @@ function ReimbursementAccountPage({route, policy, isLoadingPolicy, navigation}:
}
fetchData();
// eslint-disable-next-line react-compiler/react-compiler, react-hooks/exhaustive-deps
}, []); // The empty dependency array ensures this runs only once after the component mounts.
}, [isPreviousPolicy]); // Only re-run this effect when isPreviousPolicy changes, which happens once when the component first loads

useEffect(() => {
if (!isPreviousPolicy) {
Expand Down
2 changes: 1 addition & 1 deletion src/pages/workspace/WorkspaceResetBankAccountModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ function WorkspaceResetBankAccountModal({

const handleConfirm = () => {
if (isNonUSDWorkspace) {
resetNonUSDBankAccount(policyID, policy?.achAccount);
resetNonUSDBankAccount(policyID, policy?.achAccount, !achData?.bankAccountID);

if (setShouldShowConnectedVerifiedBankAccount) {
setShouldShowConnectedVerifiedBankAccount(false);
Expand Down
Loading