diff --git a/src/components/ReportActionItem/MoneyRequestPreview/MoneyRequestPreviewContent.tsx b/src/components/ReportActionItem/MoneyRequestPreview/MoneyRequestPreviewContent.tsx index ac61cb74d229..6ab1c0937278 100644 --- a/src/components/ReportActionItem/MoneyRequestPreview/MoneyRequestPreviewContent.tsx +++ b/src/components/ReportActionItem/MoneyRequestPreview/MoneyRequestPreviewContent.tsx @@ -116,14 +116,15 @@ function MoneyRequestPreviewContent({ const isFetchingWaypointsFromServer = TransactionUtils.isFetchingWaypointsFromServer(transaction); const isCardTransaction = TransactionUtils.isCardTransaction(transaction); const isSettled = ReportUtils.isSettled(iouReport?.reportID); + const isApproved = ReportUtils.isReportApproved(iouReport); const isDeleted = action?.pendingAction === CONST.RED_BRICK_ROAD_PENDING_ACTION.DELETE; const isReviewDuplicateTransactionPage = route.name === SCREENS.TRANSACTION_DUPLICATE.REVIEW; const isFullySettled = isSettled && !isSettlementOrApprovalPartial; - const isFullyApproved = ReportUtils.isReportApproved(iouReport) && !isSettlementOrApprovalPartial; + const isFullyApproved = isApproved && !isSettlementOrApprovalPartial; // Get transaction violations for given transaction id from onyx, find duplicated transactions violations and get duplicates - const duplicates = useMemo( + const allDuplicates = useMemo( () => transactionViolations?.[`${ONYXKEYS.COLLECTION.TRANSACTION_VIOLATIONS}${transaction?.transactionID}`]?.find( (violation) => violation.name === CONST.VIOLATIONS.DUPLICATED_TRANSACTION, @@ -131,6 +132,12 @@ function MoneyRequestPreviewContent({ [transaction?.transactionID, transactionViolations], ); + // Remove settled transactions from duplicates + const duplicates = useMemo(() => TransactionUtils.removeSettledAndApprovedTransactions(allDuplicates), [allDuplicates]); + + // When there are no settled transactions in duplicates, show the "Keep this one" button + const shouldShowKeepButton = allDuplicates.length === duplicates.length; + const hasDuplicates = duplicates.length > 0; const shouldShowRBR = hasNoticeTypeViolations || hasViolations || hasFieldErrors || (!isFullySettled && !isFullyApproved && isOnHold) || hasDuplicates; @@ -437,7 +444,7 @@ function MoneyRequestPreviewContent({ ]} > {childContainer} - {isReviewDuplicateTransactionPage && ( + {isReviewDuplicateTransactionPage && !isSettled && !isApproved && shouldShowKeepButton && (