Skip to content

Commit

Permalink
Merge pull request #45295 from dominictb/fix/45035-lhn-empty
Browse files Browse the repository at this point in the history
fix: clear duplicated report data
  • Loading branch information
puneetlath authored Jul 15, 2024
2 parents fc15af0 + ed8fdb0 commit 4b0f57f
Showing 1 changed file with 29 additions and 4 deletions.
33 changes: 29 additions & 4 deletions src/libs/actions/Report.ts
Original file line number Diff line number Diff line change
Expand Up @@ -251,6 +251,14 @@ Onyx.connect({
callback: (val) => (quickAction = val),
});

let allReportDraftComments: Record<string, string | undefined> = {};

Onyx.connect({
key: ONYXKEYS.COLLECTION.REPORT_DRAFT_COMMENT,
waitForCollectionCallback: true,
callback: (value) => (allReportDraftComments = value),
});

registerPaginationConfig({
initialCommand: WRITE_COMMANDS.OPEN_REPORT,
previousCommand: READ_COMMANDS.GET_OLDER_ACTIONS,
Expand Down Expand Up @@ -1318,6 +1326,7 @@ function handleReportChanged(report: OnyxEntry<Report>) {
if (report?.reportID && report.preexistingReportID) {
let callback = () => {
Onyx.set(`${ONYXKEYS.COLLECTION.REPORT}${report.reportID}`, null);
Onyx.set(`${ONYXKEYS.COLLECTION.REPORT_DRAFT_COMMENT}${report.reportID}`, null);
};
// Only re-route them if they are still looking at the optimistically created report
if (Navigation.getActiveRoute().includes(`/r/${report.reportID}`)) {
Expand All @@ -1326,11 +1335,27 @@ function handleReportChanged(report: OnyxEntry<Report>) {
currCallback();
Navigation.navigate(ROUTES.REPORT_WITH_ID.getRoute(report.preexistingReportID ?? '-1'), CONST.NAVIGATION.TYPE.UP);
};

// The report screen will listen to this event and transfer the draft comment to the existing report
// This will allow the newest draft comment to be transferred to the existing report
DeviceEventEmitter.emit(`switchToPreExistingReport_${report.reportID}`, {
preexistingReportID: report.preexistingReportID,
callback,
});

return;
}
DeviceEventEmitter.emit(`switchToPreExistingReport_${report.reportID}`, {
preexistingReportID: report.preexistingReportID,
callback,
});

// In case the user is not on the report screen, we will transfer the report draft comment directly to the existing report
// after that clear the optimistically created report
const draftReportComment = allReportDraftComments?.[`${ONYXKEYS.COLLECTION.REPORT_DRAFT_COMMENT}${report.reportID}`];
if (!draftReportComment) {
callback();
return;
}

saveReportDraftComment(report.preexistingReportID ?? '-1', draftReportComment, callback);

return;
}

Expand Down

0 comments on commit 4b0f57f

Please sign in to comment.