From aae942d81a502471c4f84555bc977108d7af1036 Mon Sep 17 00:00:00 2001 From: Youssef Lourayad Date: Wed, 29 May 2024 22:05:23 +0100 Subject: [PATCH 1/2] Cleanup optimistic data of unusued IOU report --- src/libs/actions/Report.ts | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/src/libs/actions/Report.ts b/src/libs/actions/Report.ts index aa134d47cf77..a3a5b3e0a76b 100644 --- a/src/libs/actions/Report.ts +++ b/src/libs/actions/Report.ts @@ -186,12 +186,12 @@ const allReportActions: OnyxCollection = {}; Onyx.connect({ key: ONYXKEYS.COLLECTION.REPORT_ACTIONS, - callback: (action, key) => { - if (!key || !action) { + callback: (actions, key) => { + if (!key || !actions) { return; } const reportID = CollectionUtils.extractCollectionItemID(key); - allReportActions[reportID] = action; + allReportActions[reportID] = actions; }, }); @@ -1282,6 +1282,14 @@ function handleReportChanged(report: OnyxEntry) { return; } + if (report?.reportID && report.preexistingReportID && ReportUtils.isMoneyRequestReport(report)) { + Onyx.merge(`${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${report.parentReportID}`, { + [report.parentReportActionID]: null, + }); + Onyx.merge(`${ONYXKEYS.COLLECTION.REPORT}${report.reportID}`, null); + return; + } + // It is possible that we optimistically created a DM/group-DM for a set of users for which a report already exists. // In this case, the API will let us know by returning a preexistingReportID. // We should clear out the optimistically created report and re-route the user to the preexisting report. From aeccf49cffe1fc69276ff63c40474fca7e02740f Mon Sep 17 00:00:00 2001 From: Youssef Lourayad Date: Sun, 18 Aug 2024 19:42:00 +0100 Subject: [PATCH 2/2] Fix TS check --- src/libs/actions/Report.ts | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/libs/actions/Report.ts b/src/libs/actions/Report.ts index cb771db4aabf..3d663b0f4cb2 100644 --- a/src/libs/actions/Report.ts +++ b/src/libs/actions/Report.ts @@ -1336,7 +1336,8 @@ function handleReportChanged(report: OnyxEntry) { return; } - if (report?.reportID && report.preexistingReportID && ReportUtils.isMoneyRequestReport(report)) { + // Handle cleanup of stale optimistic IOU report and its report preview separately + if (report?.reportID && report.preexistingReportID && ReportUtils.isMoneyRequestReport(report) && report?.parentReportActionID) { Onyx.merge(`${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${report.parentReportID}`, { [report.parentReportActionID]: null, });