diff --git a/src/libs/ReportUtils.ts b/src/libs/ReportUtils.ts index 568ce49ff961..467cedddbb93 100644 --- a/src/libs/ReportUtils.ts +++ b/src/libs/ReportUtils.ts @@ -2269,13 +2269,15 @@ function getReportPreviewMessage( }); } + let linkedTransaction; if (!isEmptyObject(reportAction) && shouldConsiderReceiptBeingScanned && reportAction && ReportActionsUtils.isMoneyRequestAction(reportAction)) { - const linkedTransaction = TransactionUtils.getLinkedTransaction(reportAction); + linkedTransaction = TransactionUtils.getLinkedTransaction(reportAction); + } - if (!isEmptyObject(linkedTransaction) && TransactionUtils.hasReceipt(linkedTransaction) && TransactionUtils.isReceiptBeingScanned(linkedTransaction)) { - return Localize.translateLocal('iou.receiptScanning'); - } + if (!isEmptyObject(linkedTransaction) && TransactionUtils.hasReceipt(linkedTransaction) && TransactionUtils.isReceiptBeingScanned(linkedTransaction)) { + return Localize.translateLocal('iou.receiptScanning'); } + const originalMessage = reportAction?.originalMessage as IOUMessage | undefined; // Show Paid preview message if it's settled or if the amount is paid & stuck at receivers end for only chat reports. @@ -2302,14 +2304,17 @@ function getReportPreviewMessage( return Localize.translateLocal('iou.waitingOnBankAccount', {submitterDisplayName}); } - const containsNonReimbursable = hasNonReimbursableTransactions(report.reportID); - const lastActorID = reportAction?.actorAccountID; + let amount = originalMessage?.amount; + let currency = originalMessage?.currency ? originalMessage?.currency : report.currency; + + if (!isEmptyObject(linkedTransaction)) { + amount = TransactionUtils.getAmount(linkedTransaction, isExpenseReport(report)); + currency = TransactionUtils.getCurrency(linkedTransaction); + } // if we have the amount in the originalMessage and lastActorID, we can use that to display the preview message for the latest request - if (originalMessage?.amount !== undefined && lastActorID && !isPreviewMessageForParentChatReport) { - const amount = originalMessage?.amount; - const currency = originalMessage?.currency ?? report.currency ?? ''; + if (amount !== undefined && lastActorID && !isPreviewMessageForParentChatReport) { const amountToDisplay = CurrencyUtils.convertToDisplayString(Math.abs(amount), currency); // We only want to show the actor name in the preview if it's not the current user who took the action @@ -2317,6 +2322,8 @@ function getReportPreviewMessage( return `${requestorName ? `${requestorName}: ` : ''}${Localize.translateLocal('iou.requestedAmount', {formattedAmount: amountToDisplay})}`; } + const containsNonReimbursable = hasNonReimbursableTransactions(report.reportID); + return Localize.translateLocal(containsNonReimbursable ? 'iou.payerSpentAmount' : 'iou.payerOwesAmount', {payer: payerName ?? '', amount: formattedAmount}); } @@ -4590,6 +4597,7 @@ function getRoom(type: ValueOf, policyID: string) function shouldDisableWelcomeMessage(report: OnyxEntry, policy: OnyxEntry): boolean { return isMoneyRequestReport(report) || isArchivedRoom(report) || !isChatRoom(report) || isChatThread(report) || !PolicyUtils.isPolicyAdmin(policy); } + /** * Checks if report action has error when smart scanning */