diff --git a/src/libs/ReportUtils.ts b/src/libs/ReportUtils.ts index 8296e38411be..f31ea72884d8 100644 --- a/src/libs/ReportUtils.ts +++ b/src/libs/ReportUtils.ts @@ -1275,7 +1275,7 @@ function isMoneyRequestReport(reportOrID: OnyxEntry | EmptyObject | stri * Checks if a report has only one transaction associated with it */ function isOneTransactionReport(reportID: string): boolean { - const reportActions = reportActionsByReport?.[`${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${reportID}`] ?? ([] as ReportAction[]); + const reportActions = reportActionsByReport?.[reportID] ?? ([] as ReportAction[]); return ReportActionsUtils.getOneTransactionThreadReportID(reportActions) !== null; } @@ -4984,7 +4984,12 @@ function canUserPerformWriteAction(report: OnyxEntry) { * Returns ID of the original report from which the given reportAction is first created. */ function getOriginalReportID(reportID: string, reportAction: OnyxEntry): string | undefined { - const currentReportAction = ReportActionsUtils.getReportAction(reportID, reportAction?.reportActionID ?? ''); + const reportActions = reportActionsByReport?.[reportID]; + const currentReportAction = reportActions?.[reportAction?.reportActionID ?? ''] ?? null; + const transactionThreadReportID = ReportActionsUtils.getOneTransactionThreadReportID(reportActions ?? ([] as ReportAction[])); + if (transactionThreadReportID !== null) { + return Object.keys(currentReportAction ?? {}).length === 0 ? transactionThreadReportID : reportID; + } return isThreadFirstChat(reportAction, reportID) && Object.keys(currentReportAction ?? {}).length === 0 ? allReports?.[`${ONYXKEYS.COLLECTION.REPORT}${reportID}`]?.parentReportID : reportID;