Skip to content

armgit / spree

Public Imported from GitHub
0

Open Source Platform for DTC, B2B Commerce, Marketplaces & Omnichannel. REST APIs, TypeScript SDKs, and production-ready Next.js storefront. Self-host it. Own your data. No vendor lock-in. Zero platform fees.

Let admins open returns, exchanges and claims from the order page

Damian Legawiec7303dd1652ca
diff --git a/packages/admin-sdk/src/types/generated/Fulfillment.ts b/packages/admin-sdk/src/types/generated/Fulfillment.ts
index 1c26410087..0e3c058cf9 100644
--- a/packages/admin-sdk/src/types/generated/Fulfillment.ts
+++ b/packages/admin-sdk/src/types/generated/Fulfillment.ts
@@ -1,7 +1,7 @@
-// Typelizer digest 86e7aceb1c85322cab69fd50d1495105
+// Typelizer digest 3f0a6296532bf05f2e34d5e65132adc6
//
// DO NOT MODIFY: This file was automatically generated by Typelizer.
-import type {DeliveryMethod, StockLocation, DeliveryRate, Order} from '@/types'
+import type {DeliveryMethod, StockLocation, DeliveryRate, FulfillmentItem, Order} from '@/types'
interface Fulfillment {
id: string;
@@ -36,6 +36,7 @@ interface Fulfillment {
updated_at: string;
order_id: string | null;
stock_location_id: string | null;
+ fulfillment_items?: Array<FulfillmentItem>;
order?: Order;
}
diff --git a/packages/admin-sdk/src/types/generated/FulfillmentItem.ts b/packages/admin-sdk/src/types/generated/FulfillmentItem.ts
new file mode 100644
index 0000000000..06be34734a
--- /dev/null
+++ b/packages/admin-sdk/src/types/generated/FulfillmentItem.ts
@@ -0,0 +1,15 @@
+// Typelizer digest 430e0e841edd12717919af94b7e37193
+//
+// DO NOT MODIFY: This file was automatically generated by Typelizer.
+
+interface FulfillmentItem {
+ id: string;
+ quantity: number;
+ status: string;
+ variant_id: string | null;
+ line_item_id: string | null;
+ name: string | null;
+ options_text: string | null;
+}
+
+export default FulfillmentItem;
diff --git a/packages/admin-sdk/src/types/generated/index.ts b/packages/admin-sdk/src/types/generated/index.ts
index 8fc3087c29..a6bf38737e 100644
--- a/packages/admin-sdk/src/types/generated/index.ts
+++ b/packages/admin-sdk/src/types/generated/index.ts
@@ -1,4 +1,4 @@
-// Typelizer digest 9ccdadcbe7896acce65607dfb45d6e6f
+// Typelizer digest c2ebf5ea871438ad65f0e28411f2e858
//
// DO NOT MODIFY: This file was automatically generated by Typelizer.
export type { default as Address } from './Address'
@@ -31,6 +31,7 @@ export type { default as ExchangeLineItem } from './ExchangeLineItem'
export type { default as Exchange } from './Exchange'
export type { default as Export } from './Export'
export type { default as Fee } from './Fee'
+export type { default as FulfillmentItem } from './FulfillmentItem'
export type { default as Fulfillment } from './Fulfillment'
export type { default as GiftCardBatch } from './GiftCardBatch'
export type { default as GiftCard } from './GiftCard'
diff --git a/packages/admin-sdk/src/types/index.ts b/packages/admin-sdk/src/types/index.ts
index 8cd33f9349..7d622ae55d 100644
--- a/packages/admin-sdk/src/types/index.ts
+++ b/packages/admin-sdk/src/types/index.ts
@@ -38,6 +38,7 @@ export type { default as ExchangeLineItem } from './generated/ExchangeLineItem'
export type { default as Export } from './generated/Export'
export type { default as Fee } from './generated/Fee'
export type { default as Fulfillment } from './generated/Fulfillment'
+export type { default as FulfillmentItem } from './generated/FulfillmentItem'
export type { default as GiftCard } from './generated/GiftCard'
export type { default as GiftCardBatch } from './generated/GiftCardBatch'
export type { default as Import } from './generated/Import'
diff --git a/packages/dashboard/src/components/spree/order-post-sale-cards.tsx b/packages/dashboard/src/components/spree/order-post-sale-cards.tsx
index c835f15734..016b9f53f8 100644
--- a/packages/dashboard/src/components/spree/order-post-sale-cards.tsx
+++ b/packages/dashboard/src/components/spree/order-post-sale-cards.tsx
@@ -1,8 +1,9 @@
-import type { Claim, Exchange } from '@spree/admin-sdk'
+import type { Claim, Exchange, Order } from '@spree/admin-sdk'
import {
Badge,
Button,
Card,
+ CardAction,
CardContent,
CardHeader,
CardTitle,
@@ -19,11 +20,13 @@ import {
CheckCircleIcon,
EllipsisVerticalIcon,
PackageCheckIcon,
+ PlusIcon,
RepeatIcon,
ShieldAlertIcon,
TruckIcon,
XCircleIcon,
} from 'lucide-react'
+import { useState } from 'react'
import { useTranslation } from 'react-i18next'
import {
useClaimActions,
@@ -31,231 +34,295 @@ import {
useOrderClaims,
useOrderExchanges,
} from '../../hooks/use-post-sale'
+import { CreateClaimDialog, CreateExchangeDialog, fulfilledUnits } from './post-sale-create-dialogs'
/** Exchanges on an order, with the actions available at each status. */
-export function OrderExchangesCard({ orderId }: { orderId: string }) {
+export function OrderExchangesCard({ order }: { order: Order }) {
+ const orderId = order.id
const { t } = useTranslation()
const confirm = useConfirm()
const { data } = useOrderExchanges(orderId)
- const { approve, receive, fulfill, cancel } = useExchangeActions(orderId)
+ const { create, approve, receive, fulfill, cancel } = useExchangeActions(orderId)
+ const [creating, setCreating] = useState(false)
const exchanges = data?.data ?? []
- if (exchanges.length === 0) return null
+ const canCreate = fulfilledUnits(order).length > 0
return (
- <Card>
- <CardHeader>
- <CardTitle>
- <RepeatIcon className="size-4" />
- {t('admin.pages.orders.detail.section_exchanges')}
- <Badge variant="outline">{exchanges.length}</Badge>
- </CardTitle>
- </CardHeader>
- <CardContent className="flex flex-col gap-4">
- {exchanges.map((exchange: Exchange) => (
- <div key={exchange.id} className="rounded-lg border p-4 flex flex-col gap-3">
- <div className="flex items-center justify-between">
- <div className="flex items-center gap-2">
- <StatusBadge status={exchange.status} />
- <span className="text-sm font-medium">{exchange.number}</span>
- </div>
+ <>
+ <Card>
+ <CardHeader>
+ <CardTitle>
+ <RepeatIcon className="size-4" />
+ {t('admin.pages.orders.detail.section_exchanges')}
+ {exchanges.length > 0 && <Badge variant="outline">{exchanges.length}</Badge>}
+ </CardTitle>
+ {canCreate && (
+ <CardAction>
+ <Button variant="outline" size="sm" onClick={() => setCreating(true)}>
+ <PlusIcon className="size-4" />
+ {t('admin.pages.orders.detail.exchanges.actions.create')}
+ </Button>
+ </CardAction>
+ )}
+ </CardHeader>
+ <CardContent className="flex flex-col gap-4">
+ {exchanges.length === 0 && (
+ <p className="text-sm text-muted-foreground">
+ {canCreate
+ ? t('admin.pages.orders.detail.exchanges.empty')
+ : t('admin.pages.orders.detail.returns.empty_nothing_fulfilled')}
+ </p>
+ )}
+ {exchanges.map((exchange: Exchange) => (
+ <div key={exchange.id} className="rounded-lg border p-4 flex flex-col gap-3">
+ <div className="flex items-center justify-between">
+ <div className="flex items-center gap-2">
+ <StatusBadge status={exchange.status} />
+ <span className="text-sm font-medium">{exchange.number}</span>
+ </div>
- <DropdownMenu>
- <DropdownMenuTrigger asChild>
- <Button variant="ghost" size="icon-xs">
- <EllipsisVerticalIcon className="size-4" />
- </Button>
- </DropdownMenuTrigger>
- <DropdownMenuContent align="end">
- {exchange.status === 'requested' && (
- <DropdownMenuItem onClick={() => approve.mutate(exchange.id)}>
- <CheckCircleIcon className="size-4" />
- {t('admin.pages.orders.detail.returns.actions.approve')}
- </DropdownMenuItem>
- )}
- {exchange.status === 'approved' && (
- <DropdownMenuItem onClick={() => receive.mutate({ exchangeId: exchange.id })}>
- <PackageCheckIcon className="size-4" />
- {t('admin.pages.orders.detail.returns.actions.receive')}
- </DropdownMenuItem>
- )}
- {exchange.status === 'received' && (
- <DropdownMenuItem onClick={() => fulfill.mutate({ exchangeId: exchange.id })}>
- <TruckIcon className="size-4" />
- {t('admin.pages.orders.detail.exchanges.actions.fulfill')}
- </DropdownMenuItem>
- )}
- {['requested', 'approved'].includes(exchange.status) && (
- <>
- <DropdownMenuSeparator />
- <DropdownMenuItem
- className="text-destructive focus:text-destructive"
- onClick={async () => {
- if (
- await confirm({
- message: t('admin.pages.orders.detail.returns.confirm.cancel'),
- variant: 'destructive',
- confirmLabel: t('admin.actions.cancel'),
- })
- ) {
- cancel.mutate({ exchangeId: exchange.id })
- }
- }}
- >
- <XCircleIcon className="size-4" />
- {t('admin.actions.cancel')}
+ <DropdownMenu>
+ <DropdownMenuTrigger asChild>
+ <Button variant="ghost" size="icon-xs">
+ <EllipsisVerticalIcon className="size-4" />
+ </Button>
+ </DropdownMenuTrigger>
+ <DropdownMenuContent align="end">
+ {exchange.status === 'requested' && (
+ <DropdownMenuItem onClick={() => approve.mutate(exchange.id)}>
+ <CheckCircleIcon className="size-4" />
+ {t('admin.pages.orders.detail.returns.actions.approve')}
</DropdownMenuItem>
- </>
- )}
- </DropdownMenuContent>
- </DropdownMenu>
- </div>
+ )}
+ {exchange.status === 'approved' && (
+ <DropdownMenuItem onClick={() => receive.mutate({ exchangeId: exchange.id })}>
+ <PackageCheckIcon className="size-4" />
+ {t('admin.pages.orders.detail.returns.actions.receive')}
+ </DropdownMenuItem>
+ )}
+ {exchange.status === 'received' && (
+ <DropdownMenuItem onClick={() => fulfill.mutate({ exchangeId: exchange.id })}>
+ <TruckIcon className="size-4" />
+ {t('admin.pages.orders.detail.exchanges.actions.fulfill')}
+ </DropdownMenuItem>
+ )}
+ {['requested', 'approved'].includes(exchange.status) && (
+ <>
+ <DropdownMenuSeparator />
+ <DropdownMenuItem
+ className="text-destructive focus:text-destructive"
+ onClick={async () => {
+ if (
+ await confirm({
+ message: t('admin.pages.orders.detail.returns.confirm.cancel'),
+ variant: 'destructive',
+ confirmLabel: t('admin.actions.cancel'),
+ })
+ ) {
+ cancel.mutate({ exchangeId: exchange.id })
+ }
+ }}
+ >
+ <XCircleIcon className="size-4" />
+ {t('admin.actions.cancel')}
+ </DropdownMenuItem>
+ </>
+ )}
+ </DropdownMenuContent>
+ </DropdownMenu>
+ </div>
- <div className="flex flex-col gap-1.5">
- {(exchange.exchange_line_items ?? []).map((line) => (
- <div key={line.id} className="flex items-center justify-between text-sm">
- <span className="truncate">
- {line.original_variant?.product_name ?? line.original_variant_id}
- {' → '}
- {line.new_variant?.options_text || line.new_variant?.sku || line.new_variant_id}
- </span>
- <span className="text-muted-foreground">×{line.quantity}</span>
- </div>
- ))}
- </div>
+ <div className="flex flex-col gap-1.5">
+ {(exchange.exchange_line_items ?? []).map((line) => (
+ <div key={line.id} className="flex items-center justify-between text-sm">
+ <span className="truncate">
+ {line.original_variant?.product_name ?? line.original_variant_id}
+ {' → '}
+ {line.new_variant?.options_text ||
+ line.new_variant?.sku ||
+ line.new_variant_id}
+ </span>
+ <span className="text-muted-foreground">×{line.quantity}</span>
+ </div>
+ ))}
+ </div>
- <div className="flex items-center justify-between text-sm border-t pt-3">
- <span className="text-muted-foreground">
- {t('admin.pages.orders.detail.exchanges.price_difference')}
- </span>
- <span className="font-medium">{exchange.display_price_difference}</span>
+ <div className="flex items-center justify-between text-sm border-t pt-3">
+ <span className="text-muted-foreground">
+ {t('admin.pages.orders.detail.exchanges.price_difference')}
+ </span>
+ <span className="font-medium">{exchange.display_price_difference}</span>
+ </div>
</div>
- </div>
- ))}
- </CardContent>
- </Card>
+ ))}
+ </CardContent>
+ </Card>
+
+ {creating && (
+ <CreateExchangeDialog
+ order={order}
+ onClose={() => setCreating(false)}
+ onSubmit={(params) => {
+ create.mutate(params)
+ setCreating(false)
+ }}
+ />
+ )}
+ </>
)
}
/** Claims on an order. Resolution is chosen at resolve time, not up front. */
-export function OrderClaimsCard({ orderId }: { orderId: string }) {
+export function OrderClaimsCard({ order }: { order: Order }) {
+ const orderId = order.id
const { t } = useTranslation()
const confirm = useConfirm()
const { data } = useOrderClaims(orderId)
- const { approve, resolve, deny, cancel } = useClaimActions(orderId)
+ const { create, approve, resolve, deny, cancel } = useClaimActions(orderId)
+ const [creatingClaim, setCreatingClaim] = useState(false)
const claims = data?.data ?? []
- if (claims.length === 0) return null
+ // A claim is about ordered items, so it never depends on anything shipping.
+ const canCreate = (order.items ?? []).length > 0
return (
- <Card>
- <CardHeader>
- <CardTitle>
- <ShieldAlertIcon className="size-4" />
- {t('admin.pages.orders.detail.section_claims')}
- <Badge variant="outline">{claims.length}</Badge>
- </CardTitle>
- </CardHeader>
- <CardContent className="flex flex-col gap-4">
- {claims.map((claim: Claim) => (
- <div key={claim.id} className="rounded-lg border p-4 flex flex-col gap-3">
- <div className="flex items-center justify-between">
- <div className="flex items-center gap-2">
- <StatusBadge status={claim.status} />
- <span className="text-sm font-medium">{claim.number}</span>
- <Badge variant="outline">
- {t(`admin.pages.orders.detail.claims.types.${claim.claim_type}`, {
- defaultValue: claim.claim_type,
- })}
- </Badge>
- </div>
+ <>
+ <Card>
+ <CardHeader>
+ <CardTitle>
+ <ShieldAlertIcon className="size-4" />
+ {t('admin.pages.orders.detail.section_claims')}
+ {claims.length > 0 && <Badge variant="outline">{claims.length}</Badge>}
+ </CardTitle>
+ {canCreate && (
+ <CardAction>
+ <Button variant="outline" size="sm" onClick={() => setCreatingClaim(true)}>
+ <PlusIcon className="size-4" />
+ {t('admin.pages.orders.detail.claims.actions.create')}
+ </Button>
+ </CardAction>
+ )}
+ </CardHeader>
+ <CardContent className="flex flex-col gap-4">
+ {claims.length === 0 && (
+ <p className="text-sm text-muted-foreground">
+ {t('admin.pages.orders.detail.claims.empty')}
+ </p>
+ )}
+ {claims.map((claim: Claim) => (
+ <div key={claim.id} className="rounded-lg border p-4 flex flex-col gap-3">
+ <div className="flex items-center justify-between">
+ <div className="flex items-center gap-2">
+ <StatusBadge status={claim.status} />
+ <span className="text-sm font-medium">{claim.number}</span>
+ <Badge variant="outline">
+ {t(`admin.pages.orders.detail.claims.types.${claim.claim_type}`, {
+ defaultValue: claim.claim_type,
+ })}
+ </Badge>
+ </div>
- <DropdownMenu>
- <DropdownMenuTrigger asChild>
- <Button variant="ghost" size="icon-xs">
- <EllipsisVerticalIcon className="size-4" />
- </Button>
- </DropdownMenuTrigger>
- <DropdownMenuContent align="end">
- {claim.status === 'open' && (
- <DropdownMenuItem onClick={() => approve.mutate(claim.id)}>
- <CheckCircleIcon className="size-4" />
- {t('admin.pages.orders.detail.returns.actions.approve')}
- </DropdownMenuItem>
- )}
- {claim.status === 'approved' && (
- <>
- <DropdownMenuItem
- onClick={() => resolve.mutate({ claimId: claim.id, resolution: 'refund' })}
- >
- <BanknoteIcon className="size-4" />
- {t('admin.pages.orders.detail.claims.actions.resolve_refund')}
+ <DropdownMenu>
+ <DropdownMenuTrigger asChild>
+ <Button variant="ghost" size="icon-xs">
+ <EllipsisVerticalIcon className="size-4" />
+ </Button>
+ </DropdownMenuTrigger>
+ <DropdownMenuContent align="end">
+ {claim.status === 'open' && (
+ <DropdownMenuItem onClick={() => approve.mutate(claim.id)}>
+ <CheckCircleIcon className="size-4" />
+ {t('admin.pages.orders.detail.returns.actions.approve')}
</DropdownMenuItem>
- <DropdownMenuItem
- onClick={() =>
- resolve.mutate({ claimId: claim.id, resolution: 'replacement' })
- }
- >
- <TruckIcon className="size-4" />
- {t('admin.pages.orders.detail.claims.actions.resolve_replacement')}
- </DropdownMenuItem>
- </>
- )}
- {claim.status === 'open' && (
- <DropdownMenuItem onClick={() => deny.mutate({ claimId: claim.id })}>
- <XCircleIcon className="size-4" />
- {t('admin.pages.orders.detail.claims.actions.deny')}
- </DropdownMenuItem>
- )}
- {['open', 'approved'].includes(claim.status) && (
- <>
- <DropdownMenuSeparator />
- <DropdownMenuItem
- className="text-destructive focus:text-destructive"
- onClick={async () => {
- if (
- await confirm({
- message: t('admin.pages.orders.detail.returns.confirm.cancel'),
- variant: 'destructive',
- confirmLabel: t('admin.actions.cancel'),
- })
- ) {
- cancel.mutate({ claimId: claim.id })
+ )}
+ {claim.status === 'approved' && (
+ <>
+ <DropdownMenuItem
+ onClick={() =>
+ resolve.mutate({ claimId: claim.id, resolution: 'refund' })
}
- }}
- >
+ >
+ <BanknoteIcon className="size-4" />
+ {t('admin.pages.orders.detail.claims.actions.resolve_refund')}
+ </DropdownMenuItem>
+ <DropdownMenuItem
+ onClick={() =>
+ resolve.mutate({ claimId: claim.id, resolution: 'replacement' })
+ }
+ >
+ <TruckIcon className="size-4" />
+ {t('admin.pages.orders.detail.claims.actions.resolve_replacement')}
+ </DropdownMenuItem>
+ </>
+ )}
+ {claim.status === 'open' && (
+ <DropdownMenuItem onClick={() => deny.mutate({ claimId: claim.id })}>
<XCircleIcon className="size-4" />
- {t('admin.actions.cancel')}
+ {t('admin.pages.orders.detail.claims.actions.deny')}
</DropdownMenuItem>
- </>
- )}
- </DropdownMenuContent>
- </DropdownMenu>
- </div>
-
- <div className="flex flex-col gap-1.5">
- {(claim.claim_line_items ?? []).map((line) => (
- <div key={line.id} className="flex items-center justify-between text-sm">
- <span className="truncate">
- {line.variant?.product_name ?? line.variant_id}
- {line.description && (
- <span className="text-muted-foreground"> — {line.description}</span>
)}
- </span>
- <span className="text-muted-foreground">×{line.quantity}</span>
- </div>
- ))}
- </div>
+ {['open', 'approved'].includes(claim.status) && (
+ <>
+ <DropdownMenuSeparator />
+ <DropdownMenuItem
+ className="text-destructive focus:text-destructive"
+ onClick={async () => {
+ if (
+ await confirm({
+ message: t('admin.pages.orders.detail.returns.confirm.cancel'),
+ variant: 'destructive',
+ confirmLabel: t('admin.actions.cancel'),
+ })
+ ) {
+ cancel.mutate({ claimId: claim.id })
+ }
+ }}
+ >
+ <XCircleIcon className="size-4" />
+ {t('admin.actions.cancel')}
+ </DropdownMenuItem>
+ </>
+ )}
+ </DropdownMenuContent>
+ </DropdownMenu>
+ </div>
- <div className="flex items-center justify-between text-sm border-t pt-3">
- <span className="text-muted-foreground">
- {t('admin.pages.orders.detail.returns.refund_total')}
- </span>
- <span className="font-medium">{claim.display_refund_total}</span>
+ <div className="flex flex-col gap-1.5">
+ {(claim.claim_line_items ?? []).map((line) => (
+ <div key={line.id} className="flex items-center justify-between text-sm">
+ <span className="truncate">
+ {line.variant?.product_name ?? line.variant_id}
+ {line.description && (
+ <span className="text-muted-foreground"> — {line.description}</span>
+ )}
+ </span>
+ <span className="text-muted-foreground">×{line.quantity}</span>
+ </div>
+ ))}
+ </div>
+
+ <div className="flex items-center justify-between text-sm border-t pt-3">
+ <span className="text-muted-foreground">
+ {t('admin.pages.orders.detail.returns.refund_total')}
+ </span>
+ <span className="font-medium">{claim.display_refund_total}</span>
+ </div>
</div>
- </div>
- ))}
- </CardContent>
- </Card>
+ ))}
+ </CardContent>
+ </Card>
+
+ {creatingClaim && (
+ <CreateClaimDialog
+ order={order}
+ onClose={() => setCreatingClaim(false)}
+ onSubmit={(params) => {
+ create.mutate(params)
+ setCreatingClaim(false)
+ }}
+ />
+ )}
+ </>
)
}
diff --git a/packages/dashboard/src/components/spree/order-returns-card.tsx b/packages/dashboard/src/components/spree/order-returns-card.tsx
index da3819de42..c6fab09d54 100644
--- a/packages/dashboard/src/components/spree/order-returns-card.tsx
+++ b/packages/dashboard/src/components/spree/order-returns-card.tsx
@@ -1,8 +1,9 @@
-import type { Return, ReturnLineItem } from '@spree/admin-sdk'
+import type { Order, Return, ReturnLineItem } from '@spree/admin-sdk'
import {
Badge,
Button,
Card,
+ CardAction,
CardContent,
CardHeader,
CardTitle,
@@ -34,12 +35,14 @@ import {
CheckCircleIcon,
EllipsisVerticalIcon,
PackageCheckIcon,
+ PlusIcon,
RotateCcwIcon,
XCircleIcon,
} from 'lucide-react'
import { useState } from 'react'
import { useTranslation } from 'react-i18next'
import { useOrderReturns, useReturnActions } from '../../hooks/use-returns'
+import { CreateReturnDialog, fulfilledUnits } from './post-sale-create-dialogs'
type ReceiptRow = { quantity: number; resellable: boolean }
@@ -58,17 +61,19 @@ function variantLabel(line: ReturnLineItem): string {
* receiving records what actually arrived, refunding picks where the money
* goes.
*/
-export function OrderReturnsCard({ orderId }: { orderId: string }) {
+export function OrderReturnsCard({ order }: { order: Order }) {
+ const orderId = order.id
const { t } = useTranslation()
const confirm = useConfirm()
const { data } = useOrderReturns(orderId)
- const { approve, receive, refund, cancel } = useReturnActions(orderId)
+ const { create, approve, receive, refund, cancel } = useReturnActions(orderId)
+ const [creating, setCreating] = useState(false)
const [receiving, setReceiving] = useState<Return | null>(null)
const [refunding, setRefunding] = useState<Return | null>(null)
const returns = data?.data ?? []
- if (returns.length === 0) return null
+ const canCreate = fulfilledUnits(order).length > 0
return (
<>
@@ -77,10 +82,25 @@ export function OrderReturnsCard({ orderId }: { orderId: string }) {
<CardTitle>
<RotateCcwIcon className="size-4" />
{t('admin.pages.orders.detail.section_returns')}
- <Badge variant="outline">{returns.length}</Badge>
+ {returns.length > 0 && <Badge variant="outline">{returns.length}</Badge>}
</CardTitle>
+ {canCreate && (
+ <CardAction>
+ <Button variant="outline" size="sm" onClick={() => setCreating(true)}>
+ <PlusIcon className="size-4" />
+ {t('admin.pages.orders.detail.returns.actions.create')}
+ </Button>
+ </CardAction>
+ )}
</CardHeader>
<CardContent className="flex flex-col gap-4">
+ {returns.length === 0 && (
+ <p className="text-sm text-muted-foreground">
+ {canCreate
+ ? t('admin.pages.orders.detail.returns.empty')
+ : t('admin.pages.orders.detail.returns.empty_nothing_fulfilled')}
+ </p>
+ )}
{returns.map((returnRecord) => (
<div key={returnRecord.id} className="rounded-lg border p-4 flex flex-col gap-3">
<div className="flex items-center justify-between">
@@ -157,6 +177,17 @@ export function OrderReturnsCard({ orderId }: { orderId: string }) {
</CardContent>
</Card>
+ {creating && (
+ <CreateReturnDialog
+ order={order}
+ onClose={() => setCreating(false)}
+ onSubmit={(params) => {
+ create.mutate(params)
+ setCreating(false)
+ }}
+ />
+ )}
+
{receiving && (
<ReceiveDialog
returnRecord={receiving}
diff --git a/packages/dashboard/src/components/spree/post-sale-create-dialogs.tsx b/packages/dashboard/src/components/spree/post-sale-create-dialogs.tsx
new file mode 100644
index 0000000000..a0d866396b
--- /dev/null
+++ b/packages/dashboard/src/components/spree/post-sale-create-dialogs.tsx
@@ -0,0 +1,347 @@
+import type { Order } from '@spree/admin-sdk'
+import {
+ Button,
+ Dialog,
+ DialogBody,
+ DialogContent,
+ DialogFooter,
+ DialogHeader,
+ DialogTitle,
+ Field,
+ FieldLabel,
+ Input,
+ Select,
+ SelectContent,
+ SelectItem,
+ SelectTrigger,
+ SelectValue,
+ Textarea,
+} from '@spree/dashboard-ui'
+import { useState } from 'react'
+import { useTranslation } from 'react-i18next'
+
+/** A fulfilled unit the customer could send back. */
+export type FulfilledUnit = {
+ id: string
+ label: string
+ quantity: number
+}
+
+/**
+ * Every fulfilled unit on the order, flattened out of its fulfillments —
+ * a return or exchange is against a shipped unit, not a line item.
+ */
+export function fulfilledUnits(order: Order): FulfilledUnit[] {
+ return (order.fulfillments ?? []).flatMap((fulfillment) =>
+ (fulfillment.fulfillment_items ?? []).map((item) => ({
+ id: item.id,
+ label: [item.name, item.options_text].filter(Boolean).join(' — ') || item.id,
+ quantity: item.quantity,
+ })),
+ )
+}
+
+type Selection = Record<string, number>
+
+/** Shared item picker: a quantity per unit, zero meaning "not included". */
+function QuantityPicker({
+ units,
+ selection,
+ onChange,
+}: {
+ units: Array<{ id: string; label: string; quantity: number }>
+ selection: Selection
+ onChange: (selection: Selection) => void
+}) {
+ return (
+ <div className="flex flex-col gap-2">
+ {units.map((unit) => (
+ <div
+ key={unit.id}
+ className="flex items-center justify-between gap-4 rounded-lg border p-3"
+ >
+ <span className="text-sm truncate">{unit.label}</span>
+ <Input
+ type="number"
+ min={0}
+ max={unit.quantity}
+ className="w-20"
+ value={selection[unit.id] ?? 0}
+ onChange={(event) =>
+ onChange({
+ ...selection,
+ [unit.id]: Math.max(0, Math.min(Number(event.target.value), unit.quantity)),
+ })
+ }
+ />
+ </div>
+ ))}
+ </div>
+ )
+}
+
+function selectedItems(selection: Selection): Array<[string, number]> {
+ return Object.entries(selection).filter(([, quantity]) => quantity > 0)
+}
+
+export function CreateReturnDialog({
+ order,
+ onClose,
+ onSubmit,
+}: {
+ order: Order
+ onClose: () => void
+ onSubmit: (params: {
+ items: Array<{ fulfillment_item_id: string; quantity: number }>
+ memo?: string
+ }) => void
+}) {
+ const { t } = useTranslation()
+ const units = fulfilledUnits(order)
+ const [selection, setSelection] = useState<Selection>({})
+ const [memo, setMemo] = useState('')
+
+ const chosen = selectedItems(selection)
+
+ return (
+ <Dialog open onOpenChange={(open) => !open && onClose()}>
+ <DialogContent>
+ <DialogHeader>
+ <DialogTitle>{t('admin.pages.orders.detail.returns.create_title')}</DialogTitle>
+ </DialogHeader>
+ <DialogBody className="flex flex-col gap-4">
+ <QuantityPicker units={units} selection={selection} onChange={setSelection} />
+ <Field>
+ <FieldLabel htmlFor="return-memo">
+ {t('admin.pages.orders.detail.returns.memo')}
+ </FieldLabel>
+ <Textarea
+ id="return-memo"
+ value={memo}
+ onChange={(event) => setMemo(event.target.value)}
+ />
+ </Field>
+ </DialogBody>
+ <DialogFooter>
+ <Button variant="outline" onClick={onClose}>
+ {t('admin.actions.cancel')}
+ </Button>
+ <Button
+ disabled={chosen.length === 0}
+ onClick={() =>
+ onSubmit({
+ items: chosen.map(([id, quantity]) => ({
+ fulfillment_item_id: id,
+ quantity,
+ })),
+ memo: memo || undefined,
+ })
+ }
+ >
+ {t('admin.pages.orders.detail.returns.actions.create')}
+ </Button>
+ </DialogFooter>
+ </DialogContent>
+ </Dialog>
+ )
+}
+
+/**
+ * An exchange needs a replacement variant per unit. The variant is entered by
+ * prefixed id rather than picked from a catalog browser — a full product
+ * picker is worth building, but this keeps the flow usable meanwhile.
+ */
+export function CreateExchangeDialog({
+ order,
+ onClose,
+ onSubmit,
+}: {
+ order: Order
+ onClose: () => void
+ onSubmit: (params: {
+ items: Array<{ fulfillment_item_id: string; new_variant_id: string; quantity: number }>
+ memo?: string
+ }) => void
+}) {
+ const { t } = useTranslation()
+ const units = fulfilledUnits(order)
+ const [selection, setSelection] = useState<Selection>({})
+ const [replacements, setReplacements] = useState<Record<string, string>>({})
+ const [memo, setMemo] = useState('')
+
+ const chosen = selectedItems(selection)
+ const ready = chosen.length > 0 && chosen.every(([id]) => replacements[id]?.trim())
+
+ return (
+ <Dialog open onOpenChange={(open) => !open && onClose()}>
+ <DialogContent>
+ <DialogHeader>
+ <DialogTitle>{t('admin.pages.orders.detail.exchanges.create_title')}</DialogTitle>
+ </DialogHeader>
+ <DialogBody className="flex flex-col gap-4">
+ {units.map((unit) => (
+ <div key={unit.id} className="flex flex-col gap-2 rounded-lg border p-3">
+ <div className="flex items-center justify-between gap-4">
+ <span className="text-sm truncate">{unit.label}</span>
+ <Input
+ type="number"
+ min={0}
+ max={unit.quantity}
+ className="w-20"
+ value={selection[unit.id] ?? 0}
+ onChange={(event) =>
+ setSelection({
+ ...selection,
+ [unit.id]: Math.max(0, Math.min(Number(event.target.value), unit.quantity)),
+ })
+ }
+ />
+ </div>
+ {(selection[unit.id] ?? 0) > 0 && (
+ <Field>
+ <FieldLabel htmlFor={`replacement-${unit.id}`}>
+ {t('admin.pages.orders.detail.exchanges.replacement_variant')}
+ </FieldLabel>
+ <Input
+ id={`replacement-${unit.id}`}
+ placeholder="variant_..."
+ value={replacements[unit.id] ?? ''}
+ onChange={(event) =>
+ setReplacements({ ...replacements, [unit.id]: event.target.value })
+ }
+ />
+ </Field>
+ )}
+ </div>
+ ))}
+ <Field>
+ <FieldLabel htmlFor="exchange-memo">
+ {t('admin.pages.orders.detail.returns.memo')}
+ </FieldLabel>
+ <Textarea
+ id="exchange-memo"
+ value={memo}
+ onChange={(event) => setMemo(event.target.value)}
+ />
+ </Field>
+ </DialogBody>
+ <DialogFooter>
+ <Button variant="outline" onClick={onClose}>
+ {t('admin.actions.cancel')}
+ </Button>
+ <Button
+ disabled={!ready}
+ onClick={() =>
+ onSubmit({
+ items: chosen.map(([id, quantity]) => ({
+ fulfillment_item_id: id,
+ new_variant_id: replacements[id].trim(),
+ quantity,
+ })),
+ memo: memo || undefined,
+ })
+ }
+ >
+ {t('admin.pages.orders.detail.exchanges.actions.create')}
+ </Button>
+ </DialogFooter>
+ </DialogContent>
+ </Dialog>
+ )
+}
+
+const CLAIM_TYPES = ['damaged', 'missing', 'wrong_item', 'other'] as const
+
+/** A claim is against ordered line items — nothing has to have shipped. */
+export function CreateClaimDialog({
+ order,
+ onClose,
+ onSubmit,
+}: {
+ order: Order
+ onClose: () => void
+ onSubmit: (params: {
+ items: Array<{ line_item_id: string; quantity: number; description?: string }>
+ claim_type: string
+ memo?: string
+ }) => void
+}) {
+ const { t } = useTranslation()
+ const items = order.items ?? []
+ const [selection, setSelection] = useState<Selection>({})
+ const [claimType, setClaimType] = useState<string>('damaged')
+ const [memo, setMemo] = useState('')
+
+ const chosen = selectedItems(selection)
+ const typeOptions = CLAIM_TYPES.map((value) => ({
+ value,
+ label: t(`admin.pages.orders.detail.claims.types.${value}`),
+ }))
+
+ return (
+ <Dialog open onOpenChange={(open) => !open && onClose()}>
+ <DialogContent>
+ <DialogHeader>
+ <DialogTitle>{t('admin.pages.orders.detail.claims.create_title')}</DialogTitle>
+ </DialogHeader>
+ <DialogBody className="flex flex-col gap-4">
+ <Field>
+ <FieldLabel htmlFor="claim-type">
+ {t('admin.pages.orders.detail.claims.claim_type')}
+ </FieldLabel>
+ <Select items={typeOptions} value={claimType} onValueChange={setClaimType}>
+ <SelectTrigger id="claim-type">
+ <SelectValue />
+ </SelectTrigger>
+ <SelectContent>
+ {typeOptions.map((option) => (
+ <SelectItem key={option.value} value={option.value}>
+ {option.label}
+ </SelectItem>
+ ))}
+ </SelectContent>
+ </Select>
+ </Field>
+
+ <QuantityPicker
+ units={items.map((item) => ({
+ id: item.id,
+ label: [item.name, item.options_text].filter(Boolean).join(' — ') || item.id,
+ quantity: item.quantity,
+ }))}
+ selection={selection}
+ onChange={setSelection}
+ />
+
+ <Field>
+ <FieldLabel htmlFor="claim-memo">
+ {t('admin.pages.orders.detail.returns.memo')}
+ </FieldLabel>
+ <Textarea
+ id="claim-memo"
+ value={memo}
+ onChange={(event) => setMemo(event.target.value)}
+ />
+ </Field>
+ </DialogBody>
+ <DialogFooter>
+ <Button variant="outline" onClick={onClose}>
+ {t('admin.actions.cancel')}
+ </Button>
+ <Button
+ disabled={chosen.length === 0}
+ onClick={() =>
+ onSubmit({
+ items: chosen.map(([id, quantity]) => ({ line_item_id: id, quantity })),
+ claim_type: claimType,
+ memo: memo || undefined,
+ })
+ }
+ >
+ {t('admin.pages.orders.detail.claims.actions.create')}
+ </Button>
+ </DialogFooter>
+ </DialogContent>
+ </Dialog>
+ )
+}
diff --git a/packages/dashboard/src/hooks/use-order.ts b/packages/dashboard/src/hooks/use-order.ts
index 83fe03b095..b5875f1401 100644
--- a/packages/dashboard/src/hooks/use-order.ts
+++ b/packages/dashboard/src/hooks/use-order.ts
@@ -9,6 +9,7 @@ export function useOrder(orderId: string) {
expand: [
'items',
'fulfillments',
+ 'fulfillments.fulfillment_items',
'fulfillments.delivery_method',
'fulfillments.stock_location',
'payments',
diff --git a/packages/dashboard/src/hooks/use-post-sale.ts b/packages/dashboard/src/hooks/use-post-sale.ts
index 08fac58d95..7f87e8ae46 100644
--- a/packages/dashboard/src/hooks/use-post-sale.ts
+++ b/packages/dashboard/src/hooks/use-post-sale.ts
@@ -53,6 +53,15 @@ function usePostSaleMutation<TParams>(
}
export function useExchangeActions(orderId: string) {
+ const create = usePostSaleMutation(
+ orderId,
+ 'order-exchanges',
+ (params: {
+ items: Array<{ fulfillment_item_id: string; new_variant_id: string; quantity: number }>
+ memo?: string
+ }) => adminClient.orders.exchanges.create(orderId, params),
+ )
+
const approve = usePostSaleMutation(orderId, 'order-exchanges', (exchangeId: string) =>
adminClient.orders.exchanges.approve(orderId, exchangeId),
)
@@ -89,10 +98,20 @@ export function useExchangeActions(orderId: string) {
adminClient.orders.exchanges.cancel(orderId, exchangeId, { reason }),
)
- return { approve, receive, fulfill, cancel }
+ return { create, approve, receive, fulfill, cancel }
}
export function useClaimActions(orderId: string) {
+ const create = usePostSaleMutation(
+ orderId,
+ 'order-claims',
+ (params: {
+ items: Array<{ line_item_id: string; quantity: number; description?: string }>
+ claim_type: string
+ memo?: string
+ }) => adminClient.orders.claims.create(orderId, params),
+ )
+
const approve = usePostSaleMutation(orderId, 'order-claims', (claimId: string) =>
adminClient.orders.claims.approve(orderId, claimId),
)
@@ -132,5 +151,5 @@ export function useClaimActions(orderId: string) {
adminClient.orders.claims.cancel(orderId, claimId, { reason }),
)
- return { approve, resolve, deny, cancel }
+ return { create, approve, resolve, deny, cancel }
}
diff --git a/packages/dashboard/src/hooks/use-returns.ts b/packages/dashboard/src/hooks/use-returns.ts
index d82ce9f16d..f574c2338f 100644
--- a/packages/dashboard/src/hooks/use-returns.ts
+++ b/packages/dashboard/src/hooks/use-returns.ts
@@ -42,6 +42,14 @@ function useReturnMutation<TParams>(
* refunding takes a method and an amount.
*/
export function useReturnActions(orderId: string) {
+ // Opens as 'requested' — identical to how a customer-filed return starts,
+ // so staff-created and self-service returns share one path.
+ const create = useReturnMutation(
+ orderId,
+ (params: { items: Array<{ fulfillment_item_id: string; quantity: number }>; memo?: string }) =>
+ adminClient.orders.returns.create(orderId, params),
+ )
+
const approve = useReturnMutation(orderId, (returnId: string) =>
adminClient.orders.returns.approve(orderId, returnId),
)
@@ -80,5 +88,5 @@ export function useReturnActions(orderId: string) {
adminClient.orders.returns.cancel(orderId, returnId, { reason }),
)
- return { approve, receive, refund, cancel }
+ return { create, approve, receive, refund, cancel }
}
diff --git a/packages/dashboard/src/locales/ar.json b/packages/dashboard/src/locales/ar.json
index e99f416b81..2e80c914eb 100644
--- a/packages/dashboard/src/locales/ar.json
+++ b/packages/dashboard/src/locales/ar.json
@@ -1704,14 +1704,18 @@
"actions": {
"resolve_refund": "الحل بالاسترداد",
"resolve_replacement": "الحل بالاستبدال",
- "deny": "رفض"
+ "deny": "رفض",
+ "create": "مطالبة جديدة"
},
"types": {
"damaged": "تالف",
"missing": "مفقود",
"wrong_item": "منتج خاطئ",
"other": "أخرى"
- }
+ },
+ "empty": "لا توجد مطالبات لهذا الطلب.",
+ "create_title": "مطالبة جديدة",
+ "claim_type": "المشكلة"
},
"dialogs": {
"approve_title": "الموافقة على الطلب؟",
@@ -1723,16 +1727,21 @@
"empty_shipments": "لا توجد شحنات حتى الآن.",
"exchanges": {
"actions": {
- "fulfill": "شحن البديل"
+ "fulfill": "شحن البديل",
+ "create": "استبدال جديد"
},
- "price_difference": "فرق السعر"
+ "price_difference": "فرق السعر",
+ "empty": "لا توجد استبدالات لهذا الطلب.",
+ "create_title": "استبدال جديد",
+ "replacement_variant": "معرّف النسخة البديلة"
},
"no_delivery_method": "لم يتم اختيار طريقة توصيل.",
"returns": {
"actions": {
"approve": "موافقة",
"receive": "استلام العناصر",
- "refund": "استرداد"
+ "refund": "استرداد",
+ "create": "مرتجع جديد"
},
"confirm": {
"cancel": "إلغاء هذا المرتجع؟ لن تتم إعادة أي مخزون ولن يتم تحويل أي مبلغ."
@@ -1749,7 +1758,11 @@
"refund_methods": {
"original_payment": "الدفعة الأصلية",
"store_credit": "رصيد المتجر"
- }
+ },
+ "empty": "لا توجد مرتجعات لهذا الطلب.",
+ "empty_nothing_fulfilled": "لم يتم شحن أي شيء في هذا الطلب بعد.",
+ "memo": "ملاحظة",
+ "create_title": "مرتجع جديد"
},
"section_billing_address": "عنوان إرسال الفواتير",
"section_claims": "المطالبات",
diff --git a/packages/dashboard/src/locales/de.json b/packages/dashboard/src/locales/de.json
index a0ae98e176..d62cebc3aa 100644
--- a/packages/dashboard/src/locales/de.json
+++ b/packages/dashboard/src/locales/de.json
@@ -1704,14 +1704,18 @@
"actions": {
"resolve_refund": "Mit Erstattung lösen",
"resolve_replacement": "Mit Ersatz lösen",
- "deny": "Ablehnen"
+ "deny": "Ablehnen",
+ "create": "Neue Reklamation"
},
"types": {
"damaged": "Beschädigt",
"missing": "Fehlt",
"wrong_item": "Falscher Artikel",
"other": "Sonstiges"
- }
+ },
+ "empty": "Keine Reklamationen für diese Bestellung.",
+ "create_title": "Neue Reklamation",
+ "claim_type": "Problem"
},
"dialogs": {
"approve_title": "Bestellung genehmigen?",
@@ -1723,16 +1727,21 @@
"empty_shipments": "Noch keine Sendungen.",
"exchanges": {
"actions": {
- "fulfill": "Ersatz versenden"
+ "fulfill": "Ersatz versenden",
+ "create": "Neuer Umtausch"
},
- "price_difference": "Preisdifferenz"
+ "price_difference": "Preisdifferenz",
+ "empty": "Kein Umtausch für diese Bestellung.",
+ "create_title": "Neuer Umtausch",
+ "replacement_variant": "Varianten-ID des Ersatzes"
},
"no_delivery_method": "Keine Versandmethode ausgewählt.",
"returns": {
"actions": {
"approve": "Genehmigen",
"receive": "Artikel annehmen",
- "refund": "Erstatten"
+ "refund": "Erstatten",
+ "create": "Neue Retoure"
},
"confirm": {
"cancel": "Diese Retoure stornieren? Es wird nichts eingelagert und kein Geld bewegt."
@@ -1749,7 +1758,11 @@
"refund_methods": {
"original_payment": "Ursprüngliche Zahlung",
"store_credit": "Guthaben"
- }
+ },
+ "empty": "Keine Retouren für diese Bestellung.",
+ "empty_nothing_fulfilled": "Für diese Bestellung wurde noch nichts versandt.",
+ "memo": "Notiz",
+ "create_title": "Neue Retoure"
},
"section_billing_address": "Rechnungsadresse",
"section_claims": "Reklamationen",
diff --git a/packages/dashboard/src/locales/en.json b/packages/dashboard/src/locales/en.json
index 180b252b9f..2535768347 100644
--- a/packages/dashboard/src/locales/en.json
+++ b/packages/dashboard/src/locales/en.json
@@ -1704,14 +1704,18 @@
"actions": {
"resolve_refund": "Resolve with refund",
"resolve_replacement": "Resolve with replacement",
- "deny": "Deny"
+ "deny": "Deny",
+ "create": "New claim"
},
"types": {
"damaged": "Damaged",
"missing": "Missing",
"wrong_item": "Wrong item",
"other": "Other"
- }
+ },
+ "empty": "No claims for this order.",
+ "create_title": "New claim",
+ "claim_type": "Problem"
},
"dialogs": {
"approve_title": "Approve order?",
@@ -1723,16 +1727,21 @@
"empty_shipments": "No shipments yet.",
"exchanges": {
"actions": {
- "fulfill": "Ship replacement"
+ "fulfill": "Ship replacement",
+ "create": "New exchange"
},
- "price_difference": "Price difference"
+ "price_difference": "Price difference",
+ "empty": "No exchanges for this order.",
+ "create_title": "New exchange",
+ "replacement_variant": "Replacement variant ID"
},
"no_delivery_method": "No delivery method selected.",
"returns": {
"actions": {
"approve": "Approve",
"receive": "Receive items",
- "refund": "Refund"
+ "refund": "Refund",
+ "create": "New return"
},
"confirm": {
"cancel": "Cancel this return? Nothing will be restocked and no money will move."
@@ -1749,7 +1758,11 @@
"refund_methods": {
"original_payment": "Original payment",
"store_credit": "Store credit"
- }
+ },
+ "empty": "No returns for this order.",
+ "empty_nothing_fulfilled": "Nothing has shipped on this order yet.",
+ "memo": "Note",
+ "create_title": "New return"
},
"section_billing_address": "Billing address",
"section_claims": "Claims",
diff --git a/packages/dashboard/src/locales/fr.json b/packages/dashboard/src/locales/fr.json
index 3d1028c216..99080aed82 100644
--- a/packages/dashboard/src/locales/fr.json
+++ b/packages/dashboard/src/locales/fr.json
@@ -1704,14 +1704,18 @@
"actions": {
"resolve_refund": "Résoudre par remboursement",
"resolve_replacement": "Résoudre par remplacement",
- "deny": "Refuser"
+ "deny": "Refuser",
+ "create": "Nouvelle réclamation"
},
"types": {
"damaged": "Endommagé",
"missing": "Manquant",
"wrong_item": "Mauvais article",
"other": "Autre"
- }
+ },
+ "empty": "Aucune réclamation pour cette commande.",
+ "create_title": "Nouvelle réclamation",
+ "claim_type": "Problème"
},
"dialogs": {
"approve_title": "Approuver la commande ?",
@@ -1723,16 +1727,21 @@
"empty_shipments": "Aucune expédition pour le moment.",
"exchanges": {
"actions": {
- "fulfill": "Expédier le remplacement"
+ "fulfill": "Expédier le remplacement",
+ "create": "Nouvel échange"
},
- "price_difference": "Différence de prix"
+ "price_difference": "Différence de prix",
+ "empty": "Aucun échange pour cette commande.",
+ "create_title": "Nouvel échange",
+ "replacement_variant": "ID de la variante de remplacement"
},
"no_delivery_method": "Aucune méthode de livraison sélectionnée.",
"returns": {
"actions": {
"approve": "Approuver",
"receive": "Réceptionner les articles",
- "refund": "Rembourser"
+ "refund": "Rembourser",
+ "create": "Nouveau retour"
},
"confirm": {
"cancel": "Annuler ce retour ? Aucun article ne sera remis en stock et aucun montant ne sera remboursé."
@@ -1749,7 +1758,11 @@
"refund_methods": {
"original_payment": "Paiement d’origine",
"store_credit": "Avoir"
- }
+ },
+ "empty": "Aucun retour pour cette commande.",
+ "empty_nothing_fulfilled": "Rien n’a encore été expédié pour cette commande.",
+ "memo": "Note",
+ "create_title": "Nouveau retour"
},
"section_billing_address": "Adresse de facturation",
"section_claims": "Réclamations",
diff --git a/packages/dashboard/src/locales/pl.json b/packages/dashboard/src/locales/pl.json
index 16c13700f7..4e134b5306 100644
--- a/packages/dashboard/src/locales/pl.json
+++ b/packages/dashboard/src/locales/pl.json
@@ -1712,14 +1712,18 @@
"actions": {
"resolve_refund": "Rozwiąż zwrotem płatności",
"resolve_replacement": "Rozwiąż zamiennikiem",
- "deny": "Odrzuć"
+ "deny": "Odrzuć",
+ "create": "Nowa reklamacja"
},
"types": {
"damaged": "Uszkodzony",
"missing": "Brakujący",
"wrong_item": "Niewłaściwy produkt",
"other": "Inne"
- }
+ },
+ "empty": "Brak reklamacji dla tego zamówienia.",
+ "create_title": "Nowa reklamacja",
+ "claim_type": "Problem"
},
"dialogs": {
"approve_title": "Zatwierdzić zamówienie?",
@@ -1731,16 +1735,21 @@
"empty_shipments": "Brak przesyłek.",
"exchanges": {
"actions": {
- "fulfill": "Wyślij zamiennik"
+ "fulfill": "Wyślij zamiennik",
+ "create": "Nowa wymiana"
},
- "price_difference": "Różnica w cenie"
+ "price_difference": "Różnica w cenie",
+ "empty": "Brak wymian dla tego zamówienia.",
+ "create_title": "Nowa wymiana",
+ "replacement_variant": "ID wariantu zamiennego"
},
"no_delivery_method": "Nie wybrano metody dostawy.",
"returns": {
"actions": {
"approve": "Zatwierdź",
"receive": "Przyjmij produkty",
- "refund": "Zwróć płatność"
+ "refund": "Zwróć płatność",
+ "create": "Nowy zwrot"
},
"confirm": {
"cancel": "Anulować ten zwrot? Nic nie wróci do magazynu i żadne pieniądze nie zostaną zwrócone."
@@ -1757,7 +1766,11 @@
"refund_methods": {
"original_payment": "Pierwotna płatność",
"store_credit": "Kredyt sklepowy"
- }
+ },
+ "empty": "Brak zwrotów dla tego zamówienia.",
+ "empty_nothing_fulfilled": "Nic jeszcze nie zostało wysłane w tym zamówieniu.",
+ "memo": "Notatka",
+ "create_title": "Nowy zwrot"
},
"section_billing_address": "Adres rozliczeniowy",
"section_claims": "Reklamacje",
diff --git a/packages/dashboard/src/locales/zh-CN.json b/packages/dashboard/src/locales/zh-CN.json
index 571b62b4b4..59b8dfef5d 100644
--- a/packages/dashboard/src/locales/zh-CN.json
+++ b/packages/dashboard/src/locales/zh-CN.json
@@ -1704,14 +1704,18 @@
"actions": {
"resolve_refund": "以退款解决",
"resolve_replacement": "以换货解决",
- "deny": "拒绝"
+ "deny": "拒绝",
+ "create": "新建索赔"
},
"types": {
"damaged": "已损坏",
"missing": "缺失",
"wrong_item": "商品错误",
"other": "其他"
- }
+ },
+ "empty": "此订单暂无索赔。",
+ "create_title": "新建索赔",
+ "claim_type": "问题"
},
"dialogs": {
"approve_title": "批准订单?",
@@ -1723,16 +1727,21 @@
"empty_shipments": "暂无发货。",
"exchanges": {
"actions": {
- "fulfill": "寄出替换商品"
+ "fulfill": "寄出替换商品",
+ "create": "新建换货"
},
- "price_difference": "差价"
+ "price_difference": "差价",
+ "empty": "此订单暂无换货。",
+ "create_title": "新建换货",
+ "replacement_variant": "替换变体 ID"
},
"no_delivery_method": "未选择配送方式。",
"returns": {
"actions": {
"approve": "批准",
"receive": "接收商品",
- "refund": "退款"
+ "refund": "退款",
+ "create": "新建退货"
},
"confirm": {
"cancel": "取消此退货?不会恢复库存,也不会退款。"
@@ -1749,7 +1758,11 @@
"refund_methods": {
"original_payment": "原支付方式",
"store_credit": "商店积分"
- }
+ },
+ "empty": "此订单暂无退货。",
+ "empty_nothing_fulfilled": "此订单尚未发货。",
+ "memo": "备注",
+ "create_title": "新建退货"
},
"section_billing_address": "账单地址",
"section_claims": "索赔",
diff --git a/packages/dashboard/src/routes/_authenticated/$storeId/orders/$orderId.tsx b/packages/dashboard/src/routes/_authenticated/$storeId/orders/$orderId.tsx
index 4c43ef6ae9..abb13d1d11 100644
--- a/packages/dashboard/src/routes/_authenticated/$storeId/orders/$orderId.tsx
+++ b/packages/dashboard/src/routes/_authenticated/$storeId/orders/$orderId.tsx
@@ -152,9 +152,9 @@ function OrderDetailPage() {
<>
<LineItemsCard order={order} />
<FulfillmentsCard order={order} />
- <OrderReturnsCard orderId={orderId} />
- <OrderExchangesCard orderId={orderId} />
- <OrderClaimsCard orderId={orderId} />
+ <OrderReturnsCard order={order} />
+ <OrderExchangesCard order={order} />
+ <OrderClaimsCard order={order} />
<PaymentsCard order={order} />
<AdjustmentLinesCard order={order} />
<OrderSummaryCard order={order} />
diff --git a/spree/api/app/serializers/spree/api/v3/admin/fulfillment_item_serializer.rb b/spree/api/app/serializers/spree/api/v3/admin/fulfillment_item_serializer.rb
new file mode 100644
index 0000000000..4dafff27ed
--- /dev/null
+++ b/spree/api/app/serializers/spree/api/v3/admin/fulfillment_item_serializer.rb
@@ -0,0 +1,39 @@
+# frozen_string_literal: true
+
+module Spree
+ module Api
+ module V3
+ module Admin
+ # A fulfilled unit. Admin-only: it exists so the dashboard can offer
+ # what is actually returnable or exchangeable — a return is against a
+ # shipped unit, not against a line item.
+ class FulfillmentItemSerializer < BaseSerializer
+ typelize quantity: :number,
+ status: :string,
+ variant_id: [:string, nullable: true],
+ line_item_id: [:string, nullable: true],
+ name: [:string, nullable: true],
+ options_text: [:string, nullable: true]
+
+ attributes :quantity, :status
+
+ attribute :variant_id do |item|
+ item.variant&.prefixed_id
+ end
+
+ attribute :line_item_id do |item|
+ item.line_item&.prefixed_id
+ end
+
+ attribute :name do |item|
+ item.variant&.product&.name
+ end
+
+ attribute :options_text do |item|
+ item.variant&.options_text
+ end
+ end
+ end
+ end
+ end
+end
diff --git a/spree/api/app/serializers/spree/api/v3/admin/fulfillment_serializer.rb b/spree/api/app/serializers/spree/api/v3/admin/fulfillment_serializer.rb
index 1a7850e0c1..19b5366daa 100644
--- a/spree/api/app/serializers/spree/api/v3/admin/fulfillment_serializer.rb
+++ b/spree/api/app/serializers/spree/api/v3/admin/fulfillment_serializer.rb
@@ -34,6 +34,12 @@ module Spree
one :stock_location, resource: proc { Spree.api.admin_stock_location_serializer }, if: proc { expand?('stock_location') }
many :delivery_rates, resource: proc { Spree.api.admin_delivery_rate_serializer }, if: proc { expand?('delivery_rates') }
+ # The units in this fulfillment — the dashboard needs them to offer
+ # what can actually be returned or exchanged.
+ many :fulfillment_items,
+ resource: proc { Spree.api.admin_fulfillment_item_serializer },
+ if: proc { expand?('fulfillment_items') }
+
one :order,
resource: proc { Spree.api.admin_order_serializer },
if: proc { expand?('order') }
diff --git a/spree/api/lib/spree/api/dependencies.rb b/spree/api/lib/spree/api/dependencies.rb
index d67d9bc73c..d38ada6142 100644
--- a/spree/api/lib/spree/api/dependencies.rb
+++ b/spree/api/lib/spree/api/dependencies.rb
@@ -126,6 +126,7 @@ module Spree
admin_stock_transfer_serializer: 'Spree::Api::V3::Admin::StockTransferSerializer',
admin_shipment_serializer: 'Spree::Api::V3::Admin::FulfillmentSerializer',
admin_fulfillment_serializer: 'Spree::Api::V3::Admin::FulfillmentSerializer',
+ admin_fulfillment_item_serializer: 'Spree::Api::V3::Admin::FulfillmentItemSerializer',
admin_gift_card_serializer: 'Spree::Api::V3::Admin::GiftCardSerializer',
admin_gift_card_batch_serializer: 'Spree::Api::V3::Admin::GiftCardBatchSerializer',
admin_payment_serializer: 'Spree::Api::V3::Admin::PaymentSerializer',