From c2a0f5cd82f2b97a76a5ba5e8bfa900dca019f8e Mon Sep 17 00:00:00 2001 From: cretadn22 Date: Fri, 2 Jan 2026 00:25:55 +0700 Subject: [PATCH 1/4] keep-reportID-in-send-invoice --- src/libs/actions/IOU/index.ts | 7 ++++++- src/pages/iou/request/step/IOURequestStepConfirmation.tsx | 2 ++ src/pages/iou/request/step/IOURequestStepParticipants.tsx | 2 +- 3 files changed, 9 insertions(+), 2 deletions(-) diff --git a/src/libs/actions/IOU/index.ts b/src/libs/actions/IOU/index.ts index 81388aa9074e6..583e68256fcfd 100644 --- a/src/libs/actions/IOU/index.ts +++ b/src/libs/actions/IOU/index.ts @@ -3360,6 +3360,7 @@ type SendInvoiceOptions = { currentUserAccountID: number; policyRecentlyUsedCurrencies: string[]; invoiceChatReport?: OnyxEntry; + invoiceChatReportID?: string; receiptFile?: Receipt; policy?: OnyxEntry; policyTagList?: OnyxEntry; @@ -3375,6 +3376,7 @@ function getSendInvoiceInformation({ currentUserAccountID, policyRecentlyUsedCurrencies, invoiceChatReport, + invoiceChatReportID, receiptFile, policy, policyTagList, @@ -3400,12 +3402,13 @@ function getSendInvoiceInformation({ if (!chatReport) { isNewChatReport = true; chatReport = buildOptimisticChatReport({ + optimisticReportID: invoiceChatReportID, participantList: [receiverAccountID, currentUserAccountID], chatType: CONST.REPORT.CHAT_TYPE.INVOICE, policyID: senderWorkspaceID, }); } - + // STEP 2: Create a new optimistic invoice report. const optimisticInvoiceReport = buildOptimisticInvoiceReport( chatReport.reportID, @@ -6701,6 +6704,7 @@ function sendInvoice({ transaction, policyRecentlyUsedCurrencies, invoiceChatReport, + invoiceChatReportID, receiptFile, policy, policyTagList, @@ -6732,6 +6736,7 @@ function sendInvoice({ currentUserAccountID, policyRecentlyUsedCurrencies, invoiceChatReport, + invoiceChatReportID, receiptFile, policy, policyTagList, diff --git a/src/pages/iou/request/step/IOURequestStepConfirmation.tsx b/src/pages/iou/request/step/IOURequestStepConfirmation.tsx index 2b39a1ab2e5f9..61e0c67bba620 100644 --- a/src/pages/iou/request/step/IOURequestStepConfirmation.tsx +++ b/src/pages/iou/request/step/IOURequestStepConfirmation.tsx @@ -983,12 +983,14 @@ function IOURequestStepConfirmation({ if (iouType === CONST.IOU.TYPE.INVOICE) { const invoiceChatReport = !isEmptyObject(report) && report?.reportID && doesReportReceiverMatchParticipant(report, receiverParticipantAccountID) ? report : existingInvoiceReport; + const invoiceChatReportID = invoiceChatReport ? undefined : reportID; sendInvoice({ currentUserAccountID: currentUserPersonalDetails.accountID, transaction, policyRecentlyUsedCurrencies: policyRecentlyUsedCurrencies ?? [], invoiceChatReport, + invoiceChatReportID, receiptFile: currentTransactionReceiptFile, policy, policyTagList: policyTags, diff --git a/src/pages/iou/request/step/IOURequestStepParticipants.tsx b/src/pages/iou/request/step/IOURequestStepParticipants.tsx index 60a15a275e8f4..96612a81d71eb 100644 --- a/src/pages/iou/request/step/IOURequestStepParticipants.tsx +++ b/src/pages/iou/request/step/IOURequestStepParticipants.tsx @@ -241,7 +241,7 @@ function IOURequestStepParticipants({ const firstParticipantReportID = val.at(0)?.reportID; const isPolicyExpenseChat = !!firstParticipant?.isPolicyExpenseChat; const policy = isPolicyExpenseChat && firstParticipant?.policyID ? allPolicies?.[`${ONYXKEYS.COLLECTION.POLICY}${firstParticipant.policyID}`] : undefined; - const isInvoice = iouType === CONST.IOU.TYPE.INVOICE && isInvoiceRoomWithID(firstParticipantReportID); + const isInvoice = iouType === CONST.IOU.TYPE.INVOICE && firstParticipant?.iouType === CONST.IOU.TYPE.INVOICE; numberOfParticipants.current = val.length; // Use transactions array if available, otherwise use initialTransactionID directly From 327f6573484fc285b61d4d04a32c1b6bc44f262f Mon Sep 17 00:00:00 2001 From: cretadn22 Date: Fri, 2 Jan 2026 00:40:31 +0700 Subject: [PATCH 2/4] remove import --- src/libs/actions/IOU/index.ts | 2 +- src/pages/iou/request/step/IOURequestStepParticipants.tsx | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/libs/actions/IOU/index.ts b/src/libs/actions/IOU/index.ts index 583e68256fcfd..e02cec5c0720a 100644 --- a/src/libs/actions/IOU/index.ts +++ b/src/libs/actions/IOU/index.ts @@ -3408,7 +3408,7 @@ function getSendInvoiceInformation({ policyID: senderWorkspaceID, }); } - + // STEP 2: Create a new optimistic invoice report. const optimisticInvoiceReport = buildOptimisticInvoiceReport( chatReport.reportID, diff --git a/src/pages/iou/request/step/IOURequestStepParticipants.tsx b/src/pages/iou/request/step/IOURequestStepParticipants.tsx index 96612a81d71eb..899fb6370b568 100644 --- a/src/pages/iou/request/step/IOURequestStepParticipants.tsx +++ b/src/pages/iou/request/step/IOURequestStepParticipants.tsx @@ -18,7 +18,7 @@ import {isMovingTransactionFromTrackExpense as isMovingTransactionFromTrackExpen import Navigation from '@libs/Navigation/Navigation'; import Performance from '@libs/Performance'; import {isPaidGroupPolicy} from '@libs/PolicyUtils'; -import {findSelfDMReportID, generateReportID, isInvoiceRoomWithID} from '@libs/ReportUtils'; +import {findSelfDMReportID, generateReportID} from '@libs/ReportUtils'; import {shouldRestrictUserBillableActions} from '@libs/SubscriptionUtils'; import {endSpan} from '@libs/telemetry/activeSpans'; import {getRequestType, isCorporateCardTransaction, isPerDiemRequest} from '@libs/TransactionUtils'; From 3db4b5c334693c2498daa90308be3b537fa552bd Mon Sep 17 00:00:00 2001 From: cretadn22 Date: Tue, 6 Jan 2026 19:42:42 +0700 Subject: [PATCH 3/4] fix: Update selectedReportID logic to check for invoice room ID before generating a new report ID --- src/pages/iou/request/step/IOURequestStepParticipants.tsx | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/pages/iou/request/step/IOURequestStepParticipants.tsx b/src/pages/iou/request/step/IOURequestStepParticipants.tsx index 899fb6370b568..f88ef2fa91a17 100644 --- a/src/pages/iou/request/step/IOURequestStepParticipants.tsx +++ b/src/pages/iou/request/step/IOURequestStepParticipants.tsx @@ -18,7 +18,7 @@ import {isMovingTransactionFromTrackExpense as isMovingTransactionFromTrackExpen import Navigation from '@libs/Navigation/Navigation'; import Performance from '@libs/Performance'; import {isPaidGroupPolicy} from '@libs/PolicyUtils'; -import {findSelfDMReportID, generateReportID} from '@libs/ReportUtils'; +import {findSelfDMReportID, generateReportID, isInvoiceRoomWithID} from '@libs/ReportUtils'; import {shouldRestrictUserBillableActions} from '@libs/SubscriptionUtils'; import {endSpan} from '@libs/telemetry/activeSpans'; import {getRequestType, isCorporateCardTransaction, isPerDiemRequest} from '@libs/TransactionUtils'; @@ -285,7 +285,7 @@ function IOURequestStepParticipants({ // When a participant is selected, the reportID needs to be saved because that's the reportID that will be used in the confirmation step. // We use || to be sure that if the first participant doesn't have a reportID, we generate a new one. // eslint-disable-next-line @typescript-eslint/prefer-nullish-coalescing - selectedReportID.current = firstParticipantReportID || generateReportID(); + selectedReportID.current = (firstParticipantReportID && isInvoiceRoomWithID(firstParticipantReportID)) ? firstParticipantReportID : generateReportID(); // IOUs are always reported. non-CREATE actions require a report if (!isPolicyExpenseChat || action !== CONST.IOU.ACTION.CREATE) { From 9d8c7893cc057fee1c3fab7e23dc386da8b08ef2 Mon Sep 17 00:00:00 2001 From: cretadn22 Date: Tue, 6 Jan 2026 19:46:31 +0700 Subject: [PATCH 4/4] feat: Add reportID prop to IOURequestStepConfirmation and refine selectedReportID logic --- src/pages/iou/request/step/IOURequestStepConfirmation.tsx | 1 + src/pages/iou/request/step/IOURequestStepParticipants.tsx | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/src/pages/iou/request/step/IOURequestStepConfirmation.tsx b/src/pages/iou/request/step/IOURequestStepConfirmation.tsx index 182a087cc4e26..00746dbe3b589 100644 --- a/src/pages/iou/request/step/IOURequestStepConfirmation.tsx +++ b/src/pages/iou/request/step/IOURequestStepConfirmation.tsx @@ -1126,6 +1126,7 @@ function IOURequestStepConfirmation({ userLocation, submitPerDiemExpense, policyRecentlyUsedCurrencies, + reportID, ], ); diff --git a/src/pages/iou/request/step/IOURequestStepParticipants.tsx b/src/pages/iou/request/step/IOURequestStepParticipants.tsx index f88ef2fa91a17..799448e84d38c 100644 --- a/src/pages/iou/request/step/IOURequestStepParticipants.tsx +++ b/src/pages/iou/request/step/IOURequestStepParticipants.tsx @@ -285,7 +285,7 @@ function IOURequestStepParticipants({ // When a participant is selected, the reportID needs to be saved because that's the reportID that will be used in the confirmation step. // We use || to be sure that if the first participant doesn't have a reportID, we generate a new one. // eslint-disable-next-line @typescript-eslint/prefer-nullish-coalescing - selectedReportID.current = (firstParticipantReportID && isInvoiceRoomWithID(firstParticipantReportID)) ? firstParticipantReportID : generateReportID(); + selectedReportID.current = firstParticipantReportID && isInvoiceRoomWithID(firstParticipantReportID) ? firstParticipantReportID : generateReportID(); // IOUs are always reported. non-CREATE actions require a report if (!isPolicyExpenseChat || action !== CONST.IOU.ACTION.CREATE) {