From bbe2c9f17f5999cdf15af39ebb04b1347a5e32fa Mon Sep 17 00:00:00 2001 From: Mohammad Luthfi Fathur Rahman Date: Wed, 8 Oct 2025 19:45:26 +0700 Subject: [PATCH 1/3] use selfDM report to create transaction thread for track expense --- src/libs/actions/Report.ts | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/src/libs/actions/Report.ts b/src/libs/actions/Report.ts index 1dd7db52af4..2d2e2c7dd7f 100644 --- a/src/libs/actions/Report.ts +++ b/src/libs/actions/Report.ts @@ -1382,12 +1382,25 @@ function getOptimisticChatReport(accountID: number): OptimisticChatReport { } function createTransactionThreadReport(iouReport: OnyxEntry, iouReportAction: OnyxEntry): OptimisticChatReport | undefined { - if (!iouReport || !iouReportAction) { - Log.warn('Cannot build transaction thread report without iouReport and iouReportAction parameters'); + if (!iouReportAction) { + Log.warn('Cannot build transaction thread report without iouReportAction parameter'); return; } + + let reportToUse = iouReport; + // For track expenses without iouReport, get the selfDM report + if (!iouReport && ReportActionsUtils.isTrackExpenseAction(iouReportAction)) { + const selfDMReportID = findSelfDMReportID(); + reportToUse = allReports?.[`${ONYXKEYS.COLLECTION.REPORT}${selfDMReportID}`]; + } + + if (!reportToUse) { + Log.warn('Cannot build transaction thread report without a valid report'); + return; + } + const optimisticTransactionThreadReportID = generateReportID(); - const optimisticTransactionThread = buildTransactionThread(iouReportAction, iouReport, undefined, optimisticTransactionThreadReportID); + const optimisticTransactionThread = buildTransactionThread(iouReportAction, reportToUse, undefined, optimisticTransactionThreadReportID); openReport(optimisticTransactionThreadReportID, undefined, currentUserEmail ? [currentUserEmail] : [], optimisticTransactionThread, iouReportAction?.reportActionID); return optimisticTransactionThread; } From 21a5d58f230845acab5d327a78528410ad4e7abf Mon Sep 17 00:00:00 2001 From: Mohammad Luthfi Fathur Rahman Date: Wed, 8 Oct 2025 19:45:49 +0700 Subject: [PATCH 2/3] try to create transaction thread report if it's not exist --- src/pages/home/report/PureReportActionItem.tsx | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/pages/home/report/PureReportActionItem.tsx b/src/pages/home/report/PureReportActionItem.tsx index f1e20920f31..702970e7588 100644 --- a/src/pages/home/report/PureReportActionItem.tsx +++ b/src/pages/home/report/PureReportActionItem.tsx @@ -166,7 +166,7 @@ import variables from '@styles/variables'; import {openPersonalBankAccountSetupView} from '@userActions/BankAccounts'; import {hideEmojiPicker, isActive} from '@userActions/EmojiPickerAction'; import {acceptJoinRequest, declineJoinRequest} from '@userActions/Policy/Member'; -import {expandURLPreview, resolveActionableMentionConfirmWhisper, resolveConciergeCategoryOptions} from '@userActions/Report'; +import {createTransactionThreadReport, expandURLPreview, resolveActionableMentionConfirmWhisper, resolveConciergeCategoryOptions} from '@userActions/Report'; import type {IgnoreDirection} from '@userActions/ReportActions'; import {isAnonymousUser, signOutAndRedirectToSignIn} from '@userActions/Session'; import {isBlockedFromConcierge} from '@userActions/User'; @@ -997,7 +997,13 @@ function PureReportActionItem({ return; } + // If no childReportID exists, create transaction thread on-demand if (!action.childReportID) { + const createdTransactionThreadReport = createTransactionThreadReport(iouReport, action); + if (createdTransactionThreadReport?.reportID) { + Navigation.navigate(ROUTES.REPORT_WITH_ID.getRoute(createdTransactionThreadReport.reportID, undefined, undefined, Navigation.getActiveRoute())); + return; + } return; } From 03c9fa7a09dfa28f7f3665df84b8d2cbcf375942 Mon Sep 17 00:00:00 2001 From: Mohammad Luthfi Fathur Rahman Date: Wed, 8 Oct 2025 20:09:23 +0700 Subject: [PATCH 3/3] fix prettier --- src/libs/actions/Report.ts | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/libs/actions/Report.ts b/src/libs/actions/Report.ts index 2d2e2c7dd7f..a7bd0bf34bf 100644 --- a/src/libs/actions/Report.ts +++ b/src/libs/actions/Report.ts @@ -1386,19 +1386,19 @@ function createTransactionThreadReport(iouReport: OnyxEntry, iouReportAc Log.warn('Cannot build transaction thread report without iouReportAction parameter'); return; } - + let reportToUse = iouReport; // For track expenses without iouReport, get the selfDM report if (!iouReport && ReportActionsUtils.isTrackExpenseAction(iouReportAction)) { const selfDMReportID = findSelfDMReportID(); reportToUse = allReports?.[`${ONYXKEYS.COLLECTION.REPORT}${selfDMReportID}`]; } - + if (!reportToUse) { Log.warn('Cannot build transaction thread report without a valid report'); return; } - + const optimisticTransactionThreadReportID = generateReportID(); const optimisticTransactionThread = buildTransactionThread(iouReportAction, reportToUse, undefined, optimisticTransactionThreadReportID); openReport(optimisticTransactionThreadReportID, undefined, currentUserEmail ? [currentUserEmail] : [], optimisticTransactionThread, iouReportAction?.reportActionID);