diff --git a/src/libs/ReportUtils.ts b/src/libs/ReportUtils.ts index 769832747c41..1a6f17c3e89a 100644 --- a/src/libs/ReportUtils.ts +++ b/src/libs/ReportUtils.ts @@ -5639,12 +5639,14 @@ 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 { +function getOriginalReportID(reportID: string, reportAction: OnyxEntry, shouldReturnTransactionThread = false): string | undefined { const reportActions = allReportActions?.[`${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${reportID}`]; const currentReportAction = reportActions?.[reportAction?.reportActionID ?? ''] ?? null; - const transactionThreadReportID = ReportActionsUtils.getOneTransactionThreadReportID(reportID, reportActions ?? ([] as ReportAction[])); - if (transactionThreadReportID !== null) { - return Object.keys(currentReportAction ?? {}).length === 0 ? transactionThreadReportID : reportID; + if (shouldReturnTransactionThread) { + const transactionThreadReportID = ReportActionsUtils.getOneTransactionThreadReportID(reportID, 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 diff --git a/src/libs/actions/ReportActions.ts b/src/libs/actions/ReportActions.ts index 217dd0b12100..5f173ac3df79 100644 --- a/src/libs/actions/ReportActions.ts +++ b/src/libs/actions/ReportActions.ts @@ -11,7 +11,7 @@ import * as Report from './Report'; type IgnoreDirection = 'parent' | 'child'; function clearReportActionErrors(reportID: string, reportAction: ReportAction, keys?: string[]) { - const originalReportID = ReportUtils.getOriginalReportID(reportID, reportAction); + const originalReportID = ReportUtils.getOriginalReportID(reportID, reportAction, true); if (!reportAction?.reportActionID) { return; diff --git a/src/pages/home/report/ContextMenu/ContextMenuActions.tsx b/src/pages/home/report/ContextMenu/ContextMenuActions.tsx index 013bc484fc63..2bba9dee8fa3 100644 --- a/src/pages/home/report/ContextMenu/ContextMenuActions.tsx +++ b/src/pages/home/report/ContextMenu/ContextMenuActions.tsx @@ -398,7 +398,7 @@ const ContextMenuActions: ContextMenuAction[] = [ onPress: (closePopover, {reportAction, reportID}) => { Environment.getEnvironmentURL().then((environmentURL) => { const reportActionID = reportAction?.reportActionID; - Clipboard.setString(`${environmentURL}/r/${reportID}/${reportActionID}`); + Clipboard.setString(`${environmentURL}/r/${ReportUtils.getOriginalReportID(reportID, reportAction)}/${reportActionID}`); }); hideContextMenu(true, ReportActionComposeFocusManager.focus); },