From 1416897ee1ef4900c794fa8a39300ad832801933 Mon Sep 17 00:00:00 2001 From: Krishna Gupta Date: Fri, 29 Mar 2024 14:50:32 +0530 Subject: [PATCH 1/2] fix: Description/Merchant does not show in request preview. Signed-off-by: Krishna Gupta --- src/components/ReportActionItem/ReportPreview.tsx | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/src/components/ReportActionItem/ReportPreview.tsx b/src/components/ReportActionItem/ReportPreview.tsx index 8b95474bf2fc..33ce01212b2f 100644 --- a/src/components/ReportActionItem/ReportPreview.tsx +++ b/src/components/ReportActionItem/ReportPreview.tsx @@ -127,6 +127,7 @@ function ReportPreview({ const isApproved = ReportUtils.isReportApproved(iouReport); const canAllowSettlement = ReportUtils.hasUpdatedTotal(iouReport); + const allTransactions = TransactionUtils.getAllReportTransactions(iouReportID); const transactionsWithReceipts = ReportUtils.getTransactionsWithReceipts(iouReportID); const numberOfScanningReceipts = transactionsWithReceipts.filter((transaction) => TransactionUtils.isReceiptBeingScanned(transaction)).length; const numberOfPendingRequests = transactionsWithReceipts.filter((transaction) => TransactionUtils.isPending(transaction) && TransactionUtils.isCardTransaction(transaction)).length; @@ -138,14 +139,16 @@ function ReportPreview({ const lastThreeTransactionsWithReceipts = transactionsWithReceipts.slice(-3); const lastThreeReceipts = lastThreeTransactionsWithReceipts.map((transaction) => ReceiptUtils.getThumbnailAndImageURIs(transaction)); - let formattedMerchant = numberOfRequests === 1 && hasReceipts ? TransactionUtils.getMerchant(transactionsWithReceipts[0]) : null; + let formattedMerchant = numberOfRequests === 1 ? TransactionUtils.getMerchant(allTransactions[0]) : null; + const formattedDescription = numberOfRequests === 1 ? TransactionUtils.getDescription(allTransactions[0]) : null; + if (TransactionUtils.isPartialMerchant(formattedMerchant ?? '')) { formattedMerchant = null; } const previewSubtitle = // Formatted merchant can be an empty string // eslint-disable-next-line @typescript-eslint/prefer-nullish-coalescing - formattedMerchant || + (formattedMerchant ?? formattedDescription) || translate('iou.requestCount', { count: numberOfRequests - numberOfScanningReceipts - numberOfPendingRequests, scanningReceipts: numberOfScanningReceipts, @@ -228,7 +231,8 @@ function ReportPreview({ In this case, we don't want to show the merchant because it says: "Pending route...", which is already displayed in the amount field. */ const shouldShowSingleRequestMerchant = numberOfRequests === 1 && !!formattedMerchant && !(hasOnlyTransactionsWithPendingRoutes && !totalDisplaySpend); - const shouldShowSubtitle = !isScanning && (shouldShowSingleRequestMerchant || numberOfRequests > 1); + const shouldShowSingleRequestDescription = numberOfRequests === 1 && !!formattedDescription && !shouldShowSingleRequestMerchant; + const shouldShowSubtitle = !isScanning && (shouldShowSingleRequestMerchant || shouldShowSingleRequestDescription || numberOfRequests > 1); return ( Date: Sat, 30 Mar 2024 04:56:38 +0530 Subject: [PATCH 2/2] update according to suggestions. Signed-off-by: Krishna Gupta --- src/components/ReportActionItem/ReportPreview.tsx | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/components/ReportActionItem/ReportPreview.tsx b/src/components/ReportActionItem/ReportPreview.tsx index 33ce01212b2f..2581359b4543 100644 --- a/src/components/ReportActionItem/ReportPreview.tsx +++ b/src/components/ReportActionItem/ReportPreview.tsx @@ -225,14 +225,14 @@ function ReportPreview({ /* Show subtitle if at least one of the money requests is not being smart scanned, and either: - There is more than one money request – in this case, the "X requests, Y scanning" subtitle is shown; - - There is only one money request, it has a receipt and is not being smart scanned – in this case, the request merchant is shown; + - There is only one money request, it has a receipt and is not being smart scanned – in this case, the request merchant or description is shown; * There is an edge case when there is only one distance request with a pending route and amount = 0. - In this case, we don't want to show the merchant because it says: "Pending route...", which is already displayed in the amount field. + In this case, we don't want to show the merchant or description because it says: "Pending route...", which is already displayed in the amount field. */ - const shouldShowSingleRequestMerchant = numberOfRequests === 1 && !!formattedMerchant && !(hasOnlyTransactionsWithPendingRoutes && !totalDisplaySpend); - const shouldShowSingleRequestDescription = numberOfRequests === 1 && !!formattedDescription && !shouldShowSingleRequestMerchant; - const shouldShowSubtitle = !isScanning && (shouldShowSingleRequestMerchant || shouldShowSingleRequestDescription || numberOfRequests > 1); + const shouldShowSingleRequestMerchantOrDescription = + numberOfRequests === 1 && (!!formattedMerchant || !!formattedDescription) && !(hasOnlyTransactionsWithPendingRoutes && !totalDisplaySpend); + const shouldShowSubtitle = !isScanning && (shouldShowSingleRequestMerchantOrDescription || numberOfRequests > 1); return (