Skip to content

Commit

Permalink
clear pending action when success
Browse files Browse the repository at this point in the history
  • Loading branch information
bernhardoj committed Nov 26, 2024
1 parent 2719015 commit 2e68cb9
Showing 1 changed file with 26 additions and 1 deletion.
27 changes: 26 additions & 1 deletion src/libs/actions/IOU.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import {format} from 'date-fns';
import {fastMerge, Str} from 'expensify-common';
import {InteractionManager} from 'react-native';
import type {NullishDeep, OnyxCollection, OnyxEntry, OnyxInputValue, OnyxUpdate} from 'react-native-onyx';
import type {NullishDeep, OnyxCollection, OnyxEntry, OnyxInputValue, OnyxMergeInput, OnyxUpdate} from 'react-native-onyx';
import Onyx from 'react-native-onyx';
import type {PartialDeep, SetRequired, ValueOf} from 'type-fest';
import ReceiptGeneric from '@assets/images/receipt-generic.png';
Expand Down Expand Up @@ -6313,6 +6313,7 @@ function getReportFromHoldRequestsOnyxData(
optimisticHoldActionID: string;
optimisticHoldReportExpenseActionIDs: OptimisticHoldReportExpenseActionID[];
optimisticData: OnyxUpdate[];
successData: OnyxUpdate[];
failureData: OnyxUpdate[];
} {
const {holdReportActions, holdTransactions} = getHoldReportActionsAndTransactions(iouReport?.reportID ?? '');
Expand Down Expand Up @@ -6352,6 +6353,7 @@ function getReportFromHoldRequestsOnyxData(

const updateHeldReports: Record<string, Pick<OnyxTypes.Report, 'parentReportActionID' | 'parentReportID' | 'chatReportID'>> = {};
const addHoldReportActions: OnyxTypes.ReportActions = {};
const addHoldReportActionsSuccess: OnyxCollection<NullishDeep<ReportAction>> = {};
const deleteHoldReportActions: Record<string, Pick<OnyxTypes.ReportAction, 'message'>> = {};
const optimisticHoldReportExpenseActionIDs: OptimisticHoldReportExpenseActionID[] = [];

Expand All @@ -6378,6 +6380,9 @@ function getReportFromHoldRequestsOnyxData(
},
pendingAction: CONST.RED_BRICK_ROAD_PENDING_ACTION.ADD,
};
addHoldReportActionsSuccess[reportActionID] = {
pendingAction: null,
};

const heldReport = ReportUtils.getReportOrDraftReport(holdReportAction.childReportID);
if (heldReport) {
Expand Down Expand Up @@ -6459,6 +6464,23 @@ function getReportFromHoldRequestsOnyxData(
bringHeldTransactionsBack[`${ONYXKEYS.COLLECTION.TRANSACTION}${transaction.transactionID}`] = transaction;
});

const successData: OnyxUpdate[] = [
{
onyxMethod: Onyx.METHOD.MERGE,
key: `${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${chatReport.reportID}`,
value: {
[optimisticExpenseReportPreview.reportActionID]: {
pendingAction: null,
},
},
},
{
onyxMethod: Onyx.METHOD.MERGE,
key: `${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${optimisticExpenseReport.reportID}`,
value: addHoldReportActionsSuccess,
},
];

const failureData: OnyxUpdate[] = [
// remove added optimistic expense report
{
Expand Down Expand Up @@ -6498,6 +6520,7 @@ function getReportFromHoldRequestsOnyxData(
optimisticData,
optimisticHoldActionID: optimisticExpenseReportPreview.reportActionID,
failureData,
successData,
optimisticHoldReportID: optimisticExpenseReport.reportID,
optimisticHoldReportExpenseActionIDs,
};
Expand Down Expand Up @@ -6758,6 +6781,7 @@ function getPayMoneyRequestParams(
const holdReportOnyxData = getReportFromHoldRequestsOnyxData(chatReport, iouReport, recipient);

optimisticData.push(...holdReportOnyxData.optimisticData);
successData.push(...holdReportOnyxData.successData);
failureData.push(...holdReportOnyxData.failureData);
optimisticHoldReportID = holdReportOnyxData.optimisticHoldReportID;
optimisticHoldActionID = holdReportOnyxData.optimisticHoldActionID;
Expand Down Expand Up @@ -7104,6 +7128,7 @@ function approveMoneyRequest(expenseReport: OnyxEntry<OnyxTypes.Report>, full?:
const holdReportOnyxData = getReportFromHoldRequestsOnyxData(chatReport, expenseReport, {accountID: expenseReport.ownerAccountID});

optimisticData.push(...holdReportOnyxData.optimisticData);
successData.push(...holdReportOnyxData.successData);
failureData.push(...holdReportOnyxData.failureData);
optimisticHoldReportID = holdReportOnyxData.optimisticHoldReportID;
optimisticHoldActionID = holdReportOnyxData.optimisticHoldActionID;
Expand Down

0 comments on commit 2e68cb9

Please sign in to comment.