diff --git a/src/libs/actions/Report.ts b/src/libs/actions/Report.ts index a8911cefa90..e53cac804b9 100644 --- a/src/libs/actions/Report.ts +++ b/src/libs/actions/Report.ts @@ -187,12 +187,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; }, }); @@ -1357,6 +1357,15 @@ function handleReportChanged(report: OnyxEntry) { return; } + // 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, + }); + 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.