diff --git a/src/components/SelectionList/Search/ReportListItem.tsx b/src/components/SelectionList/Search/ReportListItem.tsx index d6ade86c5c06..cc5605cb1562 100644 --- a/src/components/SelectionList/Search/ReportListItem.tsx +++ b/src/components/SelectionList/Search/ReportListItem.tsx @@ -9,7 +9,9 @@ import useLocalize from '@hooks/useLocalize'; import usePermissions from '@hooks/usePermissions'; import useTheme from '@hooks/useTheme'; import useThemeStyles from '@hooks/useThemeStyles'; +import {updateSearchResultsWithTransactionThreadReportID} from '@libs/actions/Search'; import Navigation from '@libs/Navigation/Navigation'; +import {generateReportID} from '@libs/ReportUtils'; import variables from '@styles/variables'; import CONST from '@src/CONST'; import ONYXKEYS from '@src/ONYXKEYS'; @@ -28,6 +30,7 @@ function ReportListItem({ onFocus, onLongPressRow, shouldSyncFocus, + queryJSONHash, }: ReportListItemProps) { const reportItem = item as unknown as ReportListItemType; const theme = useTheme(); @@ -62,11 +65,27 @@ function ReportListItem({ const isFromSelfDM = transactionItem.reportID === CONST.REPORT.UNREPORTED_REPORT_ID; - const reportID = + let reportID = (!transactionItem.isFromOneTransactionReport || isFromSelfDM) && transactionItem.transactionThreadReportID !== CONST.REPORT.UNREPORTED_REPORT_ID ? transactionItem.transactionThreadReportID : transactionItem.reportID; + // If we're trying to open a legacy transaction without a transaction thread, let's create the thread and navigate the user + if (reportID === CONST.REPORT.UNREPORTED_REPORT_ID) { + reportID = generateReportID(); + if (queryJSONHash) { + updateSearchResultsWithTransactionThreadReportID(queryJSONHash, transactionItem.transactionID, reportID); + } + Navigation.navigate( + ROUTES.SEARCH_REPORT.getRoute({ + reportID, + backTo, + moneyRequestReportActionID: transactionItem.moneyRequestReportActionID, + transactionID: transactionItem.transactionID, + }), + ); + return; + } Navigation.navigate(ROUTES.SEARCH_REPORT.getRoute({reportID, backTo})); }; diff --git a/src/components/SelectionList/types.ts b/src/components/SelectionList/types.ts index 07a5ba64a923..9543252a4721 100644 --- a/src/components/SelectionList/types.ts +++ b/src/components/SelectionList/types.ts @@ -409,6 +409,8 @@ type TaskListItemProps = ListItemProps & { }; type ReportListItemProps = ListItemProps & { + queryJSONHash?: number; + /** Callback to fire when the item is pressed */ onSelectRow: (item: TItem, isOpenedAsReport?: boolean) => void; };