diff --git a/src/libs/actions/IOU/SendInvoice.ts b/src/libs/actions/IOU/SendInvoice.ts index dc3f9d285fef..7f4f9c34fc9f 100644 --- a/src/libs/actions/IOU/SendInvoice.ts +++ b/src/libs/actions/IOU/SendInvoice.ts @@ -57,6 +57,7 @@ type SendInvoiceOptions = { currentUserAccountID: number; policyRecentlyUsedCurrencies: string[]; invoiceChatReport?: OnyxEntry; + invoiceChatReportID?: string; receiptFile?: Receipt; policy?: OnyxEntry; policyTagList?: OnyxEntry; @@ -522,6 +523,7 @@ function getSendInvoiceInformation({ currentUserAccountID, policyRecentlyUsedCurrencies, invoiceChatReport, + invoiceChatReportID, receiptFile, policy, policyTagList, @@ -548,6 +550,7 @@ function getSendInvoiceInformation({ if (!chatReport) { isNewChatReport = true; chatReport = buildOptimisticChatReport({ + optimisticReportID: invoiceChatReportID, participantList: [receiverAccountID, currentUserAccountID], chatType: CONST.REPORT.CHAT_TYPE.INVOICE, policyID: senderWorkspaceID, @@ -671,6 +674,7 @@ function sendInvoice({ policy, policyTagList, policyCategories, + invoiceChatReportID, companyName, companyWebsite, policyRecentlyUsedCategories, @@ -698,6 +702,7 @@ function sendInvoice({ transaction, currentUserAccountID, policyRecentlyUsedCurrencies, + invoiceChatReportID, invoiceChatReport, receiptFile, policy, diff --git a/src/pages/iou/request/step/IOURequestStepConfirmation.tsx b/src/pages/iou/request/step/IOURequestStepConfirmation.tsx index e9ca980e28df..00746dbe3b58 100644 --- a/src/pages/iou/request/step/IOURequestStepConfirmation.tsx +++ b/src/pages/iou/request/step/IOURequestStepConfirmation.tsx @@ -995,12 +995,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, @@ -1124,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 60a15a275e8f..799448e84d38 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 @@ -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) {