diff --git a/src/libs/actions/Report.ts b/src/libs/actions/Report.ts index ca489b923265..88fd5c8fb984 100644 --- a/src/libs/actions/Report.ts +++ b/src/libs/actions/Report.ts @@ -2674,6 +2674,11 @@ function navigateToMostRecentReport(currentReport: OnyxEntry) { } } +function getMostRecentReportID(currentReport: OnyxEntry) { + const lastAccessedReportID = ReportUtils.findLastAccessedReport(false, false, undefined, currentReport?.reportID)?.reportID; + return lastAccessedReportID ?? conciergeChatReportID; +} + function joinRoom(report: OnyxEntry) { if (!report) { return; @@ -4031,6 +4036,7 @@ export { showReportActionNotification, toggleEmojiReaction, shouldShowReportActionNotification, + getMostRecentReportID, joinRoom, leaveRoom, inviteToRoom, diff --git a/src/libs/actions/Task.ts b/src/libs/actions/Task.ts index 771788cec983..81e6beea4486 100644 --- a/src/libs/actions/Task.ts +++ b/src/libs/actions/Task.ts @@ -1056,7 +1056,13 @@ function deleteTask(report: OnyxEntry) { Report.notifyNewAction(report.reportID, currentUserAccountID); if (shouldDeleteTaskReport) { - return ROUTES.REPORT_WITH_ID.getRoute(parentReport?.reportID ?? '-1'); + if (parentReport?.reportID) { + return ROUTES.REPORT_WITH_ID.getRoute(parentReport.reportID); + } + const mostRecentReportID = Report.getMostRecentReportID(report); + if (mostRecentReportID) { + return ROUTES.REPORT_WITH_ID.getRoute(mostRecentReportID); + } } }