diff --git a/src/libs/ReportUtils.ts b/src/libs/ReportUtils.ts index 39fe12ee1ab1..e653d79a7479 100644 --- a/src/libs/ReportUtils.ts +++ b/src/libs/ReportUtils.ts @@ -3983,15 +3983,26 @@ function getAddWorkspaceRoomOrChatReportErrors(report: OnyxEntry): Recor return report?.errorFields?.addWorkspaceRoom ?? report?.errorFields?.createChat; } +/** + * Return true if the Money Request report is marked for deletion. + */ +function isMoneyRequestReportPendingDeletion(report: OnyxEntry): boolean { + if (!isMoneyRequestReport(report)) { + return false; + } + + const parentReportAction = ReportActionsUtils.getReportAction(report?.parentReportID ?? '', report?.parentReportActionID ?? ''); + return parentReportAction?.pendingAction === CONST.RED_BRICK_ROAD_PENDING_ACTION.DELETE; +} + function canUserPerformWriteAction(report: OnyxEntry) { const reportErrors = getAddWorkspaceRoomOrChatReportErrors(report); + // If the Money Request report is marked for deletion, let us prevent any further write action. - if (isMoneyRequestReport(report)) { - const parentReportAction = ReportActionsUtils.getReportAction(report?.parentReportID ?? '', report?.parentReportActionID ?? ''); - if (parentReportAction?.pendingAction === CONST.RED_BRICK_ROAD_PENDING_ACTION.DELETE) { - return false; - } + if (isMoneyRequestReportPendingDeletion(report)) { + return false; } + return !isArchivedRoom(report) && isEmptyObject(reportErrors) && report && isAllowedToComment(report) && !isAnonymousUser; } @@ -4567,6 +4578,7 @@ export { getParentReport, getRootParentReport, getReportPreviewMessage, + isMoneyRequestReportPendingDeletion, canUserPerformWriteAction, getOriginalReportID, canAccessReport, diff --git a/src/pages/home/ReportScreen.js b/src/pages/home/ReportScreen.js index b35d9240f3f7..70a0f1a236bb 100644 --- a/src/pages/home/ReportScreen.js +++ b/src/pages/home/ReportScreen.js @@ -393,6 +393,11 @@ function ReportScreen({ Navigation.goBack(ROUTES.HOME, false, true); } if (prevReport.parentReportID) { + // Prevent navigation to the Money Request Report if it is pending deletion. + const parentReport = ReportUtils.getReport(prevReport.parentReportID); + if (ReportUtils.isMoneyRequestReportPendingDeletion(parentReport)) { + return; + } Navigation.navigate(ROUTES.REPORT_WITH_ID.getRoute(prevReport.parentReportID)); return; }