Skip to content

Commit a726294

Browse files
authored
Merge pull request Expensify#69672 from nkdengineer/fix/69130
Start Over in bank account does not clear data
2 parents 9eaa84a + c35c9d7 commit a726294

3 files changed

Lines changed: 28 additions & 4 deletions

File tree

src/libs/actions/ReimbursementAccount/resetNonUSDBankAccount.ts

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,40 @@
11
import Onyx from 'react-native-onyx';
2-
import type {OnyxEntry} from 'react-native-onyx';
2+
import type {OnyxEntry, OnyxUpdate} from 'react-native-onyx';
33
import * as API from '@libs/API';
44
import {WRITE_COMMANDS} from '@libs/API/types';
55
import CONST from '@src/CONST';
66
import ONYXKEYS from '@src/ONYXKEYS';
77
import type {ACHAccount} from '@src/types/onyx/Policy';
88

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

14+
if (shouldResetLocally) {
15+
const updateData = [
16+
{
17+
onyxMethod: Onyx.METHOD.SET,
18+
key: ONYXKEYS.FORMS.REIMBURSEMENT_ACCOUNT_FORM_DRAFT,
19+
value: null,
20+
},
21+
{
22+
onyxMethod: Onyx.METHOD.MERGE,
23+
key: `${ONYXKEYS.COLLECTION.POLICY}${policyID}`,
24+
value: {
25+
achAccount: null,
26+
},
27+
},
28+
{
29+
onyxMethod: Onyx.METHOD.SET,
30+
key: ONYXKEYS.REIMBURSEMENT_ACCOUNT,
31+
value: CONST.REIMBURSEMENT_ACCOUNT.DEFAULT_DATA,
32+
},
33+
];
34+
Onyx.update(updateData as OnyxUpdate[]);
35+
return;
36+
}
37+
1438
API.write(
1539
WRITE_COMMANDS.RESET_BANK_ACCOUNT_SETUP,
1640
{policyID},

src/pages/ReimbursementAccount/ReimbursementAccountPage.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -199,7 +199,7 @@ function ReimbursementAccountPage({route, policy, isLoadingPolicy, navigation}:
199199
}
200200
fetchData();
201201
// eslint-disable-next-line react-compiler/react-compiler, react-hooks/exhaustive-deps
202-
}, []); // The empty dependency array ensures this runs only once after the component mounts.
202+
}, [isPreviousPolicy]); // Only re-run this effect when isPreviousPolicy changes, which happens once when the component first loads
203203

204204
useEffect(() => {
205205
if (!isPreviousPolicy) {

src/pages/workspace/WorkspaceResetBankAccountModal.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ function WorkspaceResetBankAccountModal({
5555

5656
const handleConfirm = () => {
5757
if (isNonUSDWorkspace) {
58-
resetNonUSDBankAccount(policyID, policy?.achAccount);
58+
resetNonUSDBankAccount(policyID, policy?.achAccount, !achData?.bankAccountID);
5959

6060
if (setShouldShowConnectedVerifiedBankAccount) {
6161
setShouldShowConnectedVerifiedBankAccount(false);

0 commit comments

Comments
 (0)