Skip to content

The complete open source platform to run your entire marketplace. Storefront, vendor panel, admin console, and integrations in one enterprise-grade platform you own.

fix(vendor): align order refund UI with design (#1198)

Viktor Holikb8f3f65da7a2
diff --git a/packages/admin/src/extension-targets.d.ts b/packages/admin/src/extension-targets.d.ts
index e0779735c..740c7d2d0 100644
--- a/packages/admin/src/extension-targets.d.ts
+++ b/packages/admin/src/extension-targets.d.ts
@@ -232,7 +232,7 @@ declare module "@mercurjs/dashboard-sdk" {
"order": {
formZones: never
formTabs: Record<string, string>
- displayZones: "activity" | "commission" | "customer" | "general" | "order-group" | "payment" | "summary"
+ displayZones: "activity" | "customer" | "general" | "order-group" | "payment" | "summary"
displayFieldIds: "created_at" | "display_id" | "fulfillment_status" | "payment_status" | "status"
}
"price_list": {
diff --git a/packages/admin/src/pages/orders/order-detail/components/order-commission-section/index.ts b/packages/admin/src/pages/orders/order-detail/components/order-commission-section/index.ts
deleted file mode 100644
index f58f25fde..000000000
--- a/packages/admin/src/pages/orders/order-detail/components/order-commission-section/index.ts
+++ /dev/null
@@ -1 +0,0 @@
-export * from "./order-commission-section";
diff --git a/packages/admin/src/pages/orders/order-detail/components/order-commission-section/order-commission-section.tsx b/packages/admin/src/pages/orders/order-detail/components/order-commission-section/order-commission-section.tsx
deleted file mode 100644
index be59230a0..000000000
--- a/packages/admin/src/pages/orders/order-detail/components/order-commission-section/order-commission-section.tsx
+++ /dev/null
@@ -1,72 +0,0 @@
-import { getLocaleAmount } from "@lib/money-amount-helpers";
-import { useOrderCommissionLines } from "@hooks/api/orders";
-import type { AdminOrder } from "@medusajs/types";
-import { Container, Heading, Text } from "@medusajs/ui";
-import { DisplayExtensionZone } from "@mercurjs/dashboard-shared";
-import { useMemo } from "react";
-import { useTranslation } from "react-i18next";
-
-type OrderCommissionSectionProps = {
- order: AdminOrder;
-};
-
-export const OrderCommissionSection = ({
- order,
-}: OrderCommissionSectionProps) => {
- const { t } = useTranslation();
- const { commission_lines, isLoading } = useOrderCommissionLines(order.id);
-
- const itemTitleById = useMemo(() => {
- const map = new Map<string, string>();
- order.items?.forEach((item: any) => {
- map.set(item.id, item.product_title ?? item.title);
- });
- return map;
- }, [order.items]);
-
- if (isLoading || !commission_lines.length) {
- return null;
- }
-
- const total = commission_lines.reduce(
- (acc, line) => acc + (line.amount ?? 0),
- 0
- );
-
- return (
- <Container className="divide-y p-0" data-testid="order-commission-section">
- <div className="flex items-center justify-between px-6 py-4">
- <Heading level="h2">{t("fields.commission")}</Heading>
- </div>
- <div className="divide-y">
- {commission_lines.map((line) => {
- const label = line.shipping_method_id
- ? t("fields.shipping")
- : itemTitleById.get(line.item_id ?? "") ?? line.code;
- return (
- <div
- key={line.id}
- className="text-ui-fg-subtle grid grid-cols-2 items-center gap-4 px-6 py-4"
- >
- <Text size="small" leading="compact">
- {label}
- </Text>
- <Text size="small" leading="compact" className="text-right">
- {getLocaleAmount(line.amount, order.currency_code)}
- </Text>
- </div>
- );
- })}
- </div>
- <div className="flex items-center justify-between px-6 py-4">
- <Text size="small" weight="plus" leading="compact">
- {t("orders.commission.total")}
- </Text>
- <Text size="small" weight="plus" leading="compact">
- {getLocaleAmount(total, order.currency_code)}
- </Text>
- </div>
- <DisplayExtensionZone model="order" zone="commission" data={order} />
- </Container>
- );
-};
diff --git a/packages/admin/src/pages/orders/order-detail/components/order-summary-section/order-summary-section.tsx b/packages/admin/src/pages/orders/order-detail/components/order-summary-section/order-summary-section.tsx
index 6648f0a04..5502ff74f 100644
--- a/packages/admin/src/pages/orders/order-detail/components/order-summary-section/order-summary-section.tsx
+++ b/packages/admin/src/pages/orders/order-detail/components/order-summary-section/order-summary-section.tsx
@@ -43,7 +43,10 @@ import DisplayId from "../../../../../components/common/display-id/display-id.ts
import { Thumbnail } from "../../../../../components/common/thumbnail/index.ts";
import { useClaims } from "../../../../../hooks/api/claims.tsx";
import { useExchanges } from "../../../../../hooks/api/exchanges.tsx";
-import { useOrderPreview } from "../../../../../hooks/api/orders.tsx";
+import {
+ useOrderCommissionLines,
+ useOrderPreview,
+} from "../../../../../hooks/api/orders.tsx";
import { useMarkPaymentCollectionAsPaid } from "../../../../../hooks/api/payment-collections.tsx";
import { useReservationItems } from "../../../../../hooks/api/reservations.tsx";
import { useReturns } from "../../../../../hooks/api/returns.tsx";
@@ -522,6 +525,21 @@ const CostBreakdown = ({
const { t } = useTranslation();
const [isTaxOpen, setIsTaxOpen] = useState(false);
const [isShippingOpen, setIsShippingOpen] = useState(false);
+ const [isCommissionOpen, setIsCommissionOpen] = useState(false);
+
+ const { commission_lines } = useOrderCommissionLines(order.id);
+ const hasCommission = commission_lines.length > 0;
+ const commissionTotal = commission_lines.reduce(
+ (acc, line) => acc + (line.amount ?? 0),
+ 0
+ );
+ const commissionItemTitleById = useMemo(() => {
+ const map = new Map<string, string>();
+ order.items?.forEach((item) => {
+ map.set(item.id, item.product_title ?? item.title);
+ });
+ return map;
+ }, [order.items]);
const taxCodes = useMemo(() => {
const taxCodeMap: { [key: string]: { total: number; rate: number } } = {};
@@ -665,6 +683,59 @@ const CostBreakdown = ({
</div>
)}
</>
+
+ {hasCommission && (
+ <>
+ <div className="flex justify-between">
+ {/* oxlint-disable-next-line jsx-a11y/click-events-have-key-events, jsx-a11y/no-static-element-interactions */}
+ <div
+ onClick={() => setIsCommissionOpen((o) => !o)}
+ className="flex cursor-pointer items-center gap-1"
+ >
+ <span className="txt-small select-none">
+ {t("fields.commission")}
+ </span>
+ <TriangleDownMini
+ style={{
+ transform: `rotate(${isCommissionOpen ? 0 : -90}deg)`,
+ }}
+ />
+ </div>
+
+ <div className="text-right">
+ <Text size="small" leading="compact">
+ {getLocaleAmount(commissionTotal, order.currency_code)}
+ </Text>
+ </div>
+ </div>
+ {isCommissionOpen && (
+ <div className="flex flex-col gap-1 pl-5">
+ {commission_lines.map((line) => {
+ const label = line.shipping_method_id
+ ? t("fields.shipping")
+ : commissionItemTitleById.get(line.item_id ?? "") ??
+ line.code;
+ return (
+ <div
+ key={line.id}
+ className="flex items-center justify-between gap-x-2"
+ >
+ <div>
+ <span className="txt-small">{label}</span>
+ </div>
+ <div className="relative flex-1">
+ <div className="bottom-[calc(50% - 2px)] absolute h-[1px] w-full border-b border-dashed" />
+ </div>
+ <span className="txt-small text-ui-fg-muted">
+ {getLocaleAmount(line.amount, order.currency_code)}
+ </span>
+ </div>
+ );
+ })}
+ </div>
+ )}
+ </>
+ )}
<div className="text-ui-fg-base flex items-center justify-between">
<Text className="text-ui-fg-subtle" size="small" leading="compact">
{t("fields.total")}
diff --git a/packages/admin/src/pages/orders/order-detail/order-detail.tsx b/packages/admin/src/pages/orders/order-detail/order-detail.tsx
index 7cd3f88d2..182b63097 100644
--- a/packages/admin/src/pages/orders/order-detail/order-detail.tsx
+++ b/packages/admin/src/pages/orders/order-detail/order-detail.tsx
@@ -10,7 +10,6 @@ import { ActiveOrderExchangeSection } from "./components/active-order-exchange-s
import { ActiveOrderReturnSection } from "./components/active-order-return-section";
import { OrderActiveEditSection } from "./components/order-active-edit-section";
import { OrderActivitySection } from "./components/order-activity-section";
-import { OrderCommissionSection } from "./components/order-commission-section";
import { OrderCustomerSection } from "./components/order-customer-section";
import { OrderFulfillmentSection } from "./components/order-fulfillment-section";
import { OrderGeneralSection } from "./components/order-general-section";
@@ -93,7 +92,6 @@ const Root = ({ children }: { children?: ReactNode }) => {
<ActiveOrderReturnSection orderPreview={orderPreview!} />
<OrderGeneralSection order={order} />
<OrderSummarySection order={order} />
- <OrderCommissionSection order={order} />
<OrderPaymentSection order={order} />
<OrderFulfillmentSection order={order} />
</WidgetZone>
diff --git a/packages/core/src/workflows/order/workflows/confirm-return-receive.ts b/packages/core/src/workflows/order/workflows/confirm-return-receive.ts
index e6268e56c..69a9d881e 100644
--- a/packages/core/src/workflows/order/workflows/confirm-return-receive.ts
+++ b/packages/core/src/workflows/order/workflows/confirm-return-receive.ts
@@ -10,6 +10,7 @@ import {
import {
ChangeActionType,
MathBN,
+ MedusaError,
Modules,
OrderChangeStatus,
OrderWorkflowEvents,
@@ -152,8 +153,9 @@ function prepareInventoryUpdate({
}
if (hasManagedInventory && !hasStockLocation) {
- throw new Error(
- `Cannot receive the Return at location ${orderReturn.location_id}`,
+ throw new MedusaError(
+ MedusaError.Types.NOT_ALLOWED,
+ `Cannot receive the return at location ${orderReturn.location_id}: none of the returned items' inventory is stocked at this location.`,
)
}
diff --git a/packages/vendor/src/extension-targets.d.ts b/packages/vendor/src/extension-targets.d.ts
index 181ffdb59..84a4d989a 100644
--- a/packages/vendor/src/extension-targets.d.ts
+++ b/packages/vendor/src/extension-targets.d.ts
@@ -203,7 +203,7 @@ declare module "@mercurjs/dashboard-sdk" {
"order": {
formZones: never
formTabs: Record<string, string>
- displayZones: "active-claim" | "active-edit" | "active-exchange" | "active-return" | "activity" | "commission" | "customer" | "fulfillment" | "general" | "payment" | "summary"
+ displayZones: "active-claim" | "active-edit" | "active-exchange" | "active-return" | "activity" | "customer" | "fulfillment" | "general" | "payment" | "summary"
displayFieldIds: "display_id" | "fulfillment_status" | "payment_status" | "status"
}
"payout": {
diff --git a/packages/vendor/src/i18n/translations/$schema.json b/packages/vendor/src/i18n/translations/$schema.json
index dc287506f..6c6819e3a 100644
--- a/packages/vendor/src/i18n/translations/$schema.json
+++ b/packages/vendor/src/i18n/translations/$schema.json
@@ -6097,6 +6097,9 @@
"createRefundWrongQuantity": {
"type": "string"
},
+ "enterAmount": {
+ "type": "string"
+ },
"refundAmount": {
"type": "string"
},
@@ -6128,6 +6131,7 @@
"createRefund",
"refundPaymentSuccess",
"createRefundWrongQuantity",
+ "enterAmount",
"refundAmount",
"paymentLink",
"selectPaymentToRefund",
diff --git a/packages/vendor/src/i18n/translations/en.json b/packages/vendor/src/i18n/translations/en.json
index d1f560b83..15196b7e4 100644
--- a/packages/vendor/src/i18n/translations/en.json
+++ b/packages/vendor/src/i18n/translations/en.json
@@ -1490,6 +1490,7 @@
"createRefund": "Create Refund",
"refundPaymentSuccess": "Refund of amount {{amount}} successful",
"createRefundWrongQuantity": "Quantity should be a number between 1 and {{number}}",
+ "enterAmount": "Please enter an amount",
"refundAmount": "Refund {{ amount }}",
"paymentLink": "Copy payment link for {{ amount }}",
"copyPaymentLink": "Copy payment link for {{ amount }}",
diff --git a/packages/vendor/src/lib/order-helpers.ts b/packages/vendor/src/lib/order-helpers.ts
index b4410b32c..328bee6fc 100644
--- a/packages/vendor/src/lib/order-helpers.ts
+++ b/packages/vendor/src/lib/order-helpers.ts
@@ -24,7 +24,7 @@ export const getOrderPaymentStatus = (
],
awaiting: [t("orders.payment.status.awaiting"), "orange"],
captured: [t("orders.payment.status.captured"), "green"],
- refunded: [t("orders.payment.status.refunded"), "red"],
+ refunded: [t("orders.payment.status.refunded"), "green"],
partially_refunded: [
t("orders.payment.status.partiallyRefunded"),
"orange",
diff --git a/packages/vendor/src/pages/orders/[id]/_components/order-commission-section/index.ts b/packages/vendor/src/pages/orders/[id]/_components/order-commission-section/index.ts
deleted file mode 100644
index f58f25fde..000000000
--- a/packages/vendor/src/pages/orders/[id]/_components/order-commission-section/index.ts
+++ /dev/null
@@ -1 +0,0 @@
-export * from "./order-commission-section";
diff --git a/packages/vendor/src/pages/orders/[id]/_components/order-commission-section/order-commission-section.tsx b/packages/vendor/src/pages/orders/[id]/_components/order-commission-section/order-commission-section.tsx
deleted file mode 100644
index 522f14e0e..000000000
--- a/packages/vendor/src/pages/orders/[id]/_components/order-commission-section/order-commission-section.tsx
+++ /dev/null
@@ -1,73 +0,0 @@
-import { HttpTypes } from "@medusajs/types"
-import { Container, Heading, Text } from "@medusajs/ui"
-import { useMemo } from "react"
-import { useTranslation } from "react-i18next"
-
-import { DisplayExtensionZone } from "@mercurjs/dashboard-shared"
-import { getLocaleAmount } from "@lib/money-amount-helpers"
-import { useOrderCommissionLines } from "@hooks/api/orders"
-
-type OrderCommissionSectionProps = {
- order: HttpTypes.AdminOrder
-}
-
-export const OrderCommissionSection = ({
- order,
-}: OrderCommissionSectionProps) => {
- const { t } = useTranslation()
- const { commission_lines, isLoading } = useOrderCommissionLines(order.id)
-
- const itemTitleById = useMemo(() => {
- const map = new Map<string, string>()
- order.items?.forEach((item: any) => {
- map.set(item.id, item.product_title ?? item.title)
- })
- return map
- }, [order.items])
-
- if (isLoading || !commission_lines.length) {
- return null
- }
-
- const total = commission_lines.reduce(
- (acc, line) => acc + (line.amount ?? 0),
- 0
- )
-
- return (
- <Container className="divide-y p-0" data-testid="order-commission-section">
- <div className="flex items-center justify-between px-6 py-4">
- <Heading level="h2">{t("fields.commission", "Commission")}</Heading>
- </div>
- <div className="divide-y">
- {commission_lines.map((line) => {
- const label = line.shipping_method_id
- ? t("fields.shipping")
- : itemTitleById.get(line.item_id ?? "") ?? line.code
- return (
- <div
- key={line.id}
- className="text-ui-fg-subtle grid grid-cols-2 items-center gap-4 px-6 py-4"
- >
- <Text size="small" leading="compact">
- {label}
- </Text>
- <Text size="small" leading="compact" className="text-right">
- {getLocaleAmount(line.amount, order.currency_code)}
- </Text>
- </div>
- )
- })}
- </div>
- <div className="flex items-center justify-between px-6 py-4">
- <Text size="small" weight="plus" leading="compact">
- {t("orders.commission.total", "Total")}
- </Text>
- <Text size="small" weight="plus" leading="compact">
- {getLocaleAmount(total, order.currency_code)}
- </Text>
- </div>
- <DisplayExtensionZone model="order" zone="commission" data={order} />
- </Container>
- )
-}
diff --git a/packages/vendor/src/pages/orders/[id]/_components/order-payment-section/order-payment-section.tsx b/packages/vendor/src/pages/orders/[id]/_components/order-payment-section/order-payment-section.tsx
index 4eb222457..15ee2e3da 100644
--- a/packages/vendor/src/pages/orders/[id]/_components/order-payment-section/order-payment-section.tsx
+++ b/packages/vendor/src/pages/orders/[id]/_components/order-payment-section/order-payment-section.tsx
@@ -1,4 +1,4 @@
-import { ArrowUturnLeft, DocumentText } from "@medusajs/icons"
+import { ArrowDownRightMini, DocumentText } from "@medusajs/icons"
import { HttpTypes } from "@medusajs/types"
import {
Badge,
@@ -13,6 +13,7 @@ import { useTranslation } from "react-i18next"
import { DisplayExtensionZone } from "@mercurjs/dashboard-shared"
import { ActionMenu } from "@components/common/action-menu"
+import DisplayId from "@components/common/display-id/display-id"
import { getLocaleAmount, getStylizedAmount } from "@lib/money-amount-helpers"
import { getOrderPaymentStatus } from "@lib/order-helpers"
import { getTotalCaptured, getTotalPending } from "@lib/payment"
@@ -41,14 +42,14 @@ export const OrderPaymentSection = ({ order }: OrderPaymentSectionProps) => {
const payments = getPaymentsFromOrder(order) ?? []
return (
- <Container className="divide-y p-0">
+ <Container className="divide-y divide-dashed p-0">
<Header order={order} />
{payments.length > 0 && (
- <ul className="divide-y">
+ <div className="divide-y divide-dashed">
{payments.map((payment) => (
<PaymentRow key={payment.id} order={order} payment={payment} />
))}
- </ul>
+ </div>
)}
<Total order={order} />
<DisplayExtensionZone model="order" zone="payment" data={order} />
@@ -85,10 +86,6 @@ const Total = ({ order }: { order: HttpTypes.AdminOrder }) => {
const paymentCollections = order.payment_collections
const totalCaptured = getTotalCaptured(paymentCollections)
const totalPending = getTotalPending(paymentCollections)
- const totalRefunded = paymentCollections.reduce(
- (acc, pc) => acc + ((pc.refunded_amount as number) || 0),
- 0
- )
return (
<div>
@@ -102,18 +99,6 @@ const Total = ({ order }: { order: HttpTypes.AdminOrder }) => {
</Text>
</div>
- {totalRefunded > 0 && (
- <div className="flex items-center justify-between px-6 py-4">
- <Text size="small" weight="plus" leading="compact">
- {t("orders.payment.totalRefunded")}
- </Text>
-
- <Text size="small" weight="plus" leading="compact">
- {getStylizedAmount(totalRefunded, order.currency_code)}
- </Text>
- </div>
- )}
-
{order.status !== "canceled" && totalPending > 0 && (
<div className="flex items-center justify-between px-6 py-4">
<Text size="small" weight="plus" leading="compact">
@@ -131,20 +116,10 @@ const Total = ({ order }: { order: HttpTypes.AdminOrder }) => {
const getPaymentStatus = (
payment: HttpTypes.AdminPayment
-): { labelKey: string; color: "green" | "orange" | "red" | "grey" } => {
- const refundedAmount = (payment.refunds ?? []).reduce(
- (acc: number, r: { amount?: number }) => acc + (r.amount ?? 0),
- 0
- )
+): { labelKey: string; color: "green" | "orange" | "red" } => {
if (payment.canceled_at) {
return { labelKey: "orders.payment.status.canceled", color: "red" }
}
- if (refundedAmount > 0 && refundedAmount >= (payment.amount as number)) {
- return { labelKey: "orders.payment.status.refunded", color: "grey" }
- }
- if (refundedAmount > 0) {
- return { labelKey: "orders.payment.status.partiallyRefunded", color: "orange" }
- }
if (payment.captured_at) {
return { labelKey: "orders.payment.status.captured", color: "green" }
}
@@ -162,77 +137,59 @@ const PaymentRow = ({
const { getFullDate } = useDate()
const status = getPaymentStatus(payment)
- const refunds = (payment.refunds ?? []) as PaymentRefund[]
- const refundedAmount = refunds.reduce(
- (acc, r) => acc + (r.amount ?? 0),
- 0
- )
+ const refunds = (payment.refunds ?? []) as unknown as PaymentRefund[]
+ const refundedAmount = refunds.reduce((acc, r) => acc + (r.amount ?? 0), 0)
const isFullyRefunded =
refundedAmount > 0 && refundedAmount >= (payment.amount as number)
const canRefund =
!!payment.captured_at && !payment.canceled_at && !isFullyRefunded
return (
- <li data-testid={`payment-row-${payment.id}`}>
- <div className="flex items-center justify-between px-6 py-4">
- <div className="flex min-w-0 flex-col">
- <Tooltip content={payment.id}>
- <Text
- size="small"
- weight="plus"
- leading="compact"
- className={
- isFullyRefunded
- ? "text-ui-fg-muted truncate line-through"
- : "text-ui-fg-base truncate"
- }
- >
- {`#${payment.id.slice(-7)}`}
- </Text>
- </Tooltip>
- <Text
- size="xsmall"
- leading="compact"
- className={
- isFullyRefunded
- ? "text-ui-fg-muted line-through"
- : "text-ui-fg-subtle"
- }
- >
+ <div className="divide-y divide-dashed" data-testid={`payment-row-${payment.id}`}>
+ <div className="text-ui-fg-subtle grid grid-cols-[1fr_1fr_1fr_20px] items-center gap-x-4 px-6 py-4 sm:grid-cols-[1fr_1fr_1fr_1fr_20px]">
+ <div className="w-full min-w-[60px] overflow-hidden">
+ <Text size="small" leading="compact" weight="plus" className="truncate">
+ <DisplayId id={payment.id} />
+ </Text>
+ <Text size="small" leading="compact">
{payment.created_at
? getFullDate({ date: payment.created_at, includeTime: true })
: null}
</Text>
</div>
- <div className="flex items-center gap-x-3">
+ <div className="hidden items-center justify-end sm:flex">
+ <Text size="small" leading="compact" className="capitalize">
+ {payment.provider_id}
+ </Text>
+ </div>
+
+ <div className="flex items-center justify-end">
<StatusBadge color={status.color} className="text-nowrap">
{t(status.labelKey)}
</StatusBadge>
- <Text
- size="small"
- weight="plus"
- leading="compact"
- className={isFullyRefunded ? "line-through" : undefined}
- >
- {getStylizedAmount(payment.amount as number, order.currency_code)}
- </Text>
+ </div>
- <ActionMenu
- groups={[
- {
- actions: [
- {
- label: t("orders.payment.createRefund"),
- icon: <ArrowUturnLeft />,
- to: `/orders/${order.id}/refund?payment_id=${payment.id}`,
- disabled: !canRefund,
- },
- ],
- },
- ]}
- />
+ <div className="flex items-center justify-end">
+ <Text size="small" leading="compact">
+ {getLocaleAmount(payment.amount as number, order.currency_code)}
+ </Text>
</div>
+
+ <ActionMenu
+ groups={[
+ {
+ actions: [
+ {
+ label: t("orders.payment.createRefund"),
+ icon: <ArrowDownRightMini />,
+ to: `/orders/${order.id}/refund?payment_id=${payment.id}`,
+ disabled: !canRefund,
+ },
+ ],
+ },
+ ]}
+ />
</div>
{refunds.map((refund) => (
@@ -242,7 +199,7 @@ const PaymentRow = ({
currencyCode={order.currency_code}
/>
))}
- </li>
+ </div>
)
}
@@ -260,36 +217,49 @@ const RefundRow = ({
return (
<div
- className="flex items-center justify-between px-6 py-3 pl-12 bg-ui-bg-subtle"
+ className="bg-ui-bg-subtle text-ui-fg-subtle grid grid-cols-[1fr_1fr_1fr_20px] items-center gap-x-4 px-6 py-4"
data-testid={`refund-row-${refund.id}`}
>
- <div className="flex min-w-0 flex-col">
- <div className="flex items-center gap-x-2">
- <Text size="small" leading="compact" className="text-ui-fg-subtle">
- {t("orders.payment.refund")}
- </Text>
- {reasonLabel && (
- <Badge size="2xsmall" rounded="full">
- {reasonLabel}
- </Badge>
- )}
- {refund.note && (
- <Tooltip content={refund.note}>
- <DocumentText className="text-ui-fg-subtle h-3 w-3" />
- </Tooltip>
+ <div className="flex flex-row">
+ <div className="self-center pr-3">
+ <ArrowDownRightMini className="text-ui-fg-muted" />
+ </div>
+ <div className="min-w-0">
+ <div className="flex items-center gap-x-1">
+ <Text size="small" leading="compact" weight="plus">
+ {t("orders.payment.refund")}
+ </Text>
+ {refund.note && (
+ <Tooltip content={refund.note}>
+ <DocumentText className="text-ui-tag-neutral-icon inline" />
+ </Tooltip>
+ )}
+ </div>
+ {refund.created_at && (
+ <Text size="small" leading="compact">
+ {getFullDate({ date: refund.created_at, includeTime: true })}
+ </Text>
)}
</div>
- {refund.created_at && (
- <Text size="xsmall" leading="compact" className="text-ui-fg-subtle">
- {getFullDate({ date: refund.created_at, includeTime: true })}
- </Text>
+ </div>
+
+ <div className="flex items-center justify-end">
+ {reasonLabel && (
+ <Badge
+ size="2xsmall"
+ className="cursor-default select-none capitalize"
+ rounded="full"
+ >
+ {reasonLabel}
+ </Badge>
)}
</div>
- <Text size="small" weight="plus" leading="compact">
- {`- ${getLocaleAmount(refund.amount ?? 0, currencyCode)}`}
- </Text>
+ <div className="flex items-center justify-end">
+ <Text size="small" leading="compact">
+ {`- ${getLocaleAmount(refund.amount ?? 0, currencyCode)}`}
+ </Text>
+ </div>
</div>
)
}
-
diff --git a/packages/vendor/src/pages/orders/[id]/_components/order-summary-section/order-summary-section.tsx b/packages/vendor/src/pages/orders/[id]/_components/order-summary-section/order-summary-section.tsx
index e3a633119..418beeff3 100644
--- a/packages/vendor/src/pages/orders/[id]/_components/order-summary-section/order-summary-section.tsx
+++ b/packages/vendor/src/pages/orders/[id]/_components/order-summary-section/order-summary-section.tsx
@@ -37,7 +37,10 @@ import {
import { DisplayExtensionZone } from "@mercurjs/dashboard-shared"
import { ActionMenu } from "@components/common/action-menu"
-import { useOrderPreview } from "../../../../../hooks/api/orders"
+import {
+ useOrderCommissionLines,
+ useOrderPreview,
+} from "../../../../../hooks/api/orders"
import { useReservationItems } from "../../../../../hooks/api/reservations"
import { useReturns } from "../../../../../hooks/api/returns"
import {
@@ -684,6 +687,21 @@ const CostBreakdown = ({
const { t } = useTranslation()
const [isTaxOpen, setIsTaxOpen] = useState(false)
const [isShippingOpen, setIsShippingOpen] = useState(false)
+ const [isCommissionOpen, setIsCommissionOpen] = useState(false)
+
+ const { commission_lines } = useOrderCommissionLines(order.id)
+ const hasCommission = commission_lines.length > 0
+ const commissionTotal = commission_lines.reduce(
+ (acc, line) => acc + (line.amount ?? 0),
+ 0
+ )
+ const commissionItemTitleById = useMemo(() => {
+ const map = new Map<string, string>()
+ order.items?.forEach((item) => {
+ map.set(item.id, item.product_title ?? item.title)
+ })
+ return map
+ }, [order.items])
const discountCodes = useMemo(() => {
const codes = new Set()
@@ -863,6 +881,60 @@ const CostBreakdown = ({
</div>
)}
</>
+
+ {hasCommission && (
+ <>
+ <div className="flex justify-between">
+ {/* oxlint-disable-next-line jsx-a11y/click-events-have-key-events, jsx-a11y/no-static-element-interactions */}
+ <div
+ onClick={() => setIsCommissionOpen((o) => !o)}
+ className="flex cursor-pointer items-center gap-1"
+ >
+ <span className="txt-small select-none">
+ {t("fields.commission")}
+ </span>
+ <TriangleDownMini
+ style={{
+ transform: `rotate(${isCommissionOpen ? 0 : -90}deg)`,
+ }}
+ />
+ </div>
+
+ <div className="text-right">
+ <Text size="small" leading="compact">
+ {getLocaleAmount(commissionTotal, order.currency_code)}
+ </Text>
+ </div>
+ </div>
+ {isCommissionOpen && (
+ <div className="flex flex-col gap-1 pl-5">
+ {commission_lines.map((line) => {
+ const label = line.shipping_method_id
+ ? t("fields.shipping")
+ : commissionItemTitleById.get(line.item_id ?? "") ?? line.code
+ return (
+ <div
+ key={line.id}
+ className="flex items-center justify-between gap-x-2"
+ >
+ <div>
+ <span className="txt-small text-ui-fg-subtle font-medium">
+ {label}
+ </span>
+ </div>
+ <div className="relative flex-1">
+ <div className="bottom-[calc(50% - 2px)] absolute h-[1px] w-full border-b border-dashed" />
+ </div>
+ <span className="txt-small text-ui-fg-muted">
+ {getLocaleAmount(line.amount, order.currency_code)}
+ </span>
+ </div>
+ )
+ })}
+ </div>
+ )}
+ </>
+ )}
</div>
)
}
diff --git a/packages/vendor/src/pages/orders/[id]/order-detail-page.tsx b/packages/vendor/src/pages/orders/[id]/order-detail-page.tsx
index 92f294725..94851d1b1 100644
--- a/packages/vendor/src/pages/orders/[id]/order-detail-page.tsx
+++ b/packages/vendor/src/pages/orders/[id]/order-detail-page.tsx
@@ -11,7 +11,6 @@ import { ActiveOrderExchangeSection } from "./_components/active-order-exchange-
import { ActiveOrderReturnSection } from "./_components/active-order-return-section";
import { OrderActiveEditSection } from "./_components/order-active-edit-section";
import { OrderActivitySection } from "./_components/order-activity-section";
-import { OrderCommissionSection } from "./_components/order-commission-section";
import { OrderCustomerSection } from "./_components/order-customer-section";
import { OrderFulfillmentSection } from "./_components/order-fulfillment-section";
import { OrderGeneralSection } from "./_components/order-general-section";
@@ -81,7 +80,6 @@ const Root = ({ children }: { children?: ReactNode }) => {
)}
<OrderGeneralSection order={order} />
<OrderSummarySection order={order} />
- <OrderCommissionSection order={order} />
<OrderPaymentSection order={order} />
<OrderFulfillmentSection order={order} />
</WidgetZone>
diff --git a/packages/vendor/src/pages/orders/[id]/refund/_components/create-refund-form/create-refund-form.tsx b/packages/vendor/src/pages/orders/[id]/refund/_components/create-refund-form/create-refund-form.tsx
index c62927bff..1432901b7 100644
--- a/packages/vendor/src/pages/orders/[id]/refund/_components/create-refund-form/create-refund-form.tsx
+++ b/packages/vendor/src/pages/orders/[id]/refund/_components/create-refund-form/create-refund-form.tsx
@@ -8,14 +8,14 @@ import { useMemo } from "react"
import { useForm } from "react-hook-form"
import { useTranslation } from "react-i18next"
import { useSearchParams } from "react-router-dom"
+import { formatValue } from "react-currency-input-field"
import { z } from "zod"
import { zodResolver } from "@hookform/resolvers/zod"
import {
Button,
+ CurrencyInput,
Heading,
- Input,
Select,
- Text,
Textarea,
toast,
} from "@medusajs/ui"
@@ -23,19 +23,13 @@ import { HttpTypes } from "@medusajs/types"
import { RouteDrawer, useRouteModal } from "@components/modals"
import { Form } from "@components/common/form"
+import DisplayId from "@components/common/display-id/display-id"
import { KeyboundForm } from "@components/utilities/keybound-form"
import { useRefundPayment } from "@hooks/api/payments"
import { useRefundReasons } from "@hooks/api/refund-reasons"
import { useDocumentDirection } from "@hooks/use-document-direction"
-import { getStylizedAmount } from "@lib/money-amount-helpers"
-
-const RefundSchema = z.object({
- amount: z.coerce.number().positive(),
- refund_reason_id: z.string().optional(),
- note: z.string().optional(),
-})
-
-type RefundFormValues = z.infer<typeof RefundSchema>
+import { currencies } from "@lib/data/currencies"
+import { getDecimalDigits, getLocaleAmount } from "@lib/money-amount-helpers"
type CreateRefundFormProps = {
order: HttpTypes.AdminOrder
@@ -88,24 +82,58 @@ export const CreateRefundForm = ({ order }: CreateRefundFormProps) => {
return Math.max(0, (payment.amount as number) - refundedAmount)
}, [payment, refundedAmount])
+ const currency = useMemo(
+ () => currencies[order.currency_code.toUpperCase()],
+ [order.currency_code]
+ )
+
+ const decimalDigits = getDecimalDigits(order.currency_code)
+
+ // Mirror getStylizedAmount's rounding so the field and the paid line agree.
+ const getRoundedAmount = (amount: number) =>
+ amount.toLocaleString("en-US", {
+ minimumFractionDigits: decimalDigits,
+ maximumFractionDigits: decimalDigits,
+ useGrouping: false,
+ })
+
+ const RefundSchema = useMemo(
+ () =>
+ z.object({
+ amount: z
+ .object({
+ value: z.union([z.string(), z.number()]),
+ float: z.number().nullable(),
+ })
+ .refine((v) => v.float !== null && v.float > 0, {
+ message: t("orders.payment.enterAmount"),
+ }),
+ refund_reason_id: z.string().optional(),
+ note: z.string().optional(),
+ }),
+ [t]
+ )
+
+ type RefundFormValues = z.infer<typeof RefundSchema>
+
const refundPayment = useRefundPayment(order.id, paymentId)
const form = useForm<RefundFormValues>({
resolver: zodResolver(RefundSchema),
defaultValues: {
- amount: remaining,
- refund_reason_id: undefined,
- note: "",
- },
- values: {
- amount: remaining,
+ amount: {
+ value: getRoundedAmount(remaining),
+ float: remaining,
+ },
refund_reason_id: undefined,
note: "",
},
})
const handleSubmit = form.handleSubmit(async (values) => {
- if (values.amount > remaining) {
+ const amount = values.amount.float ?? 0
+
+ if (amount > remaining) {
form.setError("amount", {
message: t("orders.payment.createRefundWrongQuantity", {
number: remaining,
@@ -116,7 +144,7 @@ export const CreateRefundForm = ({ order }: CreateRefundFormProps) => {
await refundPayment.mutateAsync(
{
- amount: values.amount,
+ amount,
refund_reason_id: values.refund_reason_id,
note: values.note?.trim() ? values.note.trim() : undefined,
},
@@ -124,7 +152,7 @@ export const CreateRefundForm = ({ order }: CreateRefundFormProps) => {
onSuccess: () => {
toast.success(
t("orders.payment.refundPaymentSuccess", {
- amount: getStylizedAmount(values.amount, order.currency_code),
+ amount: getLocaleAmount(amount, order.currency_code),
})
)
handleSuccess(`/orders/${order.id}`)
@@ -145,57 +173,46 @@ export const CreateRefundForm = ({ order }: CreateRefundFormProps) => {
<KeyboundForm onSubmit={handleSubmit} className="flex flex-1 flex-col">
<RouteDrawer.Body>
<div className="flex flex-col gap-y-4">
- <div className="bg-ui-bg-component shadow-elevation-card-rest rounded-lg p-3">
- <div className="flex items-center justify-between">
- <Text size="small" className="text-ui-fg-subtle">
- {t("orders.payment.totalPaidByCustomer")}
- </Text>
- <Text size="small" weight="plus">
- {getStylizedAmount(
- payment.amount as number,
- order.currency_code
- )}
- </Text>
- </div>
- {refundedAmount > 0 && (
- <div className="flex items-center justify-between pt-1">
- <Text size="small" className="text-ui-fg-subtle">
- {t("orders.payment.totalRefunded")}
- </Text>
- <Text size="small" weight="plus">
- {getStylizedAmount(refundedAmount, order.currency_code)}
- </Text>
- </div>
- )}
+ <div className="text-ui-fg-base flex items-center gap-x-1 text-sm">
+ <span>
+ {getLocaleAmount(
+ payment.amount as number,
+ order.currency_code
+ )}
+ </span>
+ <span>-</span>
+ <span>
+ (<DisplayId id={payment.id} />)
+ </span>
</div>
<Form.Field
control={form.control}
name="amount"
- render={({ field }) => (
+ render={({ field: { onChange, ...field } }) => (
<Form.Item>
<Form.Label>{t("fields.amount")}</Form.Label>
<Form.Control>
- <Input
- type="number"
- step="0.01"
- min={0}
- max={remaining}
- data-testid="refund-amount-input"
+ <CurrencyInput
{...field}
- value={field.value ?? ""}
- onChange={(e) =>
- field.onChange(
- e.target.value === "" ? "" : Number(e.target.value)
- )
+ min={0}
+ placeholder={formatValue({
+ value: "0",
+ decimalScale: currency.decimal_digits,
+ })}
+ decimalScale={currency.decimal_digits}
+ symbol={currency.symbol_native}
+ code={currency.code}
+ value={field.value.value}
+ onValueChange={(_value, _name, values) =>
+ onChange({
+ value: values?.value ?? "",
+ float: values?.float ?? null,
+ })
}
+ data-testid="refund-amount-input"
/>
</Form.Control>
- <Form.Hint>
- {t("orders.payment.refundAmount", {
- amount: getStylizedAmount(remaining, order.currency_code),
- })}
- </Form.Hint>
<Form.ErrorMessage />
</Form.Item>
)}
@@ -253,7 +270,7 @@ export const CreateRefundForm = ({ order }: CreateRefundFormProps) => {
</RouteDrawer.Body>
<RouteDrawer.Footer>
- <div className="flex items-center gap-x-2">
+ <div className="flex items-center justify-end gap-x-2">
<RouteDrawer.Close asChild>
<Button size="small" variant="secondary">
{t("actions.cancel")}
@@ -265,7 +282,7 @@ export const CreateRefundForm = ({ order }: CreateRefundFormProps) => {
isLoading={refundPayment.isPending}
data-testid="refund-submit-button"
>
- {t("actions.confirm")}
+ {t("actions.save")}
</Button>
</div>
</RouteDrawer.Footer>