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.
Ruby b2b-commercee-commerceecommerceecommerce-apiecommerce-frameworkecommerce-platformheadlessheadless-commerceheadless-ecommercemarketplacemulti-tenantmulti-vendormulti-vendor-ecommerceopen-sourcespree-commerce
Share the post-sale dialogs between both panels
Damian Legawiece6b39fcc5912
diff --git a/packages/dashboard-ui/src/index.ts b/packages/dashboard-ui/src/index.tsindex e13ac61728..8953a8dc55 100644--- a/packages/dashboard-ui/src/index.ts+++ b/packages/dashboard-ui/src/index.ts@@ -31,6 +31,7 @@ export * from './spree/bulk-dialog'export * from './spree/bulk-price-table'export * from './spree/bulk-variants-table'export * from './spree/calculator-summary'+export * from './spree/claim-resolve-dialog'export * from './spree/color-picker'export * from './spree/confirm-dialog'export * from './spree/copy-to-clipboard-button'@@ -44,6 +45,8 @@ export * from './spree/fulfill-items-form'export * from './spree/fulfillment-edit-dialog'export * from './spree/fulfillment-item-list'export * from './spree/fulfillment-panel'+export * from './spree/post-sale-fields'+export * from './spree/return-dialogs'// JsonPreviewDrawer and JsonValueView are intentionally NOT re-exported from// this barrel: they pull in `@uiw/react-json-view` (~30KB gzip), anddiff --git a/packages/dashboard-ui/src/spree/claim-resolve-dialog.tsx b/packages/dashboard-ui/src/spree/claim-resolve-dialog.tsxnew file mode 100644index 0000000000..dadcf11b69--- /dev/null+++ b/packages/dashboard-ui/src/spree/claim-resolve-dialog.tsx@@ -0,0 +1,218 @@+import { useState } from 'react'+import { useTranslation } from 'react-i18next'+import { Button } from '../ui/button'+import {+ Dialog,+ DialogBody,+ DialogContent,+ DialogFooter,+ DialogHeader,+ DialogTitle,+} from '../ui/dialog'+import { Field, FieldLabel } from '../ui/field'+import { InputGroup, InputGroupAddon, InputGroupInput, InputGroupText } from '../ui/input-group'+import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue } from '../ui/select'+import { Switch } from '../ui/switch'+import type { RefundMethod } from './return-dialogs'++/** How a claim is settled. */+export type ClaimResolution = 'refund' | 'replacement' | 'refund_and_replacement'++/** One claimed line, as the resolve form needs it. */+export type ClaimLineForResolve = {+ id: string+ label: string+ quantity: number+ /** Whether the claim was opened asking for this line to be replaced. */+ sendReplacement: boolean+}++/**+ * Settles a claim: money back, a replacement shipment, or both.+ *+ * The resolution is chosen here rather than at claim creation, so the+ * merchant decides how to make things right once they have the facts. The+ * currency symbol comes from the caller — the operator reads it from the+ * store, and a seller has no currency of their own.+ *+ * Shared by the operator's order page and the seller's.+ */+export function ClaimResolveDialog({+ lines,+ defaultAmount,+ currencySymbol,+ onClose,+ onSubmit,+ pending = false,+}: {+ lines: ClaimLineForResolve[]+ /** What to offer as the refund, already resolved by the caller. */+ defaultAmount: string+ currencySymbol: string+ onClose: () => void+ onSubmit: (params: {+ resolution: ClaimResolution+ refundMethod: RefundMethod+ amount?: string+ replacementLineItemIds: string[]+ }) => void+ pending?: boolean+}) {+ const { t } = useTranslation()++ const [resolution, setResolution] = useState<ClaimResolution>('refund')+ const [refundMethod, setRefundMethod] = useState<RefundMethod>('store_credit')+ const [amount, setAmount] = useState(defaultAmount)+ const [replacing, setReplacing] = useState<Record<string, boolean>>(() =>+ Object.fromEntries(lines.map((line) => [line.id, line.sendReplacement])),+ )++ const refunding = resolution.includes('refund')+ const sendingReplacement = resolution.includes('replacement')+ const chosenReplacements = Object.entries(replacing)+ .filter(([, on]) => on)+ .map(([id]) => id)++ const resolutionOptions = (['refund', 'replacement', 'refund_and_replacement'] as const).map(+ (value) => ({+ value,+ label: t(`admin.pages.orders.detail.claims.resolutions.${value}`),+ }),+ )++ const methodOptions = [+ {+ value: 'store_credit',+ label: t('admin.pages.orders.detail.returns.refund_methods.store_credit'),+ },+ {+ value: 'original_payment',+ label: t('admin.pages.orders.detail.returns.refund_methods.original_payment'),+ },+ ]++ // Refunding nothing, or replacing nothing, is what the server rejects —+ // say so here instead of letting the request fail.+ const ready =+ (!refunding || Number(amount) > 0) && (!sendingReplacement || chosenReplacements.length > 0)++ return (+ <Dialog open onOpenChange={(open) => !open && onClose()}>+ <DialogContent>+ <DialogHeader>+ <DialogTitle>{t('admin.pages.orders.detail.claims.resolve_title')}</DialogTitle>+ </DialogHeader>+ <DialogBody className="flex flex-col gap-4">+ <Field>+ <FieldLabel htmlFor="claim-resolution">+ {t('admin.pages.orders.detail.claims.resolution')}+ </FieldLabel>+ <Select+ items={resolutionOptions}+ value={resolution}+ onValueChange={(value) => setResolution(value as ClaimResolution)}+ >+ <SelectTrigger id="claim-resolution">+ <SelectValue />+ </SelectTrigger>+ <SelectContent>+ {resolutionOptions.map((option) => (+ <SelectItem key={option.value} value={option.value}>+ {option.label}+ </SelectItem>+ ))}+ </SelectContent>+ </Select>+ </Field>++ {refunding && (+ <>+ <Field>+ <FieldLabel htmlFor="claim-resolve-amount">+ {t('admin.pages.orders.detail.claims.refund_amount')}+ </FieldLabel>+ <InputGroup>+ <InputGroupAddon>+ <InputGroupText>{currencySymbol}</InputGroupText>+ </InputGroupAddon>+ <InputGroupInput+ id="claim-resolve-amount"+ type="number"+ step="0.01"+ min="0"+ value={amount}+ onChange={(event) => setAmount(event.target.value)}+ />+ </InputGroup>+ </Field>+ <Field>+ <FieldLabel htmlFor="claim-refund-method">+ {t('admin.pages.orders.detail.returns.refund_method')}+ </FieldLabel>+ <Select+ items={methodOptions}+ value={refundMethod}+ onValueChange={(value) => setRefundMethod(value as RefundMethod)}+ >+ <SelectTrigger id="claim-refund-method">+ <SelectValue />+ </SelectTrigger>+ <SelectContent>+ {methodOptions.map((option) => (+ <SelectItem key={option.value} value={option.value}>+ {option.label}+ </SelectItem>+ ))}+ </SelectContent>+ </Select>+ </Field>+ </>+ )}++ {sendingReplacement && (+ <div className="flex flex-col gap-2">+ <span className="font-medium text-sm">+ {t('admin.pages.orders.detail.claims.replacement_items')}+ </span>+ {lines.map((line) => (+ <div+ key={line.id}+ className="flex items-center justify-between gap-4 rounded-lg border p-3"+ >+ <span className="truncate text-sm">+ {line.label}+ <span className="text-muted-foreground"> ×{line.quantity}</span>+ </span>+ <Switch+ checked={replacing[line.id] ?? false}+ onCheckedChange={(checked) =>+ setReplacing({ ...replacing, [line.id]: checked })+ }+ />+ </div>+ ))}+ </div>+ )}+ </DialogBody>+ <DialogFooter>+ <Button variant="outline" onClick={onClose} disabled={pending}>+ {t('admin.actions.cancel')}+ </Button>+ <Button+ disabled={!ready || pending}+ onClick={() =>+ onSubmit({+ resolution,+ refundMethod,+ amount: refunding ? amount : undefined,+ replacementLineItemIds: chosenReplacements,+ })+ }+ >+ {t('admin.pages.orders.detail.claims.actions.resolve')}+ </Button>+ </DialogFooter>+ </DialogContent>+ </Dialog>+ )+}diff --git a/packages/dashboard-ui/src/spree/post-sale-fields.tsx b/packages/dashboard-ui/src/spree/post-sale-fields.tsxnew file mode 100644index 0000000000..03de1b399b--- /dev/null+++ b/packages/dashboard-ui/src/spree/post-sale-fields.tsx@@ -0,0 +1,133 @@+import { useTranslation } from 'react-i18next'+import { Field, FieldLabel } from '../ui/field'+import { Input } from '../ui/input'+import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue } from '../ui/select'++/** A unit on the order that a return, exchange or claim can name. */+export type PostSaleUnit = {+ id: string+ label: string+ quantity: number+}++/** How many of each unit a record covers; zero means "not included". */+export type PostSaleSelection = Record<string, number>++/**+ * Picks how many of each unit a post-sale record covers.+ *+ * Shared by the operator's order page and the seller's, so opening a return+ * looks the same on both sides of a marketplace.+ */+export function QuantityPicker({+ units,+ selection,+ onChange,+}: {+ units: PostSaleUnit[]+ selection: PostSaleSelection+ onChange: (selection: PostSaleSelection) => 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="min-w-0 truncate text-sm">{unit.label}</span>+ <Input+ type="number"+ min={0}+ max={unit.quantity}+ className="w-20"+ value={selection[unit.id] ?? 0}+ aria-label={unit.label}+ onChange={(event) =>+ onChange({+ ...selection,+ [unit.id]: Math.max(0, Math.min(Number(event.target.value), unit.quantity)),+ })+ }+ />+ </div>+ ))}+ </div>+ )+}++/** The units a record actually covers, as id/quantity pairs. */+export function selectedUnits(selection: PostSaleSelection): Array<[string, number]> {+ return Object.entries(selection).filter(([, quantity]) => quantity > 0)+}++/** One entry of a merchant's reason vocabulary. */+export type ReasonOption = {+ id: string+ name: string+}++/**+ * Reason dropdown, shared by every surface that records why something+ * happened. Optional by design — the API accepts a record without a reason,+ * and a merchant mid-return should not be blocked because nobody has curated+ * the list yet.+ *+ * With no `emptyOptionLabel` the field hides itself when the vocabulary is+ * empty, which suits a form that has other fields to fall back on. Passing one+ * keeps the field visible with an explicit "none" choice at the top, for a+ * surface where the reason is the point and its absence has to be sayable.+ *+ * The reasons come from the caller: each panel reads its own endpoint, and+ * which vocabulary a surface offers is not this component's business.+ */+export function ReasonField({+ id,+ reasons,+ value,+ onChange,+ label,+ emptyOptionLabel,+}: {+ /** Scopes the field id, since a page can show more than one of these. */+ id: string+ reasons: ReasonOption[]+ value: string+ onChange: (value: string) => void+ label?: string+ emptyOptionLabel?: string+}) {+ const { t } = useTranslation()++ if (reasons.length === 0 && emptyOptionLabel === undefined) return null++ // Base UI's <Select> needs `items` to resolve the trigger label; without it+ // the closed trigger renders the raw id (see CLAUDE.md).+ const options = [+ ...(emptyOptionLabel === undefined ? [] : [{ value: '', label: emptyOptionLabel }]),+ ...reasons.map((reason) => ({ value: reason.id, label: reason.name })),+ ]++ return (+ <Field>+ <FieldLabel htmlFor={`reason-${id}`}>+ {label ?? t('admin.pages.orders.detail.returns.reason')}+ </FieldLabel>+ <Select items={options} value={value} onValueChange={(next) => onChange(next ?? '')}>+ <SelectTrigger id={`reason-${id}`}>+ {/* An explicit empty choice IS the label for "none", so it must show+ rather than fall through to the placeholder Base UI renders for+ an unset value. */}+ <SelectValue placeholder={emptyOptionLabel ?? t('admin.common.select_placeholder')} />+ </SelectTrigger>+ <SelectContent>+ {options.map((option) => (+ <SelectItem key={option.value} value={option.value}>+ {option.label}+ </SelectItem>+ ))}+ </SelectContent>+ </Select>+ </Field>+ )+}diff --git a/packages/dashboard-ui/src/spree/return-dialogs.tsx b/packages/dashboard-ui/src/spree/return-dialogs.tsxnew file mode 100644index 0000000000..edc879bdb4--- /dev/null+++ b/packages/dashboard-ui/src/spree/return-dialogs.tsx@@ -0,0 +1,228 @@+import { useState } from 'react'+import { useTranslation } from 'react-i18next'+import { Button } from '../ui/button'+import {+ Dialog,+ DialogBody,+ DialogContent,+ DialogFooter,+ DialogHeader,+ DialogTitle,+} from '../ui/dialog'+import { Field, FieldLabel } from '../ui/field'+import { Input } from '../ui/input'+import { InputGroup, InputGroupAddon, InputGroupInput, InputGroupText } from '../ui/input-group'+import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue } from '../ui/select'+import { Switch } from '../ui/switch'++/** How money goes back to the buyer. */+export type RefundMethod = 'original_payment' | 'store_credit'++/** One line of a return, as the receipt form needs it. */+export type ReturnLineForReceipt = {+ id: string+ label: string+ quantity: number+}++type ReceiptRow = { quantity: number; resellable: boolean }++/**+ * Records what actually arrived: a quantity per line, and whether each can go+ * back on the shelf.+ *+ * Deliberately not defaulted server-side — an omitted `items` means "receive+ * everything as requested", so a partial receipt has to say so line by line.+ * Shared by the operator's order page and the seller's.+ */+export function ReturnReceiveDialog({+ lines,+ onClose,+ onSubmit,+ pending = false,+}: {+ lines: ReturnLineForReceipt[]+ onClose: () => void+ onSubmit: (+ items: Array<{ return_line_item_id: string; quantity: number; resellable: boolean }>,+ ) => void+ pending?: boolean+}) {+ const { t } = useTranslation()+ const [rows, setRows] = useState<Record<string, ReceiptRow>>(() =>+ Object.fromEntries(+ lines.map((line) => [line.id, { quantity: line.quantity, resellable: true }]),+ ),+ )++ return (+ <Dialog open onOpenChange={(open) => !open && onClose()}>+ <DialogContent>+ <DialogHeader>+ <DialogTitle>{t('admin.pages.orders.detail.returns.receive_title')}</DialogTitle>+ </DialogHeader>+ <DialogBody className="flex flex-col gap-4">+ {lines.map((line) => (+ <div key={line.id} className="flex flex-col gap-3">+ <span className="font-medium text-sm">{line.label}</span>+ <div className="flex flex-col gap-3">+ <Field>+ <FieldLabel htmlFor={`qty-${line.id}`}>+ {t('admin.pages.orders.detail.returns.received_quantity')}+ </FieldLabel>+ <Input+ id={`qty-${line.id}`}+ type="number"+ min={0}+ max={line.quantity}+ value={rows[line.id]?.quantity ?? 0}+ onChange={(event) =>+ setRows((current) => ({+ ...current,+ [line.id]: {+ quantity: Math.min(Number(event.target.value), line.quantity),+ resellable: current[line.id]?.resellable ?? true,+ },+ }))+ }+ />+ </Field>+ <Field orientation="horizontal">+ <FieldLabel htmlFor={`resellable-${line.id}`}>+ {t('admin.pages.orders.detail.returns.resellable')}+ </FieldLabel>+ <Switch+ id={`resellable-${line.id}`}+ checked={rows[line.id]?.resellable ?? true}+ onCheckedChange={(checked) =>+ setRows((current) => ({+ ...current,+ [line.id]: {+ quantity: current[line.id]?.quantity ?? 0,+ resellable: checked,+ },+ }))+ }+ />+ </Field>+ </div>+ </div>+ ))}+ </DialogBody>+ <DialogFooter>+ <Button variant="outline" onClick={onClose} disabled={pending}>+ {t('admin.actions.cancel')}+ </Button>+ <Button+ disabled={pending}+ onClick={() =>+ onSubmit(+ lines.map((line) => ({+ return_line_item_id: line.id,+ quantity: rows[line.id]?.quantity ?? 0,+ resellable: rows[line.id]?.resellable ?? true,+ })),+ )+ }+ >+ {t('admin.pages.orders.detail.returns.actions.receive')}+ </Button>+ </DialogFooter>+ </DialogContent>+ </Dialog>+ )+}++/**+ * Gives the money back: how much, and by what means.+ *+ * The currency symbol comes from the caller — the operator's panel reads it+ * from the store it is looking at, and a seller has no currency of their own.+ */+export function ReturnRefundDialog({+ refundableTotal,+ currencySymbol,+ onClose,+ onSubmit,+ pending = false,+}: {+ refundableTotal: string+ currencySymbol: string+ onClose: () => void+ onSubmit: (params: { refundMethod: RefundMethod; amount?: string }) => void+ pending?: boolean+}) {+ const { t } = useTranslation()+ const [refundMethod, setRefundMethod] = useState<RefundMethod>('original_payment')+ const [amount, setAmount] = useState(refundableTotal)++ const methodOptions = [+ {+ value: 'original_payment',+ label: t('admin.pages.orders.detail.returns.refund_methods.original_payment'),+ },+ {+ value: 'store_credit',+ label: t('admin.pages.orders.detail.returns.refund_methods.store_credit'),+ },+ ]++ return (+ <Dialog open onOpenChange={(open) => !open && onClose()}>+ <DialogContent>+ <DialogHeader>+ <DialogTitle>{t('admin.pages.orders.detail.returns.refund_title')}</DialogTitle>+ </DialogHeader>+ <DialogBody className="flex flex-col gap-4">+ <Field>+ <FieldLabel htmlFor="refund-amount">+ {t('admin.pages.orders.detail.returns.refund_amount')}+ </FieldLabel>+ <InputGroup>+ <InputGroupAddon>+ <InputGroupText>{currencySymbol}</InputGroupText>+ </InputGroupAddon>+ <InputGroupInput+ id="refund-amount"+ type="number"+ step="0.01"+ min="0"+ value={amount}+ onChange={(event) => setAmount(event.target.value)}+ />+ </InputGroup>+ </Field>+ <Field>+ <FieldLabel htmlFor="refund-method">+ {t('admin.pages.orders.detail.returns.refund_method')}+ </FieldLabel>+ <Select+ items={methodOptions}+ value={refundMethod}+ onValueChange={(value) => setRefundMethod(value as RefundMethod)}+ >+ <SelectTrigger id="refund-method">+ <SelectValue />+ </SelectTrigger>+ <SelectContent>+ {methodOptions.map((option) => (+ <SelectItem key={option.value} value={option.value}>+ {option.label}+ </SelectItem>+ ))}+ </SelectContent>+ </Select>+ </Field>+ </DialogBody>+ <DialogFooter>+ <Button variant="outline" onClick={onClose} disabled={pending}>+ {t('admin.actions.cancel')}+ </Button>+ <Button disabled={pending} onClick={() => onSubmit({ refundMethod, amount })}>+ {t('admin.pages.orders.detail.returns.actions.refund')}+ </Button>+ </DialogFooter>+ </DialogContent>+ </Dialog>+ )+}diff --git a/packages/dashboard/src/components/spree/order-returns-card.tsx b/packages/dashboard/src/components/spree/order-returns-card.tsxindex a170ede1c7..e14642e4c6 100644--- a/packages/dashboard/src/components/spree/order-returns-card.tsx+++ b/packages/dashboard/src/components/spree/order-returns-card.tsx@@ -9,31 +9,15 @@ import {CardFooter,CardHeader,CardTitle,- Dialog,- DialogBody,- DialogContent,- DialogFooter,- DialogHeader,- DialogTitle,DropdownMenu,DropdownMenuContent,DropdownMenuItem,DropdownMenuSeparator,DropdownMenuTrigger,- Field,- FieldLabel,- Input,- InputGroup,- InputGroupAddon,- InputGroupInput,- InputGroupText,- Select,- SelectContent,- SelectItem,- SelectTrigger,- SelectValue,+ type RefundMethod,+ ReturnReceiveDialog,+ ReturnRefundDialog,StatusBadge,- Switch,useConfirm,} from '@spree/dashboard-ui'import {@@ -54,8 +38,6 @@ import { ShippingDocuments } from './orders/shipping-documents'import { ShippingLabelRow } from './orders/shipping-label-row'import { CreateReturnDialog, fulfilledUnits } from './post-sale-create-dialogs'-type ReceiptRow = { quantity: number; resellable: boolean }-// Statuses that still offer an action; refunded and canceled are done and// would render a menu button that opens onto nothing.const RETURN_ACTIONABLE = ['requested', 'approved', 'received']@@ -359,6 +341,7 @@ function ReturnLineRow({ line, status }: { line: ReturnLineItem; status: string* Partial and damaged receipt is the normal case, so the dialog opens with* every line editable rather than hiding that behind an "advanced" toggle.*/+function ReceiveDialog({returnRecord,onClose,@@ -370,88 +353,16 @@ function ReceiveDialog({items: Array<{ return_line_item_id: string; quantity: number; resellable: boolean }>,) => void}) {- const { t } = useTranslation()- const lines = returnRecord.return_line_items ?? []- const [rows, setRows] = useState<Record<string, ReceiptRow>>(() =>- Object.fromEntries(- lines.map((line) => [line.id, { quantity: line.quantity, resellable: true }]),- ),- )-return (- <Dialog open onOpenChange={(open) => !open && onClose()}>- <DialogContent>- <DialogHeader>- <DialogTitle>{t('admin.pages.orders.detail.returns.receive_title')}</DialogTitle>- </DialogHeader>- <DialogBody className="flex flex-col gap-4">- {lines.map((line) => (- <div key={line.id} className="flex flex-col gap-3">- <span className="text-sm font-medium">{variantLabel(line)}</span>- <div className="flex flex-col gap-3">- <Field>- <FieldLabel htmlFor={`qty-${line.id}`}>- {t('admin.pages.orders.detail.returns.received_quantity')}- </FieldLabel>- <Input- id={`qty-${line.id}`}- type="number"- min={0}- max={line.quantity}- value={rows[line.id]?.quantity ?? 0}- onChange={(event) =>- setRows((current) => ({- ...current,- [line.id]: {- quantity: Math.min(Number(event.target.value), line.quantity),- resellable: current[line.id]?.resellable ?? true,- },- }))- }- />- </Field>- <Field orientation="horizontal">- <FieldLabel htmlFor={`resellable-${line.id}`}>- {t('admin.pages.orders.detail.returns.resellable')}- </FieldLabel>- <Switch- id={`resellable-${line.id}`}- checked={rows[line.id]?.resellable ?? true}- onCheckedChange={(checked) =>- setRows((current) => ({- ...current,- [line.id]: {- quantity: current[line.id]?.quantity ?? 0,- resellable: checked,- },- }))- }- />- </Field>- </div>- </div>- ))}- </DialogBody>- <DialogFooter>- <Button variant="outline" onClick={onClose}>- {t('admin.actions.cancel')}- </Button>- <Button- onClick={() =>- onSubmit(- lines.map((line) => ({- return_line_item_id: line.id,- quantity: rows[line.id]?.quantity ?? 0,- resellable: rows[line.id]?.resellable ?? true,- })),- )- }- >- {t('admin.pages.orders.detail.returns.actions.receive')}- </Button>- </DialogFooter>- </DialogContent>- </Dialog>+ <ReturnReceiveDialog+ lines={(returnRecord.return_line_items ?? []).map((line) => ({+ id: line.id,+ label: variantLabel(line),+ quantity: line.quantity,+ }))}+ onClose={onClose}+ onSubmit={onSubmit}+ />)}@@ -462,85 +373,17 @@ function RefundDialog({}: {returnRecord: ReturnonClose: () => void- onSubmit: (params: { refundMethod: 'original_payment' | 'store_credit'; amount?: string }) => void+ onSubmit: (params: { refundMethod: RefundMethod; amount?: string }) => void}) {- const { t } = useTranslation()- const [refundMethod, setRefundMethod] = useState<'original_payment' | 'store_credit'>(- 'original_payment',- )- const [amount, setAmount] = useState(returnRecord.refundable_total)const { defaultCurrency } = useStore()const { symbol: currencySymbol } = currencyParts(defaultCurrency, i18n.language)- const methodOptions = [- {- value: 'original_payment',- label: t('admin.pages.orders.detail.returns.refund_methods.original_payment'),- },- {- value: 'store_credit',- label: t('admin.pages.orders.detail.returns.refund_methods.store_credit'),- },- ]-return (- <Dialog open onOpenChange={(open) => !open && onClose()}>- <DialogContent>- <DialogHeader>- <DialogTitle>{t('admin.pages.orders.detail.returns.refund_title')}</DialogTitle>- </DialogHeader>- <DialogBody className="flex flex-col gap-4">- <Field>- <FieldLabel htmlFor="refund-amount">- {t('admin.pages.orders.detail.returns.refund_amount')}- </FieldLabel>- <InputGroup>- <InputGroupAddon>- <InputGroupText>{currencySymbol}</InputGroupText>- </InputGroupAddon>- <InputGroupInput- id="refund-amount"- type="number"- step="0.01"- min="0"- value={amount}- onChange={(event) => setAmount(event.target.value)}- />- </InputGroup>- </Field>- <Field>- <FieldLabel htmlFor="refund-method">- {t('admin.pages.orders.detail.returns.refund_method')}- </FieldLabel>- <Select- items={methodOptions}- value={refundMethod}- onValueChange={(value) =>- setRefundMethod(value as 'original_payment' | 'store_credit')- }- >- <SelectTrigger id="refund-method">- <SelectValue />- </SelectTrigger>- <SelectContent>- {methodOptions.map((option) => (- <SelectItem key={option.value} value={option.value}>- {option.label}- </SelectItem>- ))}- </SelectContent>- </Select>- </Field>- </DialogBody>- <DialogFooter>- <Button variant="outline" onClick={onClose}>- {t('admin.actions.cancel')}- </Button>- <Button onClick={() => onSubmit({ refundMethod, amount })}>- {t('admin.pages.orders.detail.returns.actions.refund')}- </Button>- </DialogFooter>- </DialogContent>- </Dialog>+ <ReturnRefundDialog+ refundableTotal={returnRecord.refundable_total}+ currencySymbol={currencySymbol}+ onClose={onClose}+ onSubmit={onSubmit}+ />)}diff --git a/packages/dashboard/src/components/spree/post-sale-create-dialogs.tsx b/packages/dashboard/src/components/spree/post-sale-create-dialogs.tsxindex de5e2b5767..6635e21d35 100644--- a/packages/dashboard/src/components/spree/post-sale-create-dialogs.tsx+++ b/packages/dashboard/src/components/spree/post-sale-create-dialogs.tsx@@ -8,6 +8,8 @@ import {} from '@spree/dashboard-core'import {Button,+ type ClaimResolution,+ ClaimResolveDialog,Dialog,DialogBody,DialogContent,@@ -21,12 +23,15 @@ import {InputGroupAddon,InputGroupInput,InputGroupText,+ QuantityPicker,+ type RefundMethod,Select,SelectContent,SelectItem,+ type PostSaleSelection as Selection,SelectTrigger,SelectValue,- Switch,+ selectedUnits as selectedItems,Textarea,} from '@spree/dashboard-ui'import i18n from 'i18next'@@ -61,49 +66,6 @@ export function fulfilledUnits(order: Order): FulfilledUnit[] {)}-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,@@ -496,183 +458,40 @@ export function ResolveClaimDialog({claim: ClaimonClose: () => voidonSubmit: (params: {- resolution: 'refund' | 'replacement' | 'refund_and_replacement'- refundMethod: 'original_payment' | 'store_credit'+ resolution: ClaimResolution+ refundMethod: RefundMethodamount?: stringreplacementLineItemIds: string[]}) => void}) {- const { t } = useTranslation()const lines = claim.claim_line_items ?? []const { defaultCurrency } = useStore()const { symbol: currencySymbol } = currencyParts(defaultCurrency, i18n.language)- const [resolution, setResolution] = useState<'refund' | 'replacement' | 'refund_and_replacement'>(- 'refund',- )- const [refundMethod, setRefundMethod] = useState<'original_payment' | 'store_credit'>(- 'store_credit',- )// A claim opened without per-item amounts has a refund_total of zero, and// the workflow refuses to refund nothing — offer what the customer paid for// the claimed items instead, which is also the ceiling it enforces.- const [amount, setAmount] = useState(() => {- const recorded = Number(claim.refund_total)- if (Number.isFinite(recorded) && recorded > 0) return claim.refund_total-- const paid = lines.reduce((sum, line) => sum + Number(line.paid_amount ?? 0), 0)- return paid > 0 ? paid.toFixed(2) : claim.refund_total- })- const [replacing, setReplacing] = useState<Record<string, boolean>>(() =>- Object.fromEntries(lines.map((line) => [line.id, line.send_replacement])),- )-- const refunding = resolution.includes('refund')- const sendingReplacement = resolution.includes('replacement')- const chosenReplacements = Object.entries(replacing)- .filter(([, on]) => on)- .map(([id]) => id)-- const resolutionOptions = (['refund', 'replacement', 'refund_and_replacement'] as const).map(- (value) => ({- value,- label: t(`admin.pages.orders.detail.claims.resolutions.${value}`),- }),- )-- const methodOptions = [- {- value: 'store_credit',- label: t('admin.pages.orders.detail.returns.refund_methods.store_credit'),- },- {- value: 'original_payment',- label: t('admin.pages.orders.detail.returns.refund_methods.original_payment'),- },- ]-- // Refunding nothing, or replacing nothing, is what the server rejects —- // say so here instead of letting the request fail.- const ready =- (!refunding || Number(amount) > 0) && (!sendingReplacement || chosenReplacements.length > 0)+ const recorded = Number(claim.refund_total)+ const paid = lines.reduce((sum, line) => sum + Number(line.paid_amount ?? 0), 0)+ const defaultAmount =+ Number.isFinite(recorded) && recorded > 0+ ? claim.refund_total+ : paid > 0+ ? paid.toFixed(2)+ : claim.refund_totalreturn (- <Dialog open onOpenChange={(open) => !open && onClose()}>- <DialogContent>- <DialogHeader>- <DialogTitle>{t('admin.pages.orders.detail.claims.resolve_title')}</DialogTitle>- </DialogHeader>- <DialogBody className="flex flex-col gap-4">- <Field>- <FieldLabel htmlFor="claim-resolution">- {t('admin.pages.orders.detail.claims.resolution')}- </FieldLabel>- <Select- items={resolutionOptions}- value={resolution}- onValueChange={(value) => setResolution(value as typeof resolution)}- >- <SelectTrigger id="claim-resolution">- <SelectValue />- </SelectTrigger>- <SelectContent>- {resolutionOptions.map((option) => (- <SelectItem key={option.value} value={option.value}>- {option.label}- </SelectItem>- ))}- </SelectContent>- </Select>- </Field>-- {refunding && (- <>- <Field>- <FieldLabel htmlFor="claim-resolve-amount">- {t('admin.pages.orders.detail.claims.refund_amount')}- </FieldLabel>- <InputGroup>- <InputGroupAddon>- <InputGroupText>{currencySymbol}</InputGroupText>- </InputGroupAddon>- <InputGroupInput- id="claim-resolve-amount"- type="number"- step="0.01"- min="0"- value={amount}- onChange={(event) => setAmount(event.target.value)}- />- </InputGroup>- </Field>- <Field>- <FieldLabel htmlFor="claim-refund-method">- {t('admin.pages.orders.detail.returns.refund_method')}- </FieldLabel>- <Select- items={methodOptions}- value={refundMethod}- onValueChange={(value) => setRefundMethod(value as typeof refundMethod)}- >- <SelectTrigger id="claim-refund-method">- <SelectValue />- </SelectTrigger>- <SelectContent>- {methodOptions.map((option) => (- <SelectItem key={option.value} value={option.value}>- {option.label}- </SelectItem>- ))}- </SelectContent>- </Select>- </Field>- </>- )}-- {sendingReplacement && (- <div className="flex flex-col gap-2">- <span className="text-sm font-medium">- {t('admin.pages.orders.detail.claims.replacement_items')}- </span>- {lines.map((line) => (- <div- key={line.id}- className="flex items-center justify-between gap-4 rounded-lg border p-3"- >- <span className="text-sm truncate">- {line.variant?.product_name ?? line.variant_id}- <span className="text-muted-foreground"> ×{line.quantity}</span>- </span>- <Switch- checked={replacing[line.id] ?? false}- onCheckedChange={(checked) =>- setReplacing({ ...replacing, [line.id]: checked })- }- />- </div>- ))}- </div>- )}- </DialogBody>- <DialogFooter>- <Button variant="outline" onClick={onClose}>- {t('admin.actions.cancel')}- </Button>- <Button- disabled={!ready}- onClick={() =>- onSubmit({- resolution,- refundMethod,- amount: refunding ? amount : undefined,- replacementLineItemIds: chosenReplacements,- })- }- >- {t('admin.pages.orders.detail.claims.actions.resolve')}- </Button>- </DialogFooter>- </DialogContent>- </Dialog>+ <ClaimResolveDialog+ lines={lines.map((line) => ({+ id: line.id,+ label: line.variant?.product_name ?? line.variant_id ?? line.id,+ quantity: line.quantity,+ sendReplacement: line.send_replacement,+ }))}+ defaultAmount={defaultAmount}+ currencySymbol={currencySymbol}+ onClose={onClose}+ onSubmit={onSubmit}+ />)}diff --git a/packages/seller-dashboard/src/components/orders/post-sale-cards.tsx b/packages/seller-dashboard/src/components/orders/post-sale-cards.tsxindex f03e99cd0c..9ab1f5dd9a 100644--- a/packages/seller-dashboard/src/components/orders/post-sale-cards.tsx+++ b/packages/seller-dashboard/src/components/orders/post-sale-cards.tsx@@ -1,3 +1,4 @@+import { currencyParts } from '@spree/dashboard-core'import {Button,Card,@@ -5,25 +6,12 @@ import {CardContent,CardHeader,CardTitle,- Dialog,- DialogBody,- DialogContent,- DialogFooter,- DialogHeader,- DialogTitle,+ ClaimResolveDialog,DropdownMenu,DropdownMenuContent,DropdownMenuItem,DropdownMenuSeparator,DropdownMenuTrigger,- Field,- FieldLabel,- Input,- Select,- SelectContent,- SelectItem,- SelectTrigger,- SelectValue,StatusBadge,useConfirm,} from '@spree/dashboard-ui'@@ -35,6 +23,7 @@ import {ShieldAlertIcon,} from '@spree/dashboard-ui/icons'import type { Claim, Order } from '@spree/seller-sdk'+import i18n from 'i18next'import { useState } from 'react'import { useTranslation } from 'react-i18next'import {@@ -286,8 +275,8 @@ export function ClaimsCard({ order }: { order: Order }) {{resolving && (<ResolveClaimDialogorderId={order.id}+ order={order}claim={resolving}- openonOpenChange={() => setResolving(null)}/>)}@@ -296,149 +285,63 @@ export function ClaimsCard({ order }: { order: Order }) {}/** Money back, a replacement, or both. */++/**+ * How the seller puts a delivery right: money back, a replacement, or both.+ *+ * The currency is the order's — a seller has none of their own.+ */function ResolveClaimDialog({orderId,+ order,claim,- open,onOpenChange,}: {orderId: string+ order: Orderclaim: Claim- open: booleanonOpenChange: (open: boolean) => void}) {- const { t } = useTranslation()const { resolve } = useClaimActions(orderId)+ const lines = claim.claim_line_items ?? []+ const { symbol: currencySymbol } = currencyParts(order.currency, i18n.language)- const [resolution, setResolution] = useState<'refund' | 'replacement' | 'refund_and_replacement'>(- 'refund',- )- const [amount, setAmount] = useState('')- const [method, setMethod] = useState<'original_payment' | 'store_credit'>('store_credit')-- // A replacement resolution only works when a line was opened asking for- // one, and nothing on this branch flags a line yet — so offering it would- // guarantee a 422 for a choice the seller made in good faith. The options- // follow what the claim actually carries.- const replaceable = (claim.claim_line_items ?? []).some((line) => line.send_replacement)-- const resolutionOptions = [- { value: 'refund', label: t('orders.post_sale.claims.resolutions.refund') },- ...(replaceable- ? [- { value: 'replacement', label: t('orders.post_sale.claims.resolutions.replacement') },- {- value: 'refund_and_replacement',- label: t('orders.post_sale.claims.resolutions.refund_and_replacement'),- },- ]- : []),- ]- const methodOptions = [- { value: 'store_credit', label: t('orders.post_sale.returns.store_credit') },- { value: 'original_payment', label: t('orders.post_sale.returns.original_payment') },- ]-- const refunding = resolution.includes('refund')-- async function handleResolve() {- await resolve- .mutateAsync({- claimId: claim.id,- resolution,- refundMethod: refunding ? method : undefined,- amount: refunding && amount ? amount : undefined,- })- .then(() => onOpenChange(false))- .catch(() => undefined)- }+ // A claim opened without per-item amounts has a refund_total of zero, and+ // the workflow refuses to refund nothing — offer what the customer paid for+ // the claimed items instead, which is also the ceiling it enforces.+ const recorded = Number(claim.refund_total)+ const paid = lines.reduce((sum, line) => sum + Number(line.paid_amount ?? 0), 0)+ const defaultAmount =+ Number.isFinite(recorded) && recorded > 0+ ? claim.refund_total+ : paid > 0+ ? paid.toFixed(2)+ : claim.refund_totalreturn (- <Dialog open={open} onOpenChange={onOpenChange}>- <DialogContent>- <DialogHeader>- <DialogTitle>{t('orders.post_sale.claims.resolve_title')}</DialogTitle>- </DialogHeader>- <DialogBody>- <div className="flex flex-col gap-4">- <Field>- <FieldLabel htmlFor="claim-resolution">- {t('orders.post_sale.claims.resolution')}- </FieldLabel>- <Select- items={resolutionOptions}- value={resolution}- onValueChange={(value) =>- setResolution(- (value as 'refund' | 'replacement' | 'refund_and_replacement') ?? 'refund',- )- }- >- <SelectTrigger id="claim-resolution">- <SelectValue />- </SelectTrigger>- <SelectContent>- {resolutionOptions.map((option) => (- <SelectItem key={option.value} value={option.value}>- {option.label}- </SelectItem>- ))}- </SelectContent>- </Select>- </Field>-- {refunding && (- <>- <Field>- <FieldLabel htmlFor="claim-amount">- {t('orders.post_sale.returns.amount')}- </FieldLabel>- <Input- id="claim-amount"- type="number"- step="0.01"- min={0}- value={amount}- onChange={(event) => setAmount(event.target.value)}- />- </Field>-- <Field>- <FieldLabel htmlFor="claim-refund-method">- {t('orders.post_sale.returns.refund_method')}- </FieldLabel>- <Select- items={methodOptions}- value={method}- onValueChange={(value) =>- setMethod((value as 'original_payment' | 'store_credit') ?? 'store_credit')- }- >- <SelectTrigger id="claim-refund-method">- <SelectValue />- </SelectTrigger>- <SelectContent>- {methodOptions.map((option) => (- <SelectItem key={option.value} value={option.value}>- {option.label}- </SelectItem>- ))}- </SelectContent>- </Select>- </Field>- </>- )}- </div>- </DialogBody>- <DialogFooter>- <Button type="button" variant="outline" onClick={() => onOpenChange(false)}>- {t('common.cancel')}- </Button>- <Button type="button" disabled={resolve.isPending} onClick={handleResolve}>- {t('orders.post_sale.claims.resolve')}- </Button>- </DialogFooter>- </DialogContent>- </Dialog>+ <ClaimResolveDialog+ lines={lines.map((line) => ({+ id: line.id,+ label: lineLabel(line.name, line.variant, line.variant_id),+ quantity: line.quantity,+ sendReplacement: line.send_replacement,+ }))}+ defaultAmount={defaultAmount}+ currencySymbol={currencySymbol}+ onClose={() => onOpenChange(false)}+ pending={resolve.isPending}+ onSubmit={({ resolution, refundMethod, amount, replacementLineItemIds }) => {+ resolve+ .mutateAsync({+ claimId: claim.id,+ resolution,+ refundMethod,+ amount,+ replacementLineItemIds,+ })+ .then(() => onOpenChange(false))+ .catch(() => undefined)+ }}+ />)}diff --git a/packages/seller-dashboard/src/components/orders/post-sale-create-dialogs.tsx b/packages/seller-dashboard/src/components/orders/post-sale-create-dialogs.tsxindex b63cd67715..9c7d69c3f4 100644--- a/packages/seller-dashboard/src/components/orders/post-sale-create-dialogs.tsx+++ b/packages/seller-dashboard/src/components/orders/post-sale-create-dialogs.tsx@@ -8,19 +8,17 @@ import {DialogTitle,Field,FieldLabel,- Input,- Select,- SelectContent,- SelectItem,- SelectTrigger,- SelectValue,+ QuantityPicker,+ ReasonField,+ type PostSaleSelection as Selection,+ selectedUnits as selectedItems,Textarea,} from '@spree/dashboard-ui'import type { Order } from '@spree/seller-sdk'import { useState } from 'react'import { useTranslation } from 'react-i18next'import { useClaimActions, useReturnActions } from '../../hooks/use-post-sale'-import { type ReasonKind, useReasons } from '../../hooks/use-reasons'+import { useReasons } from '../../hooks/use-reasons'import { unitLabel } from './line-label'/** Units that actually went out, which is all that can come back. */@@ -34,93 +32,6 @@ export function fulfilledUnits(order: Order) {)}-type Selection = Record<string, number>--/** A quantity per unit; zero means "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-3">- <span className="min-w-0 truncate text-sm">{unit.label}</span>- <Input- type="number"- min={0}- max={unit.quantity}- value={selection[unit.id] ?? 0}- className="w-20"- aria-label={unit.label}- onChange={(event) =>- onChange({- ...selection,- [unit.id]: Math.max(0, Math.min(unit.quantity, Number(event.target.value))),- })- }- />- </div>- ))}- </div>- )-}--/**- * The reason picker. Optional by design — the API takes a record without one,- * so a marketplace that has not filled in its vocabulary yet is not blocked.- */-function ReasonField({- kind,- value,- onChange,-}: {- kind: ReasonKind- value: string- onChange: (value: string) => void-}) {- const { t } = useTranslation()- const { data } = useReasons(kind)-- const reasons = data?.data ?? []- if (reasons.length === 0) return null-- const options = reasons.map((reason) => ({ value: reason.id, label: reason.name }))-- return (- <Field>- <FieldLabel htmlFor={`reason-${kind}`}>{t('orders.post_sale.reason')}</FieldLabel>- <Select- items={options}- value={value}- onValueChange={(next) => onChange((next as string) ?? '')}- >- <SelectTrigger id={`reason-${kind}`}>- <SelectValue />- </SelectTrigger>- <SelectContent>- {options.map((option) => (- <SelectItem key={option.value} value={option.value}>- {option.label}- </SelectItem>- ))}- </SelectContent>- </Select>- </Field>- )-}--function selectedItems(selection: Selection) {- return Object.entries(selection)- .filter(([, quantity]) => quantity > 0)- .map(([id, quantity]) => ({ id, quantity }))-}-export function CreateReturnDialog({order,open,@@ -143,7 +54,7 @@ export function CreateReturnDialog({async function handleCreate() {await create.mutateAsync({- items: chosen.map((item) => ({ fulfillment_item_id: item.id, quantity: item.quantity })),+ items: chosen.map(([id, quantity]) => ({ fulfillment_item_id: id, quantity })),reason_id: reasonId || undefined,memo: memo.trim() || undefined,})@@ -164,7 +75,7 @@ export function CreateReturnDialog({<DialogBody><div className="flex flex-col gap-4"><QuantityPicker units={units} selection={selection} onChange={setSelection} />- <ReasonField kind="return-reasons" value={reasonId} onChange={setReasonId} />+ <ReturnReasonField value={reasonId} onChange={setReasonId} /><Field><FieldLabel htmlFor="return-memo">{t('orders.post_sale.memo')}</FieldLabel><Textarea@@ -221,9 +132,9 @@ export function CreateClaimDialog({async function handleCreate() {await create.mutateAsync({- items: chosen.map((item) => ({- line_item_id: item.id,- quantity: item.quantity,+ items: chosen.map(([id, quantity]) => ({+ line_item_id: id,+ quantity,description: description.trim() || undefined,})),reason_id: reasonId || undefined,@@ -245,7 +156,7 @@ export function CreateClaimDialog({<DialogBody><div className="flex flex-col gap-4"><QuantityPicker units={units} selection={selection} onChange={setSelection} />- <ReasonField kind="claim-reasons" value={reasonId} onChange={setReasonId} />+ <ClaimReasonField value={reasonId} onChange={setReasonId} /><Field><FieldLabel htmlFor="claim-description">{t('orders.post_sale.claims.description')}@@ -274,3 +185,50 @@ export function CreateClaimDialog({</Dialog>)}++/**+ * The seller picks from the marketplace's vocabulary — the operator decides+ * what the reasons are, so this reads the store's list rather than one of the+ * seller's own.+ */+function ReturnReasonField({+ value,+ onChange,+}: {+ value: string+ onChange: (value: string) => void+}) {+ const { t } = useTranslation()+ const { data } = useReasons('return-reasons')++ return (+ <ReasonField+ id="return"+ reasons={(data?.data ?? []).filter((reason) => reason.active)}+ value={value}+ onChange={onChange}+ label={t('orders.post_sale.reason')}+ />+ )+}++function ClaimReasonField({+ value,+ onChange,+}: {+ value: string+ onChange: (value: string) => void+}) {+ const { t } = useTranslation()+ const { data } = useReasons('claim-reasons')++ return (+ <ReasonField+ id="claim"+ reasons={(data?.data ?? []).filter((reason) => reason.active)}+ value={value}+ onChange={onChange}+ label={t('orders.post_sale.reason')}+ />+ )+}diff --git a/packages/seller-dashboard/src/components/orders/returns-card.tsx b/packages/seller-dashboard/src/components/orders/returns-card.tsxindex 2735df6db9..3639bf4d00 100644--- a/packages/seller-dashboard/src/components/orders/returns-card.tsx+++ b/packages/seller-dashboard/src/components/orders/returns-card.tsx@@ -1,3 +1,4 @@+import { currencyParts } from '@spree/dashboard-core'import {Badge,Button,@@ -6,31 +7,19 @@ import {CardContent,CardHeader,CardTitle,- Dialog,- DialogBody,- DialogContent,- DialogFooter,- DialogHeader,- DialogTitle,DropdownMenu,DropdownMenuContent,DropdownMenuItem,DropdownMenuSeparator,DropdownMenuTrigger,- Field,- FieldLabel,- Input,- Select,- SelectContent,- SelectItem,- SelectTrigger,- SelectValue,+ ReturnReceiveDialog,+ ReturnRefundDialog,StatusBadge,- Switch,useConfirm,} from '@spree/dashboard-ui'import { EllipsisVerticalIcon, PlusIcon, RotateCcwIcon } from '@spree/dashboard-ui/icons'import type { Order, Return, ReturnLineItem } from '@spree/seller-sdk'+import i18n from 'i18next'import { useState } from 'react'import { useTranslation } from 'react-i18next'import { useOrderReturns, useReturnActions } from '../../hooks/use-post-sale'@@ -161,15 +150,14 @@ export function ReturnsCard({ order }: { order: Order }) {<ReceiveDialogorderId={order.id}returnRecord={receiving}- openonOpenChange={() => setReceiving(null)}/>)}{refunding && (<RefundDialogorderId={order.id}+ order={order}returnRecord={refunding}- openonOpenChange={() => setRefunding(null)}/>)}@@ -203,201 +191,68 @@ function ReturnLineRow({ line }: { line: ReturnLineItem }) {}/** What actually turned up, and whether it can go back on the shelf. */++/** What the seller records as having arrived back. */function ReceiveDialog({orderId,returnRecord,- open,onOpenChange,}: {orderId: stringreturnRecord: Return- open: booleanonOpenChange: (open: boolean) => void}) {- const { t } = useTranslation()const { receive } = useReturnActions(orderId)- const lines = returnRecord.return_line_items ?? []- const [rows, setRows] = useState<Record<string, { quantity: number; resellable: boolean }>>(() =>- Object.fromEntries(- lines.map((line) => [line.id, { quantity: line.quantity, resellable: true }]),- ),- )-- async function handleReceive() {- await receive- .mutateAsync({- returnId: returnRecord.id,- items: lines.map((line) => ({- return_line_item_id: line.id,- quantity: rows[line.id]?.quantity ?? 0,- resellable: rows[line.id]?.resellable ?? true,- })),- })- .then(() => onOpenChange(false))- .catch(() => undefined)- }-return (- <Dialog open={open} onOpenChange={onOpenChange}>- <DialogContent>- <DialogHeader>- <DialogTitle>{t('orders.post_sale.returns.receive_title')}</DialogTitle>- </DialogHeader>- <DialogBody>- <div className="flex flex-col gap-3">- {lines.map((line) => (- <div key={line.id} className="flex items-center justify-between gap-3">- <span className="min-w-0 truncate text-sm">- {lineLabel(line.name, line.variant, line.variant_id)}- </span>- <div className="flex shrink-0 items-center gap-3">- <label className="flex items-center gap-2 text-xs" htmlFor={`resell-${line.id}`}>- {t('orders.post_sale.returns.resellable')}- <Switch- id={`resell-${line.id}`}- checked={rows[line.id]?.resellable ?? true}- onCheckedChange={(checked) =>- setRows((current) => ({- ...current,- [line.id]: {- quantity: current[line.id]?.quantity ?? 0,- resellable: !!checked,- },- }))- }- />- </label>- <Input- type="number"- min={0}- max={line.quantity}- className="w-20"- aria-label={t('orders.post_sale.returns.received_quantity')}- value={rows[line.id]?.quantity ?? 0}- onChange={(event) =>- setRows((current) => ({- ...current,- [line.id]: {- quantity: Math.max(- 0,- Math.min(line.quantity, Number(event.target.value)),- ),- resellable: current[line.id]?.resellable ?? true,- },- }))- }- />- </div>- </div>- ))}- </div>- </DialogBody>- <DialogFooter>- <Button type="button" variant="outline" onClick={() => onOpenChange(false)}>- {t('common.cancel')}- </Button>- <Button type="button" disabled={receive.isPending} onClick={handleReceive}>- {t('orders.post_sale.returns.receive')}- </Button>- </DialogFooter>- </DialogContent>- </Dialog>+ <ReturnReceiveDialog+ lines={(returnRecord.return_line_items ?? []).map((line) => ({+ id: line.id,+ label: lineLabel(line.name, line.variant, line.variant_id),+ quantity: line.quantity,+ }))}+ onClose={() => onOpenChange(false)}+ pending={receive.isPending}+ onSubmit={(items) => {+ receive+ .mutateAsync({ returnId: returnRecord.id, items })+ .then(() => onOpenChange(false))+ .catch(() => undefined)+ }}+ />)}/**- * Giving the money back.- *- * Opens on what the return is still owed, which is also the most that can be- * given back — the server refuses anything above it, and on a split checkout- * bounds it again by this order's share of the payment.+ * The seller took the money for their own child order, so giving it back is+ * theirs. The currency is the order's — a seller has none of their own.*/function RefundDialog({orderId,+ order,returnRecord,- open,onOpenChange,}: {orderId: string+ order: OrderreturnRecord: Return- open: booleanonOpenChange: (open: boolean) => void}) {- const { t } = useTranslation()const { refund } = useReturnActions(orderId)-- const [amount, setAmount] = useState(returnRecord.refundable_total ?? '')- const [method, setMethod] = useState<'original_payment' | 'store_credit'>('original_payment')-- const methodOptions = [- { value: 'original_payment', label: t('orders.post_sale.returns.original_payment') },- { value: 'store_credit', label: t('orders.post_sale.returns.store_credit') },- ]-- async function handleRefund() {- await refund- .mutateAsync({ returnId: returnRecord.id, amount, refundMethod: method })- .then(() => onOpenChange(false))- .catch(() => undefined)- }+ const { symbol: currencySymbol } = currencyParts(order.currency, i18n.language)return (- <Dialog open={open} onOpenChange={onOpenChange}>- <DialogContent>- <DialogHeader>- <DialogTitle>{t('orders.post_sale.returns.refund_title')}</DialogTitle>- </DialogHeader>- <DialogBody>- <div className="flex flex-col gap-4">- <Field>- <FieldLabel htmlFor="refund-amount">- {t('orders.post_sale.returns.amount')}- </FieldLabel>- <Input- id="refund-amount"- type="number"- step="0.01"- min={0}- value={amount}- onChange={(event) => setAmount(event.target.value)}- />- </Field>-- <Field>- <FieldLabel htmlFor="refund-method">- {t('orders.post_sale.returns.refund_method')}- </FieldLabel>- <Select- items={methodOptions}- value={method}- onValueChange={(value) =>- setMethod((value as 'original_payment' | 'store_credit') ?? 'original_payment')- }- >- <SelectTrigger id="refund-method">- <SelectValue />- </SelectTrigger>- <SelectContent>- {methodOptions.map((option) => (- <SelectItem key={option.value} value={option.value}>- {option.label}- </SelectItem>- ))}- </SelectContent>- </Select>- </Field>- </div>- </DialogBody>- <DialogFooter>- <Button type="button" variant="outline" onClick={() => onOpenChange(false)}>- {t('common.cancel')}- </Button>- <Button type="button" disabled={refund.isPending} onClick={handleRefund}>- {t('orders.post_sale.returns.refund')}- </Button>- </DialogFooter>- </DialogContent>- </Dialog>+ <ReturnRefundDialog+ refundableTotal={returnRecord.refundable_total}+ currencySymbol={currencySymbol}+ onClose={() => onOpenChange(false)}+ pending={refund.isPending}+ onSubmit={({ refundMethod, amount }) => {+ refund+ .mutateAsync({ returnId: returnRecord.id, refundMethod, amount })+ .then(() => onOpenChange(false))+ .catch(() => undefined)+ }}+ />)}diff --git a/packages/seller-dashboard/src/hooks/use-post-sale.ts b/packages/seller-dashboard/src/hooks/use-post-sale.tsindex 358728336e..5f6eab933e 100644--- a/packages/seller-dashboard/src/hooks/use-post-sale.ts+++ b/packages/seller-dashboard/src/hooks/use-post-sale.ts@@ -178,12 +178,20 @@ export function useClaimActions(orderId: string) {resolution,refundMethod,amount,+ replacementLineItemIds,}: {claimId: stringresolution: 'refund' | 'replacement' | 'refund_and_replacement'refundMethod?: 'original_payment' | 'store_credit'amount?: string- }) => claims().resolve(orderId, claimId, { resolution, refund_method: refundMethod, amount }),+ replacementLineItemIds?: string[]+ }) =>+ claims().resolve(orderId, claimId, {+ resolution,+ refund_method: refundMethod,+ amount,+ replacement_line_item_ids: replacementLineItemIds,+ }),)const deny = usePostSaleMutation(orderId, key, (id: string) => claims().deny(orderId, id))diff --git a/packages/seller-dashboard/src/locales/en.json b/packages/seller-dashboard/src/locales/en.jsonindex e9d585d5ad..8d1edaff3f 100644--- a/packages/seller-dashboard/src/locales/en.json+++ b/packages/seller-dashboard/src/locales/en.json@@ -114,6 +114,43 @@"unverified": "Not valid","verified": "Verified"}+ },+ "pages": {+ "orders": {+ "detail": {+ "returns": {+ "receive_title": "Receive returned items",+ "received_quantity": "Received",+ "resellable": "Resellable",+ "actions": {+ "receive": "Receive items",+ "refund": "Refund"+ },+ "refund_title": "Refund return",+ "refund_amount": "Amount",+ "refund_method": "Refund to",+ "refund_methods": {+ "original_payment": "Original payment",+ "store_credit": "Store credit"+ },+ "reason": "Reason"+ },+ "claims": {+ "resolve_title": "Resolve claim",+ "resolution": "How to resolve",+ "resolutions": {+ "refund": "Refund",+ "replacement": "Replacement",+ "refund_and_replacement": "Refund and replacement"+ },+ "refund_amount": "Refund amount",+ "replacement_items": "Send a replacement for",+ "actions": {+ "resolve": "Resolve"+ }+ }+ }+ }}},"app": {@@ -387,25 +424,17 @@"canceled": "Canceled"},"returns": {- "title": "Returns",- "empty": "Nothing has come back from this order.",+ "cancel_message": "The customer is told it will not go ahead.",+ "cancel_title": "Cancel this return?","create": "New return","create_title": "Take goods back",- "receive": "Receive",- "receive_title": "What arrived?",- "received_quantity": "Quantity received",- "resellable": "Resellable",- "partially_received": "{{received}} of {{quantity}} received",+ "empty": "Nothing has come back from this order.","not_resellable": "Not resellable",+ "partially_received": "{{received}} of {{quantity}} received",+ "receive": "Receive","refund": "Refund",- "refund_title": "Give the money back",- "refund_method": "Refund to","refund_total": "Refund total: {{amount}}",- "amount": "Amount",- "original_payment": "Original payment",- "store_credit": "Store credit",- "cancel_title": "Cancel this return?",- "cancel_message": "The customer is told it will not go ahead."+ "title": "Returns"},"exchanges": {"title": "Exchanges",@@ -416,24 +445,17 @@"cancel_message": "The customer is told it will not go ahead."},"claims": {- "title": "Claims",- "empty": "Nothing has been reported on this order.",+ "cancel_message": "The customer is told it will not go ahead.",+ "cancel_title": "Cancel this claim?","create": "New claim","create_title": "Report a problem",- "description": "What went wrong",- "resolve": "Resolve",- "resolve_title": "Put this right",- "resolution": "How to resolve",- "resolutions": {- "refund": "Refund",- "replacement": "Send a replacement",- "refund_and_replacement": "Refund and send a replacement"- },"deny": "Deny",- "deny_title": "Deny this claim?","deny_message": "The customer is told the claim was not upheld.",- "cancel_title": "Cancel this claim?",- "cancel_message": "The customer is told it will not go ahead."+ "deny_title": "Deny this claim?",+ "description": "What went wrong",+ "empty": "Nothing has been reported on this order.",+ "resolve": "Resolve",+ "title": "Claims"}},"search_placeholder": "Search by order number…",