From e0a3b8fc2ef91906b75455ccb5b5554815f3a0d1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Frane=20Poli=C4=87?= <16856471+fPolic@users.noreply.github.com> Date: Wed, 28 Aug 2024 08:44:22 +0200 Subject: [PATCH] feat(dashboard): summary shipping breakdown (#8779) **What** - display a shipping costs breakdown in the order summary - allow to receive only non canceled returns - show how many items is actually received with return in the timeline **Question** - should we display the shipping total somewhere as well --- CLOSES CC-356 --- .../order-activity-section/order-timeline.tsx | 6 ++- .../order-summary-section.tsx | 47 ++++++++++++------- 2 files changed, 33 insertions(+), 20 deletions(-) diff --git a/packages/admin-next/dashboard/src/routes/orders/order-detail/components/order-activity-section/order-timeline.tsx b/packages/admin-next/dashboard/src/routes/orders/order-detail/components/order-activity-section/order-timeline.tsx index 49ff3fb79f..4414be791d 100644 --- a/packages/admin-next/dashboard/src/routes/orders/order-detail/components/order-activity-section/order-timeline.tsx +++ b/packages/admin-next/dashboard/src/routes/orders/order-detail/components/order-activity-section/order-timeline.tsx @@ -242,7 +242,7 @@ const useActivityItems = (order: AdminOrder) => { returnId: ret.id.slice(-7), }), timestamp: ret.received_at, - children: , + children: , }) } } @@ -498,9 +498,11 @@ const FulfillmentCreatedBody = ({ const ReturnBody = ({ orderReturn, isCreated, + isReceived, }: { orderReturn: AdminReturn isCreated: boolean + isReceived?: boolean }) => { const prompt = usePrompt() const { t } = useTranslation() @@ -526,7 +528,7 @@ const ReturnBody = ({ } const numberOfItems = orderReturn.items.reduce((acc, item) => { - return acc + item.quantity + return acc + (isReceived ? item.received_quantity : item.quantity) // TODO: revisit when we add dismissed quantity on ReturnItem }, 0) return ( diff --git a/packages/admin-next/dashboard/src/routes/orders/order-detail/components/order-summary-section/order-summary-section.tsx b/packages/admin-next/dashboard/src/routes/orders/order-detail/components/order-summary-section/order-summary-section.tsx index 526c9cca94..d2d55ca3f9 100644 --- a/packages/admin-next/dashboard/src/routes/orders/order-detail/components/order-summary-section/order-summary-section.tsx +++ b/packages/admin-next/dashboard/src/routes/orders/order-detail/components/order-summary-section/order-summary-section.tsx @@ -35,23 +35,23 @@ import { import { AdminPaymentCollection } from "../../../../../../../../core/types/dist/http/payment/admin/entities" import { ActionMenu } from "../../../../../components/common/action-menu" -import { ButtonMenu } from "../../../../../components/common/button-menu/button-menu.tsx" +import { ButtonMenu } from "../../../../../components/common/button-menu/button-menu" import { Thumbnail } from "../../../../../components/common/thumbnail" -import { useClaims } from "../../../../../hooks/api/claims.tsx" -import { useExchanges } from "../../../../../hooks/api/exchanges.tsx" -import { useOrderPreview } from "../../../../../hooks/api/orders.tsx" -import { useMarkPaymentCollectionAsPaid } from "../../../../../hooks/api/payment-collections.tsx" +import { useClaims } from "../../../../../hooks/api/claims" +import { useExchanges } from "../../../../../hooks/api/exchanges" +import { useOrderPreview } from "../../../../../hooks/api/orders" +import { useMarkPaymentCollectionAsPaid } from "../../../../../hooks/api/payment-collections" import { useReservationItems } from "../../../../../hooks/api/reservations" import { useReturns } from "../../../../../hooks/api/returns" import { useDate } from "../../../../../hooks/use-date" -import { formatCurrency } from "../../../../../lib/format-currency.ts" +import { formatCurrency } from "../../../../../lib/format-currency" import { getLocaleAmount, getStylizedAmount, } from "../../../../../lib/money-amount-helpers" -import { getTotalCaptured } from "../../../../../lib/payment.ts" -import { getReturnableQuantity } from "../../../../../lib/rma.ts" -import { CopyPaymentLink } from "../copy-payment-link/copy-payment-link.tsx" +import { getTotalCaptured } from "../../../../../lib/payment" +import { getReturnableQuantity } from "../../../../../lib/rma" +import { CopyPaymentLink } from "../copy-payment-link/copy-payment-link" type OrderSummarySectionProps = { order: AdminOrder @@ -77,7 +77,12 @@ export const OrderSummarySection = ({ order }: OrderSummarySectionProps) => { fields: "+received_at", }) - const showReturns = !!returns.length + const receivableReturns = useMemo( + () => returns.filter((r) => !r.canceled_at), + [returns] + ) + + const showReturns = !!receivableReturns.length /** * Show Allocation button only if there are unfulfilled items that don't have reservations @@ -170,11 +175,11 @@ export const OrderSummarySection = ({ order }: OrderSummarySectionProps) => { {(showAllocateButton || showReturns || showPayment || showRefund) && (
{showReturns && - (returns.length === 1 ? ( + (receivableReturns.length === 1 ? (
) }