Skip to content

Commit

Permalink
clear the report when there is a preexisting report
Browse files Browse the repository at this point in the history
  • Loading branch information
bernhardoj committed Jun 13, 2024
1 parent a451de4 commit 7ee0fca
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion src/libs/actions/Report.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1280,10 +1280,14 @@ function handleReportChanged(report: OnyxEntry<Report>) {
// 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.
if (report?.reportID && report.preexistingReportID) {
let callback = () => {};
let callback = () => {
Onyx.set(`${ONYXKEYS.COLLECTION.REPORT}${report.reportID}`, null);
};
// Only re-route them if they are still looking at the optimistically created report
if (Navigation.getActiveRoute().includes(`/r/${report.reportID}`)) {
const currCallback = callback;
callback = () => {
currCallback();
Navigation.navigate(ROUTES.REPORT_WITH_ID.getRoute(report.preexistingReportID ?? ''), CONST.NAVIGATION.TYPE.UP);
};
}
Expand Down

0 comments on commit 7ee0fca

Please sign in to comment.