Skip to content

Commit

Permalink
Merge pull request #42806 from Expensify/youssef_cleanup_iou_optimist…
Browse files Browse the repository at this point in the history
…ic_data

Cleanup optimistic data of stale Chat/IOU report
  • Loading branch information
stitesExpensify authored Sep 24, 2024
2 parents a8e95b9 + 2707088 commit a7a0c53
Showing 1 changed file with 12 additions and 3 deletions.
15 changes: 12 additions & 3 deletions src/libs/actions/Report.ts
Original file line number Diff line number Diff line change
Expand Up @@ -187,12 +187,12 @@ const allReportActions: OnyxCollection<ReportActions> = {};

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;
},
});

Expand Down Expand Up @@ -1357,6 +1357,15 @@ function handleReportChanged(report: OnyxEntry<Report>) {
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.
Expand Down

0 comments on commit a7a0c53

Please sign in to comment.