diff --git a/src/libs/actions/Report.ts b/src/libs/actions/Report.ts index 12484f9a5d6e..de66d298de81 100644 --- a/src/libs/actions/Report.ts +++ b/src/libs/actions/Report.ts @@ -5059,31 +5059,54 @@ function deleteAppReport(reportID: string | undefined) { value: reportActionsForReport, }); - // 7. Delete the report + // 7. Mark the iouReport as being deleted and then delete it optimisticData.push({ onyxMethod: Onyx.METHOD.MERGE, key: `${ONYXKEYS.COLLECTION.REPORT}${reportID}`, + value: { + pendingFields: { + preview: CONST.RED_BRICK_ROAD_PENDING_ACTION.DELETE, + }, + }, + }); + + successData.push({ + onyxMethod: Onyx.METHOD.SET, + key: `${ONYXKEYS.COLLECTION.REPORT}${reportID}`, value: null, }); // @ts-expect-error - will be solved in https://github.com/Expensify/App/issues/73830 failureData.push({ - onyxMethod: Onyx.METHOD.MERGE, + onyxMethod: Onyx.METHOD.SET, key: `${ONYXKEYS.COLLECTION.REPORT}${reportID}`, value: report, }); - // 8. Delete chat report preview + // 8. Mark chat report preview action as deleted const reportActionID = report?.parentReportActionID; - const reportAction = allReportActions?.[reportID]; const parentReportID = report?.parentReportID; + const parentReportAction = parentReportID && reportActionID ? allReportActions?.[parentReportID]?.[reportActionID] : undefined; if (reportActionID) { optimisticData.push({ onyxMethod: Onyx.METHOD.MERGE, key: `${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${parentReportID}`, value: { - [reportActionID]: null, + [reportActionID]: { + pendingAction: CONST.RED_BRICK_ROAD_PENDING_ACTION.DELETE, + }, + }, + }); + + successData.push({ + onyxMethod: Onyx.METHOD.MERGE, + key: `${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${parentReportID}`, + value: { + [reportActionID]: { + pendingAction: null, + errors: null, + }, }, }); @@ -5091,7 +5114,10 @@ function deleteAppReport(reportID: string | undefined) { onyxMethod: Onyx.METHOD.MERGE, key: `${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${parentReportID}`, value: { - [reportActionID]: reportAction, + [reportActionID]: { + ...parentReportAction, + errors: getMicroSecondOnyxErrorWithTranslationKey('iou.error.genericDeleteFailureMessage'), + }, }, }); }