Skip to content

Commit

Permalink
Merge pull request #40226 from nkdengineer/fix/39439
Browse files Browse the repository at this point in the history
Fix disconnected bank account still displayed in workflow page
  • Loading branch information
Hayata Suenaga authored Apr 18, 2024
2 parents fdca69c + 8d6a4a9 commit 9d7ebf2
Showing 1 changed file with 24 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type {OnyxEntry} from 'react-native-onyx';
import type {OnyxCollection, OnyxEntry} from 'react-native-onyx';
import Onyx from 'react-native-onyx';
import * as API from '@libs/API';
import {WRITE_COMMANDS} from '@libs/API/types';
Expand All @@ -10,6 +10,13 @@ import ONYXKEYS from '@src/ONYXKEYS';
import INPUT_IDS from '@src/types/form/ReimbursementAccountForm';
import type * as OnyxTypes from '@src/types/onyx';

let allPolicies: OnyxCollection<OnyxTypes.Policy>;
Onyx.connect({
key: ONYXKEYS.COLLECTION.POLICY,
waitForCollectionCallback: true,
callback: (value) => (allPolicies = value),
});

/**
* Reset user's reimbursement account. This will delete the bank account.
*/
Expand All @@ -21,6 +28,8 @@ function resetFreePlanBankAccount(bankAccountID: number | undefined, session: On
throw new Error('Missing credentials when attempting to reset free plan bank account');
}

const policy = allPolicies?.[`${ONYXKEYS.COLLECTION.POLICY}${policyID}`] ?? ({} as OnyxTypes.Policy);

API.write(
WRITE_COMMANDS.RESTART_BANK_ACCOUNT_SETUP,
{
Expand All @@ -40,6 +49,13 @@ function resetFreePlanBankAccount(bankAccountID: number | undefined, session: On
achData: null,
},
},
{
onyxMethod: Onyx.METHOD.MERGE,
key: `${ONYXKEYS.COLLECTION.POLICY}${policyID}`,
value: {
achAccount: null,
},
},
],
successData: [
{
Expand Down Expand Up @@ -119,6 +135,13 @@ function resetFreePlanBankAccount(bankAccountID: number | undefined, session: On
key: ONYXKEYS.REIMBURSEMENT_ACCOUNT,
value: {isLoading: false, pendingAction: null},
},
{
onyxMethod: Onyx.METHOD.MERGE,
key: `${ONYXKEYS.COLLECTION.POLICY}${policyID}`,
value: {
achAccount: policy?.achAccount,
},
},
],
},
);
Expand Down

0 comments on commit 9d7ebf2

Please sign in to comment.