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 order fulfillment components between both panels
Damian Legawiec85398623d892
diff --git a/packages/dashboard-core/src/index.ts b/packages/dashboard-core/src/index.tsindex 4dba8c1989..d5a773742c 100644--- a/packages/dashboard-core/src/index.ts+++ b/packages/dashboard-core/src/index.ts@@ -73,6 +73,7 @@ export * from './lib/create-action-registry'// ---------------------------------------------------------------------------export * from './lib/custom-field-components'export * from './lib/date-presets'+export * from './lib/delivery-form'// ---------------------------------------------------------------------------// Helpers// ---------------------------------------------------------------------------@@ -83,6 +84,7 @@ export * from './lib/form-errors'export * from './lib/form-fields-registry'export * from './lib/form-mappers'export * from './lib/formatters'+export * from './lib/fulfillment-items'// i18n side-effect import bootstraps i18next + React adapter on first import.// Consumers that need the singleton (e.g. plugin authors calling// `i18n.addResourceBundle`) get it via the named re-export.diff --git a/packages/dashboard-core/src/lib/delivery-form.ts b/packages/dashboard-core/src/lib/delivery-form.tsnew file mode 100644index 0000000000..e011da482f--- /dev/null+++ b/packages/dashboard-core/src/lib/delivery-form.ts@@ -0,0 +1,15 @@+import { z } from 'zod'++/**+ * One consignment's editable fields.+ *+ * The carrier is free text: a forwarder's own name is as valid as a+ * registered carrier, and an empty value asks the server to detect one from+ * the number.+ */+export const deliveryFormSchema = z.object({+ tracking_number: z.string().min(1),+ carrier: z.string(),+})++export type DeliveryFormValues = z.infer<typeof deliveryFormSchema>diff --git a/packages/dashboard-ui/src/index.ts b/packages/dashboard-ui/src/index.tsindex 4942884f3c..e13ac61728 100644--- a/packages/dashboard-ui/src/index.ts+++ b/packages/dashboard-ui/src/index.ts@@ -36,10 +36,14 @@ export * from './spree/confirm-dialog'export * from './spree/copy-to-clipboard-button'export * from './spree/country-flag'export * from './spree/data-grid'+export * from './spree/delivery-form-dialog'export * from './spree/drag-handle'export * from './spree/file-type-icon'export * from './spree/form-actions'+export * from './spree/fulfill-items-form'export * from './spree/fulfillment-edit-dialog'+export * from './spree/fulfillment-item-list'+export * from './spree/fulfillment-panel'// 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/delivery-form-dialog.tsx b/packages/dashboard-ui/src/spree/delivery-form-dialog.tsxnew file mode 100644index 0000000000..38101f4c79--- /dev/null+++ b/packages/dashboard-ui/src/spree/delivery-form-dialog.tsx@@ -0,0 +1,166 @@+import type { UseFormReturn } from 'react-hook-form'+import { Controller } from 'react-hook-form'+import { useTranslation } from 'react-i18next'+import { Button } from '../ui/button'+import {+ Combobox,+ ComboboxButtonTrigger,+ ComboboxContent,+ ComboboxEmpty,+ ComboboxItem,+ ComboboxList,+ ComboboxSearch,+ ComboboxTriggerPlaceholder,+ ComboboxValue,+} from '../ui/combobox'+import {+ Dialog,+ DialogBody,+ DialogContent,+ DialogDescription,+ DialogFooter,+ DialogHeader,+ DialogTitle,+} from '../ui/dialog'+import { Field, FieldError, FieldLabel } from '../ui/field'+import { Input } from '../ui/input'++/** The form shape both panels bind for one consignment. */+export type DeliveryFormFields = {+ tracking_number: string+ carrier: string+}++/**+ * Records a tracked consignment on a parcel, or corrects one. A parcel can+ * carry several — three boxes, or a freight PRO number covering a pallet —+ * and each travels on its own carrier status.+ *+ * Shared by the operator's order page and the seller's. Headless: the caller+ * owns the form and the submit, so each panel keeps its own mutation, while+ * the carrier field's contract lives here — the value stored is the carrier's+ * key rather than its display name, and anything off the list stays as typed+ * because a forwarder's own name has to be enterable.+ */+export function DeliveryFormDialog({+ form,+ open,+ onOpenChange,+ editing,+ carrierKeys,+ carrierLabel,+ onSubmit,+ pending = false,+}: {+ form: UseFormReturn<DeliveryFormFields>+ open: boolean+ onOpenChange: (open: boolean) => void+ /** Correcting an existing consignment rather than adding one. */+ editing: boolean+ carrierKeys: string[]+ carrierLabel: (key: string) => string+ onSubmit: (values: DeliveryFormFields) => void | Promise<void>+ pending?: boolean+}) {+ const { t } = useTranslation()+ const { errors } = form.formState++ return (+ <Dialog open={open} onOpenChange={onOpenChange}>+ <DialogContent>+ <form+ onSubmit={(event) => {+ // The order page renders its cards inside their own forms — without+ // stopping the bubble the browser submits the outer one.+ form.handleSubmit(onSubmit)(event)+ event.stopPropagation()+ }}+ >+ <DialogHeader>+ <DialogTitle>+ {editing+ ? t('admin.orders.detail.fulfillments.edit_tracking_title')+ : t('admin.orders.detail.fulfillments.add_tracking_title')}+ </DialogTitle>+ <DialogDescription>+ {t('admin.orders.detail.fulfillments.tracking_description')}+ </DialogDescription>+ </DialogHeader>++ <DialogBody className="flex flex-col gap-4">+ {errors.root?.message && (+ <p className="text-destructive text-sm" role="alert">+ {errors.root.message}+ </p>+ )}++ <div className="grid grid-cols-1 gap-4 sm:grid-cols-2">+ <Field>+ <FieldLabel htmlFor="delivery-tracking-number">+ {t('admin.orders.fulfill.tracking_label')}+ </FieldLabel>+ <Input+ id="delivery-tracking-number"+ placeholder={t('admin.orders.fulfill.tracking_placeholder')}+ aria-invalid={!!errors.tracking_number}+ {...form.register('tracking_number')}+ />+ <FieldError errors={[errors.tracking_number]} />+ </Field>++ <Field>+ <FieldLabel htmlFor="delivery-carrier">+ {t('admin.orders.detail.fulfillments.carrier_label')}+ </FieldLabel>+ <Controller+ control={form.control}+ name="carrier"+ render={({ field }) => (+ <Combobox+ items={carrierKeys}+ value={field.value}+ onValueChange={(value: string | null) => field.onChange(value ?? '')}+ itemToStringLabel={carrierLabel}+ >+ <ComboboxButtonTrigger id="delivery-carrier" onBlur={field.onBlur}>+ {field.value ? (+ <ComboboxValue />+ ) : (+ <ComboboxTriggerPlaceholder>+ {t('admin.orders.detail.fulfillments.carrier_auto')}+ </ComboboxTriggerPlaceholder>+ )}+ </ComboboxButtonTrigger>+ <ComboboxContent>+ <ComboboxSearch+ placeholder={t('admin.orders.detail.fulfillments.carrier_search')}+ />+ <ComboboxEmpty>{t('admin.common.no_results')}</ComboboxEmpty>+ <ComboboxList>+ {(value: string) => (+ <ComboboxItem key={value} value={value}>+ {carrierLabel(value)}+ </ComboboxItem>+ )}+ </ComboboxList>+ </ComboboxContent>+ </Combobox>+ )}+ />+ </Field>+ </div>+ </DialogBody>++ <DialogFooter>+ <Button type="button" variant="outline" onClick={() => onOpenChange(false)}>+ {t('admin.actions.cancel')}+ </Button>+ <Button type="submit" disabled={pending}>+ {pending ? t('admin.actions.saving') : t('admin.actions.save')}+ </Button>+ </DialogFooter>+ </form>+ </DialogContent>+ </Dialog>+ )+}diff --git a/packages/dashboard-ui/src/spree/fulfill-items-form.tsx b/packages/dashboard-ui/src/spree/fulfill-items-form.tsxnew file mode 100644index 0000000000..6738b08562--- /dev/null+++ b/packages/dashboard-ui/src/spree/fulfill-items-form.tsx@@ -0,0 +1,264 @@+import type { UseFormReturn } from 'react-hook-form'+import { Controller } from 'react-hook-form'+import { useTranslation } from 'react-i18next'+import { cn } from '../lib/utils'+import { Alert, AlertDescription } from '../ui/alert'+import { Button } from '../ui/button'+import { Checkbox } from '../ui/checkbox'+import { Field, FieldLabel } from '../ui/field'+import { Input } from '../ui/input'+import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue } from '../ui/select'+import { Thumbnail } from '../ui/thumbnail'+import { PackageIcon, TriangleAlertIcon } from './icons'++/** A pickable row: what it looks like and how many units are on offer. */+export type FulfillableRowData = {+ key: string+ itemId: string+ name: string+ optionsText?: string | null+ thumbnailUrl?: string | null+ quantity: number+}++/** The form shape both panels bind — see the shared fulfillment schema. */+export type FulfillItemsValues = {+ items: Array<{ item_id: string; selected: boolean; quantity: number }>+ tracking: string+ tracking_carrier: string+ notify_customer: boolean+}++function ItemQuantityRow({+ row,+ index,+ selected,+ idPrefix,+ form,+}: {+ row: FulfillableRowData+ index: number+ selected: boolean+ /** Scopes the field ids, since an order can show several of these forms. */+ idPrefix: string+ form: UseFormReturn<FulfillItemsValues>+}) {+ const { t } = useTranslation()+ const checkboxId = `${idPrefix}-item-${index}`++ return (+ <div+ className={cn('my-2 flex items-center gap-3 rounded-lg py-2 pl-2', selected && 'bg-accent')}+ >+ <Controller+ control={form.control}+ name={`items.${index}.selected`}+ render={({ field }) => (+ <Checkbox+ id={checkboxId}+ checked={field.value}+ aria-label={t('admin.orders.fulfill.include_item', { name: row.name })}+ onCheckedChange={(checked) => {+ const include = checked === true+ field.onChange(include)+ // Re-checking restores the full held quantity, so the merchant+ // never has to retype what they just excluded.+ form.setValue(`items.${index}.quantity`, include ? row.quantity : 0, {+ shouldDirty: true,+ })+ }}+ />+ )}+ />++ <Thumbnail src={row.thumbnailUrl} fallback={<PackageIcon />} />++ <div className="min-w-0 flex-1">+ <div className="truncate font-medium text-sm">{row.name}</div>+ {row.optionsText && (+ <div className="truncate text-muted-foreground text-xs">{row.optionsText}</div>+ )}+ </div>++ <Controller+ control={form.control}+ name={`items.${index}.quantity`}+ render={({ field }) => (+ <div className="flex shrink-0 items-center gap-2">+ <Input+ type="number"+ min={0}+ max={row.quantity}+ className="w-20 text-right"+ disabled={!selected}+ aria-label={t('admin.orders.fulfill.quantity_for', { name: row.name })}+ value={field.value}+ onChange={(event) => {+ const parsed = Number(event.target.value)+ const quantity = Number.isFinite(parsed)+ ? Math.max(0, Math.min(parsed, row.quantity))+ : 0+ field.onChange(quantity)+ // Typing the quantity down to zero is the same statement as+ // unticking the row, so keep the two in step.+ form.setValue(`items.${index}.selected`, quantity > 0, { shouldDirty: true })+ }}+ onBlur={field.onBlur}+ />+ <span className="w-16 whitespace-nowrap text-muted-foreground text-sm">+ {t('admin.orders.fulfill.of_units', { count: row.quantity })}+ </span>+ </div>+ )}+ />+ </div>+ )+}++/**+ * Picks what to ship out of one fulfillment, in place of the card's normal+ * contents. Shipping everything is the default; lowering a quantity or+ * unticking an item splits the chosen units into a new fulfillment that ships,+ * leaving the rest of this one open.+ *+ * Shared by the operator's order page and the seller's. Headless: the caller+ * owns the form instance and the submit, so each panel keeps its own mutation+ * and its own idea of who may ship — this holds the shape and the+ * select/quantity coupling so the two cannot drift.+ */+export function FulfillItemsForm({+ form,+ rows,+ idPrefix,+ carrierOptions,+ onSubmit,+ onCancel,+ pending = false,+}: {+ form: UseFormReturn<FulfillItemsValues>+ rows: FulfillableRowData[]+ idPrefix: string+ /** Carriers to choose between; the first is normally "detect from number". */+ carrierOptions: Array<{ value: string; label: string }>+ onSubmit: (values: FulfillItemsValues) => void | Promise<void>+ onCancel: () => void+ pending?: boolean+}) {+ const { t } = useTranslation()+ const { errors } = form.formState++ const watched = form.watch('items')+ const totalSelected = watched.reduce(+ (sum, item) => sum + (item.selected ? item.quantity || 0 : 0),+ 0,+ )+ const totalAvailable = rows.reduce((sum, row) => sum + row.quantity, 0)+ const shipsEverything = totalSelected === totalAvailable++ return (+ <form onSubmit={form.handleSubmit(onSubmit)} className="flex flex-col">+ {errors.root?.message && (+ <p className="text-destructive text-sm" role="alert">+ {errors.root.message}+ </p>+ )}++ {rows.length === 0 ? (+ <p className="py-6 text-center text-muted-foreground">{t('admin.orders.fulfill.empty')}</p>+ ) : (+ <div className="divide-y">+ {rows.map((row, index) => (+ <ItemQuantityRow+ key={row.key}+ row={row}+ index={index}+ selected={watched[index]?.selected ?? true}+ idPrefix={idPrefix}+ form={form}+ />+ ))}+ </div>+ )}++ <div className="grid grid-cols-1 gap-4 border-border-subtle border-t py-3 sm:grid-cols-2">+ <Field>+ <FieldLabel htmlFor={`${idPrefix}-tracking`}>+ {t('admin.orders.fulfill.tracking_label')}+ </FieldLabel>+ <Input+ id={`${idPrefix}-tracking`}+ placeholder={t('admin.orders.fulfill.tracking_placeholder')}+ {...form.register('tracking')}+ />+ </Field>++ <Field>+ <FieldLabel htmlFor={`${idPrefix}-tracking-carrier`}>+ {t('admin.orders.detail.fulfillments.carrier_label')}+ </FieldLabel>+ <Controller+ control={form.control}+ name="tracking_carrier"+ render={({ field }) => (+ <Select+ items={carrierOptions}+ value={field.value}+ onValueChange={(value) => field.onChange(value ?? '')}+ >+ <SelectTrigger id={`${idPrefix}-tracking-carrier`}>+ <SelectValue />+ </SelectTrigger>+ <SelectContent>+ {carrierOptions.map((option) => (+ <SelectItem key={option.value} value={option.value}>+ {option.label}+ </SelectItem>+ ))}+ </SelectContent>+ </Select>+ )}+ />+ </Field>+ </div>++ <Controller+ control={form.control}+ name="notify_customer"+ render={({ field }) => (+ <label+ htmlFor={`${idPrefix}-notify`}+ className="flex cursor-pointer items-center gap-2 py-3 text-sm"+ >+ <Checkbox+ id={`${idPrefix}-notify`}+ checked={field.value}+ onCheckedChange={(checked) => field.onChange(checked === true)}+ />+ {t('admin.orders.fulfill.notify_customer')}+ </label>+ )}+ />++ {!shipsEverything && totalSelected > 0 && (+ <div className="px-3 pb-3">+ <Alert variant="warning">+ <TriangleAlertIcon />+ <AlertDescription>{t('admin.orders.fulfill.partial_hint')}</AlertDescription>+ </Alert>+ </div>+ )}++ <div className="flex items-center justify-end gap-2 border-border-subtle border-t py-3">+ <span className="mr-auto text-muted-foreground text-sm">+ {t('admin.orders.fulfill.units_selected')}: {totalSelected} / {totalAvailable}+ </span>+ <Button type="button" size="sm" variant="outline" onClick={onCancel}>+ {t('admin.actions.cancel')}+ </Button>+ <Button type="submit" size="sm" disabled={totalSelected === 0 || pending}>+ {pending ? t('admin.actions.saving') : t('admin.orders.fulfill.submit')}+ </Button>+ </div>+ </form>+ )+}diff --git a/packages/dashboard-ui/src/spree/fulfillment-item-list.tsx b/packages/dashboard-ui/src/spree/fulfillment-item-list.tsxnew file mode 100644index 0000000000..cd17e62522--- /dev/null+++ b/packages/dashboard-ui/src/spree/fulfillment-item-list.tsx@@ -0,0 +1,61 @@+import { Thumbnail } from '../ui/thumbnail'+import { PackageIcon } from './icons'++/**+ * One row of a fulfillment's item list, already joined to its line item by+ * the caller. The image and the price are optional: a surface that does not+ * expose them renders the name and the count alone.+ */+export type FulfillmentItemRowData = {+ key: string+ name: string+ optionsText?: string | null+ thumbnailUrl?: string | null+ displayPrice?: string | null+ quantity: number+}++/**+ * What a fulfillment holds: what it looks like, what it costs and how many+ * units travel together.+ *+ * Read-only — changing what an order contains after placement belongs to the+ * order edit screen, not here. Shared by the operator's order page and the+ * seller's so a parcel's contents read the same on both.+ */+function ItemRow({ row }: { row: FulfillmentItemRowData }) {+ return (+ <div className="flex items-center gap-3 p-3">+ <Thumbnail src={row.thumbnailUrl} fallback={<PackageIcon />} />++ <div className="min-w-0 flex-1">+ <div className="truncate text-sm font-medium">{row.name}</div>+ {row.optionsText && (+ <div className="truncate text-xs text-muted-foreground">{row.optionsText}</div>+ )}+ </div>++ <div className="shrink-0 whitespace-nowrap text-right text-muted-foreground text-sm">+ {row.displayPrice ? (+ <span>+ {row.displayPrice} × {row.quantity}+ </span>+ ) : (+ <span>× {row.quantity}</span>+ )}+ </div>+ </div>+ )+}++export function FulfillmentItemList({ rows }: { rows: FulfillmentItemRowData[] }) {+ if (rows.length === 0) return null++ return (+ <div className="divide-y">+ {rows.map((row) => (+ <ItemRow key={row.key} row={row} />+ ))}+ </div>+ )+}diff --git a/packages/dashboard-ui/src/spree/fulfillment-panel.tsx b/packages/dashboard-ui/src/spree/fulfillment-panel.tsxnew file mode 100644index 0000000000..6793df7c70--- /dev/null+++ b/packages/dashboard-ui/src/spree/fulfillment-panel.tsx@@ -0,0 +1,53 @@+import type { ReactNode } from 'react'+import { StatusBadge } from '../ui/badge'+import { Card, CardAction, CardHeader, CardTitle } from '../ui/card'+import { MapPinIcon } from './icons'++/**+ * The nested card one parcel occupies on an order page: what state it is in,+ * where it ships from, and its own menu.+ *+ * Shared by the operator's order page and the seller's, so a parcel reads the+ * same on both sides of a marketplace. Headless — the status label and every+ * action come from the caller.+ */+export function FulfillmentPanel({+ status,+ statusLabel,+ location,+ meta,+ actions,+ children,+}: {+ status: string+ /** Omit to let the badge humanize the status itself. */+ statusLabel?: string+ /** Where it ships from. Absent until a fulfillment exists. */+ location?: string | null+ /** Trailing header detail, e.g. when it shipped. */+ meta?: ReactNode+ /** The panel's own menu. Absent when there is nothing to act on. */+ actions?: ReactNode+ children: ReactNode+}) {+ return (+ <Card variant="nested">+ <CardHeader>+ <CardTitle className="min-w-0 font-normal text-sm">+ <StatusBadge status={status} label={statusLabel} />+ {location && (+ <div className="flex min-w-0 items-center gap-1.5 text-muted-foreground text-xs">+ <MapPinIcon className="size-3 shrink-0" />+ {/* The card clips its overflow, so a long warehouse name has to+ truncate here or it is simply cut off. */}+ <span className="truncate">{location}</span>+ </div>+ )}+ {meta}+ </CardTitle>+ {actions && <CardAction>{actions}</CardAction>}+ </CardHeader>+ {children}+ </Card>+ )+}diff --git a/packages/dashboard/src/components/spree/orders/fulfillment-delivery-dialog.tsx b/packages/dashboard/src/components/spree/orders/fulfillment-delivery-dialog.tsxindex 1dd46bc8f2..bc9b772d21 100644--- a/packages/dashboard/src/components/spree/orders/fulfillment-delivery-dialog.tsx+++ b/packages/dashboard/src/components/spree/orders/fulfillment-delivery-dialog.tsx@@ -1,49 +1,16 @@import { zodResolver } from '@hookform/resolvers/zod'import type { Delivery } from '@spree/admin-sdk'-import { mapSpreeErrorsToForm } from '@spree/dashboard-core'import {- Button,- Combobox,- ComboboxButtonTrigger,- ComboboxContent,- ComboboxEmpty,- ComboboxItem,- ComboboxList,- ComboboxSearch,- ComboboxTriggerPlaceholder,- ComboboxValue,- Dialog,- DialogBody,- DialogContent,- DialogDescription,- DialogFooter,- DialogHeader,- DialogTitle,- Field,- FieldError,- FieldLabel,- Input,-} from '@spree/dashboard-ui'-import { Controller, useForm } from 'react-hook-form'-import { useTranslation } from 'react-i18next'-import { z } from 'zod'+ type DeliveryFormValues,+ deliveryFormSchema,+ mapSpreeErrorsToForm,+} from '@spree/dashboard-core'+import { DeliveryFormDialog } from '@spree/dashboard-ui'+import { useForm } from 'react-hook-form'import { useFulfillmentActions } from '../../../hooks/use-fulfillments'import { useTrackingCarriers } from '../../../hooks/use-tracking-carriers'-const deliverySchema = z.object({- tracking_number: z.string().min(1),- // Free text: a forwarder's own name is as valid as a registered carrier,- // and an empty value asks the server to detect one from the number.- carrier: z.string(),-})--type DeliveryFormValues = z.infer<typeof deliverySchema>--/**- * Records a tracked consignment on a parcel, or corrects one. A parcel can- * carry several — three boxes, or a freight PRO number covering a pallet —- * and each travels on its own carrier status.- */+/** What the operator records against one consignment of a parcel. */export function FulfillmentDeliveryDialog({orderId,fulfillmentId,@@ -57,32 +24,22 @@ export function FulfillmentDeliveryDialog({open: booleanonOpenChange: (open: boolean) => void}) {- const { t } = useTranslation()const { createDelivery, updateDelivery } = useFulfillmentActions(orderId)const { data: carriersData } = useTrackingCarriers(open)- // The picker offers what the registry knows, but the value stored is the- // carrier's key — seeding it with the display name would rewrite a known- // carrier to its own label on the next save. Anything not on the list is- // still typeable, because a forwarder's own name has to be enterable.- const carrierOptions = (carriersData?.data ?? []).map((carrier) => ({- value: carrier.id,- label: carrier.name,- }))-+ const carriers = carriersData?.data ?? []+ const carrierKeys = carriers.map((carrier) => carrier.id)const carrierLabel = (value: string) =>- carrierOptions.find((option) => option.value === value)?.label ?? value+ carriers.find((carrier) => carrier.id === value)?.name ?? valueconst form = useForm<DeliveryFormValues>({- resolver: zodResolver(deliverySchema),+ resolver: zodResolver(deliveryFormSchema),defaultValues: {tracking_number: delivery?.tracking_number ?? '',carrier: delivery?.carrier ?? '',},})- const pending = createDelivery.isPending || updateDelivery.isPending-async function onSubmit(values: DeliveryFormValues) {try {const tracking_number = values.tracking_number.trim()@@ -111,101 +68,15 @@ export function FulfillmentDeliveryDialog({}return (- <Dialog open={open} onOpenChange={onOpenChange}>- <DialogContent>- <form- onSubmit={(event) => {- // The order page renders its cards inside their own forms — without- // stopping the bubble the browser submits the outer one.- form.handleSubmit(onSubmit)(event)- event.stopPropagation()- }}- >- <DialogHeader>- <DialogTitle>- {delivery- ? t('admin.orders.detail.fulfillments.edit_tracking_title')- : t('admin.orders.detail.fulfillments.add_tracking_title')}- </DialogTitle>- <DialogDescription>- {t('admin.orders.detail.fulfillments.tracking_description')}- </DialogDescription>- </DialogHeader>-- <DialogBody className="flex flex-col gap-4">- {form.formState.errors.root?.message && (- <p className="text-sm text-destructive" role="alert">- {form.formState.errors.root.message}- </p>- )}-- <div className="grid grid-cols-1 gap-4 sm:grid-cols-2">- <Field>- <FieldLabel htmlFor="delivery-tracking-number">- {t('admin.orders.fulfill.tracking_label')}- </FieldLabel>- <Input- id="delivery-tracking-number"- placeholder={t('admin.orders.fulfill.tracking_placeholder')}- aria-invalid={!!form.formState.errors.tracking_number}- {...form.register('tracking_number')}- />- <FieldError errors={[form.formState.errors.tracking_number]} />- </Field>-- <Field>- <FieldLabel htmlFor="delivery-carrier">- {t('admin.orders.detail.fulfillments.carrier_label')}- </FieldLabel>- <Controller- control={form.control}- name="carrier"- render={({ field }) => (- <Combobox- items={carrierOptions.map((option) => option.value)}- value={field.value}- onValueChange={(value: string | null) => field.onChange(value ?? '')}- itemToStringLabel={carrierLabel}- >- <ComboboxButtonTrigger id="delivery-carrier" onBlur={field.onBlur}>- {field.value ? (- <ComboboxValue />- ) : (- <ComboboxTriggerPlaceholder>- {t('admin.orders.detail.fulfillments.carrier_auto')}- </ComboboxTriggerPlaceholder>- )}- </ComboboxButtonTrigger>- <ComboboxContent>- <ComboboxSearch- placeholder={t('admin.orders.detail.fulfillments.carrier_search')}- />- <ComboboxEmpty>{t('admin.common.no_results')}</ComboboxEmpty>- <ComboboxList>- {(value: string) => (- <ComboboxItem key={value} value={value}>- {carrierLabel(value)}- </ComboboxItem>- )}- </ComboboxList>- </ComboboxContent>- </Combobox>- )}- />- </Field>- </div>- </DialogBody>-- <DialogFooter>- <Button type="button" variant="outline" onClick={() => onOpenChange(false)}>- {t('admin.actions.cancel')}- </Button>- <Button type="submit" disabled={pending}>- {pending ? t('admin.actions.saving') : t('admin.actions.save')}- </Button>- </DialogFooter>- </form>- </DialogContent>- </Dialog>+ <DeliveryFormDialog+ form={form}+ open={open}+ onOpenChange={onOpenChange}+ editing={!!delivery}+ carrierKeys={carrierKeys}+ carrierLabel={carrierLabel}+ onSubmit={onSubmit}+ pending={createDelivery.isPending || updateDelivery.isPending}+ />)}diff --git a/packages/dashboard/src/components/spree/orders/fulfillment-fulfill-form.tsx b/packages/dashboard/src/components/spree/orders/fulfillment-fulfill-form.tsxindex 6912364fe4..3084c58ebb 100644--- a/packages/dashboard/src/components/spree/orders/fulfillment-fulfill-form.tsx+++ b/packages/dashboard/src/components/spree/orders/fulfillment-fulfill-form.tsx@@ -1,138 +1,33 @@import { zodResolver } from '@hookform/resolvers/zod'import type { Fulfillment, Order } from '@spree/admin-sdk'-import { mapSpreeErrorsToForm } from '@spree/dashboard-core'import {- Alert,- AlertDescription,- Button,- Checkbox,- cn,- Field,- FieldLabel,- Input,- Select,- SelectContent,- SelectItem,- SelectTrigger,- SelectValue,- Thumbnail,+ type FulfillmentItemRow,+ fulfillmentItemRows,+ mapSpreeErrorsToForm,+} from '@spree/dashboard-core'+import {+ type FulfillableRowData,+ FulfillItemsForm,+ type FulfillItemsValues,} from '@spree/dashboard-ui'-import { PackageIcon, TriangleAlertIcon } from '@spree/dashboard-ui/icons'import { useEffect, useRef } from 'react'-import { Controller, type UseFormReturn, useForm } from 'react-hook-form'+import { useForm } from 'react-hook-form'import { useTranslation } from 'react-i18next'import { useFulfillmentActions } from '../../../hooks/use-fulfillments'import { useTrackingCarriers } from '../../../hooks/use-tracking-carriers'-import { type FulfillmentItemRow, fulfillmentItemRows } from '../../../lib/fulfillment-items'import { type FulfillItemsFormValues, fulfillItemsFormSchema } from '../../../schemas/fulfillment'-/** A row the merchant can pick a quantity for, and the line item it addresses. */-interface FulfillableRow extends FulfillmentItemRow {- itemId: string-}-/*** Rows whose fulfillment item no longer maps to a line item are dropped: the* fulfill endpoint addresses items by line item, so there is nothing to send* for them. They still ship — selecting everything else sends no `items` at* all, which ships the whole fulfillment including them.*/-function fulfillableRows(rows: FulfillmentItemRow[]): FulfillableRow[] {+function fulfillableRows(rows: FulfillmentItemRow[]): FulfillableRowData[] {return rows.flatMap((row) => (row.lineItem ? [{ ...row, itemId: row.lineItem.id }] : []))}-function ItemQuantityRow({- row,- index,- selected,- idPrefix,- form,-}: {- row: FulfillableRow- index: number- selected: boolean- /** Scopes the field ids, since an order can show several of these forms. */- idPrefix: string- form: UseFormReturn<FulfillItemsFormValues>-}) {- const { t } = useTranslation()- const checkboxId = `${idPrefix}-item-${index}`-- return (- <div- className={cn('flex items-center gap-3 py-2 my-2 pl-2 rounded-lg', selected && 'bg-accent')}- >- <Controller- control={form.control}- name={`items.${index}.selected`}- render={({ field }) => (- <Checkbox- id={checkboxId}- checked={field.value}- aria-label={t('admin.orders.fulfill.include_item', { name: row.name })}- onCheckedChange={(checked) => {- const include = checked === true- field.onChange(include)- // Re-checking restores the full held quantity, so the merchant- // never has to retype what they just excluded.- form.setValue(`items.${index}.quantity`, include ? row.quantity : 0, {- shouldDirty: true,- })- }}- />- )}- />-- <Thumbnail src={row.thumbnailUrl} fallback={<PackageIcon />} />-- <div className="min-w-0 flex-1">- <div className="truncate text-sm font-medium">{row.name}</div>- {row.optionsText && (- <div className="truncate text-xs text-muted-foreground">{row.optionsText}</div>- )}- </div>-- <Controller- control={form.control}- name={`items.${index}.quantity`}- render={({ field }) => (- <div className="flex shrink-0 items-center gap-2">- <Input- type="number"- min={0}- max={row.quantity}- className="w-20 text-right"- disabled={!selected}- aria-label={t('admin.orders.fulfill.quantity_for', { name: row.name })}- value={field.value}- onChange={(event) => {- const parsed = Number(event.target.value)- const quantity = Number.isFinite(parsed)- ? Math.max(0, Math.min(parsed, row.quantity))- : 0- field.onChange(quantity)- // Typing the quantity down to zero is the same statement as- // unticking the row, so keep the two in step.- form.setValue(`items.${index}.selected`, quantity > 0, { shouldDirty: true })- }}- onBlur={field.onBlur}- />- <span className="w-16 text-sm whitespace-nowrap text-muted-foreground">- {t('admin.orders.fulfill.of_units', { count: row.quantity })}- </span>- </div>- )}- />- </div>- )-}--/**- * Picks what to ship out of one fulfillment, in place of the card's normal- * contents. Shipping everything is the default; lowering a quantity or- * unticking an item splits the chosen units into a new fulfillment that ships,- * leaving the rest of this one open.- */+/** What the operator ships out of one fulfillment. */export function FulfillmentFulfillForm({order,fulfillment,@@ -165,7 +60,6 @@ export function FulfillmentFulfillForm({notify_customer: true,},})- const { errors } = form.formState// A refetch re-renders this form with fresh rows, so the values it mirrors// have to follow. The effect keys on the fulfillment's composition, not on@@ -190,22 +84,16 @@ export function FulfillmentFulfillForm({})}, [rowsKey, form])- const watched = form.watch('items')- const totalSelected = watched.reduce(- (sum, item) => sum + (item.selected ? item.quantity || 0 : 0),- 0,- )const totalAvailable = rows.reduce((sum, row) => sum + row.quantity, 0)- const shipsEverything = totalSelected === totalAvailable- async function onSubmit(values: FulfillItemsFormValues) {+ async function onSubmit(values: FulfillItemsValues) {const items = values.items.filter((item) => item.selected && item.quantity > 0).map((item) => ({ item_id: item.item_id, quantity: item.quantity }))if (items.length === 0) return- // Recomputed from the submitted values rather than reusing the watched- // total, so the branch is decided by exactly what is being sent.+ // Recomputed from the submitted values rather than a watched total, so the+ // branch is decided by exactly what is being sent.const everything = items.reduce((sum, item) => sum + item.quantity, 0) === totalAvailableconst tracking = values.tracking.trim()@@ -226,109 +114,14 @@ export function FulfillmentFulfillForm({}return (- <form onSubmit={form.handleSubmit(onSubmit)} className="flex flex-col">- {errors.root?.message && (- <p className="text-sm text-destructive" role="alert">- {errors.root.message}- </p>- )}-- {rows.length === 0 ? (- <p className="py-6 text-center text-muted-foreground">{t('admin.orders.fulfill.empty')}</p>- ) : (- <div className="divide-y">- {rows.map((row, index) => (- <ItemQuantityRow- key={row.key}- row={row}- index={index}- selected={watched[index]?.selected ?? true}- idPrefix={idPrefix}- form={form}- />- ))}- </div>- )}-- <div className="grid grid-cols-1 gap-4 py-3 border-t border-border-subtle sm:grid-cols-2">- <Field>- <FieldLabel htmlFor={`${idPrefix}-tracking`}>- {t('admin.orders.fulfill.tracking_label')}- </FieldLabel>- <Input- id={`${idPrefix}-tracking`}- placeholder={t('admin.orders.fulfill.tracking_placeholder')}- {...form.register('tracking')}- />- </Field>-- <Field>- <FieldLabel htmlFor={`${idPrefix}-tracking-carrier`}>- {t('admin.orders.detail.fulfillments.carrier_label')}- </FieldLabel>- <Controller- control={form.control}- name="tracking_carrier"- render={({ field }) => (- <Select- items={carrierOptions}- value={field.value}- onValueChange={(value) => field.onChange(value ?? '')}- >- <SelectTrigger id={`${idPrefix}-tracking-carrier`}>- <SelectValue />- </SelectTrigger>- <SelectContent>- {carrierOptions.map((option) => (- <SelectItem key={option.value} value={option.value}>- {option.label}- </SelectItem>- ))}- </SelectContent>- </Select>- )}- />- </Field>- </div>-- <Controller- control={form.control}- name="notify_customer"- render={({ field }) => (- <label- htmlFor={`${idPrefix}-notify`}- className="flex cursor-pointer items-center gap-2 text-sm py-3"- >- <Checkbox- id={`${idPrefix}-notify`}- checked={field.value}- onCheckedChange={(checked) => field.onChange(checked === true)}- />- {t('admin.orders.fulfill.notify_customer')}- </label>- )}- />-- {!shipsEverything && totalSelected > 0 && (- <div className="px-3 pb-3">- <Alert variant="warning">- <TriangleAlertIcon />- <AlertDescription>{t('admin.orders.fulfill.partial_hint')}</AlertDescription>- </Alert>- </div>- )}-- <div className="flex items-center justify-end gap-2 py-3 border-t border-border-subtle">- <span className="mr-auto text-sm text-muted-foreground">- {t('admin.orders.fulfill.units_selected')}: {totalSelected} / {totalAvailable}- </span>- <Button type="button" size="sm" variant="outline" onClick={onDone}>- {t('admin.actions.cancel')}- </Button>- <Button type="submit" size="sm" disabled={totalSelected === 0 || fulfill.isPending}>- {fulfill.isPending ? t('admin.actions.saving') : t('admin.orders.fulfill.submit')}- </Button>- </div>- </form>+ <FulfillItemsForm+ form={form}+ rows={rows}+ idPrefix={idPrefix}+ carrierOptions={carrierOptions}+ onSubmit={onSubmit}+ onCancel={onDone}+ pending={fulfill.isPending}+ />)}diff --git a/packages/dashboard/src/components/spree/orders/fulfillment-item-list.tsx b/packages/dashboard/src/components/spree/orders/fulfillment-item-list.tsxdeleted file mode 100644index 9ac2f8b214..0000000000--- a/packages/dashboard/src/components/spree/orders/fulfillment-item-list.tsx+++ /dev/null@@ -1,46 +0,0 @@-import { Thumbnail } from '@spree/dashboard-ui'-import { PackageIcon } from '@spree/dashboard-ui/icons'-import type { FulfillmentItemRow } from '../../../lib/fulfillment-items'--/**- * One item inside a fulfillment group: what it looks like, what it costs and- * how many units this group holds. Read-only — changing what an order contains- * after placement belongs to the order edit screen, not here.- */-function ItemRow({ row }: { row: FulfillmentItemRow }) {- return (- <div className="flex items-center gap-3 p-3">- <Thumbnail src={row.thumbnailUrl} fallback={<PackageIcon />} />-- <div className="min-w-0 flex-1">- <div className="truncate text-sm font-medium">{row.name}</div>- {row.optionsText && (- <div className="truncate text-xs text-muted-foreground">{row.optionsText}</div>- )}- </div>-- <div className="shrink-0 text-right text-sm whitespace-nowrap text-muted-foreground">- {row.displayPrice ? (- <span>- {row.displayPrice} × {row.quantity}- </span>- ) : (- <span>× {row.quantity}</span>- )}- </div>- </div>- )-}--/** The item list rendered inside a fulfillment group. */-export function FulfillmentItemList({ rows }: { rows: FulfillmentItemRow[] }) {- if (rows.length === 0) return null-- return (- <div className="divide-y">- {rows.map((row) => (- <ItemRow key={row.key} row={row} />- ))}- </div>- )-}diff --git a/packages/dashboard/src/components/spree/orders/fulfillments-card.tsx b/packages/dashboard/src/components/spree/orders/fulfillments-card.tsxindex d3cf772ff3..4fb0a88b51 100644--- a/packages/dashboard/src/components/spree/orders/fulfillments-card.tsx+++ b/packages/dashboard/src/components/spree/orders/fulfillments-card.tsx@@ -1,5 +1,10 @@import type { Delivery, Fulfillment, Order } from '@spree/admin-sdk'-import { useStockLocations } from '@spree/dashboard-core'+import {+ type FulfillmentItemRow,+ fulfillmentItemRows,+ unfulfilledItemRows,+ useStockLocations,+} from '@spree/dashboard-core'import {Badge,Button,@@ -25,6 +30,8 @@ import {FieldError,FieldGroup,FieldLabel,+ FulfillmentItemList,+ FulfillmentPanel,Input,RelativeTime,Select,@@ -38,7 +45,6 @@ import {} from '@spree/dashboard-ui'import {EllipsisVerticalIcon,- MapPinIcon,PackageCheckIcon,PencilIcon,PlusIcon,@@ -48,20 +54,14 @@ import {TruckIcon,XCircleIcon,} from '@spree/dashboard-ui/icons'-import { type ReactNode, useState } from 'react'+import { useState } from 'react'import { useTranslation } from 'react-i18next'import { useFulfillmentActions } from '../../../hooks/use-fulfillments'-import {- type FulfillmentItemRow,- fulfillmentItemRows,- unfulfilledItemRows,-} from '../../../lib/fulfillment-items'import { printPackingSlip } from '../../../lib/packing-slip'import { FulfillmentDeliveries } from './fulfillment-deliveries'import { FulfillmentDeliveryDialog } from './fulfillment-delivery-dialog'import { FulfillmentEditDialog } from './fulfillment-edit-dialog'import { FulfillmentFulfillForm } from './fulfillment-fulfill-form'-import { FulfillmentItemList } from './fulfillment-item-list'import { FulfillmentLabelUploadDialog } from './fulfillment-label-upload-dialog'import { ShippingDocuments } from './shipping-documents'import { ShippingLabelRow } from './shipping-label-row'@@ -730,44 +730,6 @@ function FulfillmentRow({ order, fulfillment }: { order: Order; fulfillment: Ful* to act on — so the two callers pass what they have rather than one of them* inventing a record. What they do share is how it looks.*/-function FulfillmentPanel({- status,- location,- meta,- actions,- children,-}: {- status: string- /** Where it ships from. Absent until a fulfillment exists. */- location?: string | null- /** Trailing header detail, e.g. when it shipped. */- meta?: ReactNode- /** The panel's own menu. Absent when there is nothing to act on. */- actions?: ReactNode- children: ReactNode-}) {- return (- <Card variant="nested">- <CardHeader>- <CardTitle className="min-w-0 text-sm font-normal">- <StatusBadge status={status} />- {location && (- <div className="flex min-w-0 items-center gap-1.5 text-muted-foreground text-xs">- <MapPinIcon className="size-3 shrink-0" />- {/* The card clips its overflow, so a long warehouse name has to- truncate here or it is simply cut off. */}- <span className="truncate">{location}</span>- </div>- )}- {meta}- </CardTitle>- {actions && <CardAction>{actions}</CardAction>}- </CardHeader>- {children}- </Card>- )-}-/*** Units nobody has put into a fulfillment yet. Reads like a fulfillment group* so the eye can compare it against the real ones, minus the status and numberdiff --git a/packages/dashboard/src/components/spree/orders/order-header.tsx b/packages/dashboard/src/components/spree/orders/order-header.tsxindex 48b00e7051..e165fed236 100644--- a/packages/dashboard/src/components/spree/orders/order-header.tsx+++ b/packages/dashboard/src/components/spree/orders/order-header.tsx@@ -1,5 +1,11 @@import type { Order } from '@spree/admin-sdk'-import { adminClient, PageHeader, useResourceMutation, useStore } from '@spree/dashboard-core'+import {+ adminClient,+ GONE_STATUSES,+ PageHeader,+ useResourceMutation,+ useStore,+} from '@spree/dashboard-core'import {Button,DropdownMenuItem,@@ -19,7 +25,6 @@ import { Link } from '@tanstack/react-router'import { useState } from 'react'import { useTranslation } from 'react-i18next'import { orderQueryKey } from '../../../hooks/use-order'-import { GONE_STATUSES } from '../../../lib/fulfillment-items'import { spreeJsonLinkResolver } from '../../../lib/json-link-resolver'import { OrderCancelDialog } from './order-cancel-dialog'diff --git a/packages/dashboard/src/lib/packing-slip.ts b/packages/dashboard/src/lib/packing-slip.tsindex 00670f34e3..f124a72a93 100644--- a/packages/dashboard/src/lib/packing-slip.ts+++ b/packages/dashboard/src/lib/packing-slip.ts@@ -1,6 +1,6 @@import type { Fulfillment, Order } from '@spree/admin-sdk'+import { type FulfillmentItemRow, fulfillmentItemRows } from '@spree/dashboard-core'import type { TFunction } from 'i18next'-import { type FulfillmentItemRow, fulfillmentItemRows } from './fulfillment-items'function escapeHtml(value: string): string {return valuediff --git a/packages/dashboard/src/routes/_authenticated/$storeId/orders/$orderId/edit.tsx b/packages/dashboard/src/routes/_authenticated/$storeId/orders/$orderId/edit.tsxindex a1f65f957a..e785172e9a 100644--- a/packages/dashboard/src/routes/_authenticated/$storeId/orders/$orderId/edit.tsx+++ b/packages/dashboard/src/routes/_authenticated/$storeId/orders/$orderId/edit.tsx@@ -1,6 +1,12 @@import { zodResolver } from '@hookform/resolvers/zod'import { type Order, SpreeError, type Variant } from '@spree/admin-sdk'-import { adminClient, formatPrice, mapSpreeErrorsToForm, PageHeader } from '@spree/dashboard-core'+import {+ adminClient,+ formatPrice,+ GONE_STATUSES,+ mapSpreeErrorsToForm,+ PageHeader,+} from '@spree/dashboard-core'import {Alert,AlertDescription,@@ -25,7 +31,6 @@ import { useTranslation } from 'react-i18next'import { AddLineItemDialog } from '../../../../../components/spree/orders/line-item-dialogs'import { OrderEditItemsTable } from '../../../../../components/spree/orders/order-edit-items-table'import { useOrder, useOrderMutation } from '../../../../../hooks/use-order'-import { GONE_STATUSES } from '../../../../../lib/fulfillment-items'import {buildOrderItemsPayload,formatAmount,diff --git a/packages/dashboard/src/schemas/order.ts b/packages/dashboard/src/schemas/order.tsindex 769cfa3442..fbad757c7e 100644--- a/packages/dashboard/src/schemas/order.ts+++ b/packages/dashboard/src/schemas/order.ts@@ -1,7 +1,6 @@import type { LineItem, OrderUpdateParams } from '@spree/admin-sdk'-import { i18n } from '@spree/dashboard-core'+import { fulfilledQuantities, type GroupableFulfillment, i18n } from '@spree/dashboard-core'import { z } from 'zod/v4'-import { fulfilledQuantities, type GroupableFulfillment } from '../lib/fulfillment-items'/*** New-order form schema. The "customer OR email" rule is enforced at thediff --git a/packages/seller-dashboard/src/components/orders/fulfillment-deliveries.tsx b/packages/seller-dashboard/src/components/orders/fulfillment-deliveries.tsxindex 3d88243f23..5a191dd161 100644--- a/packages/seller-dashboard/src/components/orders/fulfillment-deliveries.tsx+++ b/packages/seller-dashboard/src/components/orders/fulfillment-deliveries.tsx@@ -50,7 +50,7 @@ export function FulfillmentDeliveries({}return (- <CardContent className="flex flex-col gap-2 border-b py-3 text-sm">+ <CardContent className="flex flex-col gap-2 border-border-subtle border-b py-3 text-sm">{deliveries.map((delivery) => (<div key={delivery.id} className="flex flex-wrap items-center justify-between gap-2"><div className="flex min-w-0 flex-wrap items-center gap-2">@@ -78,13 +78,12 @@ export function FulfillmentDeliveries({</div><DropdownMenu>- <DropdownMenuTrigger- render={- <Button variant="ghost" size="icon" aria-label={t('common.actions')}>- <EllipsisVerticalIcon className="size-4" />- </Button>- }- />+ <DropdownMenuTrigger asChild>+ <Button variant="ghost" size="icon-xs">+ <EllipsisVerticalIcon className="size-4" />+ <span className="sr-only">{t('admin.actions.actions_menu')}</span>+ </Button>+ </DropdownMenuTrigger><DropdownMenuContent align="end"><DropdownMenuItem onClick={() => onEdit(delivery)}><PencilIcon className="size-4" />diff --git a/packages/seller-dashboard/src/components/orders/fulfillment-delivery-dialog.tsx b/packages/seller-dashboard/src/components/orders/fulfillment-delivery-dialog.tsxindex 1067f5ed6b..8ef56e5062 100644--- a/packages/seller-dashboard/src/components/orders/fulfillment-delivery-dialog.tsx+++ b/packages/seller-dashboard/src/components/orders/fulfillment-delivery-dialog.tsx@@ -1,50 +1,16 @@import { zodResolver } from '@hookform/resolvers/zod'-import { mapSpreeErrorsToForm } from '@spree/dashboard-core'import {- Button,- Combobox,- ComboboxButtonTrigger,- ComboboxContent,- ComboboxEmpty,- ComboboxItem,- ComboboxList,- ComboboxSearch,- ComboboxTriggerPlaceholder,- ComboboxValue,- Dialog,- DialogBody,- DialogContent,- DialogDescription,- DialogFooter,- DialogHeader,- DialogTitle,- Field,- FieldError,- FieldLabel,- Input,-} from '@spree/dashboard-ui'+ type DeliveryFormValues,+ deliveryFormSchema,+ mapSpreeErrorsToForm,+} from '@spree/dashboard-core'+import { DeliveryFormDialog } from '@spree/dashboard-ui'import type { Delivery } from '@spree/seller-sdk'-import { Controller, useForm } from 'react-hook-form'-import { useTranslation } from 'react-i18next'-import { z } from 'zod/v4'+import { useForm } from 'react-hook-form'import { useFulfillmentActions } from '../../hooks/use-fulfillments'import { useTrackingCarriers } from '../../hooks/use-reasons'-const deliverySchema = z.object({- tracking_number: z.string().min(1),- // Free text: a forwarder's own name is as valid as a registered carrier,- // and an empty value asks the server to detect one from the number.- carrier: z.string(),-})--type DeliveryFormValues = z.infer<typeof deliverySchema>--/**- * Adds or corrects one consignment of a parcel.- *- * A parcel can travel as several — three boxes, or a pallet under a freight- * PRO number — and each carries its own tracking number and carrier status.- */+/** What the seller records against one consignment of a parcel they ship themselves. */export function FulfillmentDeliveryDialog({orderId,fulfillmentId,@@ -58,37 +24,30 @@ export function FulfillmentDeliveryDialog({open: booleanonOpenChange: (open: boolean) => void}) {- const { t } = useTranslation()const { createDelivery, updateDelivery } = useFulfillmentActions(orderId)const { data: carriersData } = useTrackingCarriers(open)- // Options carry the carrier's key, not its display name — seeding the field- // with a label would rewrite a known carrier to its own name on the next- // save. Anything not on the list is kept as typed.- const carrierOptions = (carriersData?.data ?? []).map((carrier) => ({- value: carrier.id,- label: carrier.name,- }))-+ const carriers = carriersData?.data ?? []+ const carrierKeys = carriers.map((carrier) => carrier.id)const carrierLabel = (value: string) =>- carrierOptions.find((option) => option.value === value)?.label ?? value+ carriers.find((carrier) => carrier.id === value)?.name ?? valueconst form = useForm<DeliveryFormValues>({- resolver: zodResolver(deliverySchema),+ resolver: zodResolver(deliveryFormSchema),defaultValues: {tracking_number: delivery?.tracking_number ?? '',carrier: delivery?.carrier ?? '',},})- const pending = createDelivery.isPending || updateDelivery.isPending-async function onSubmit(values: DeliveryFormValues) {- const tracking_number = values.tracking_number.trim()- const carrier = values.carrier.trim()-try {+ const tracking_number = values.tracking_number.trim()+ const carrier = values.carrier.trim()+if (delivery) {+ // Carrier is sent even when empty: clearing it is how a merchant asks+ // for it to be detected from the number again.await updateDelivery.mutateAsync({fulfillmentId,deliveryId: delivery.id,@@ -109,97 +68,15 @@ export function FulfillmentDeliveryDialog({}return (- <Dialog open={open} onOpenChange={onOpenChange}>- <DialogContent>- <form- onSubmit={(event) => {- // The order page renders its cards inside their own forms — without- // stopping the bubble the browser submits the outer one.- form.handleSubmit(onSubmit)(event)- event.stopPropagation()- }}- >- <DialogHeader>- <DialogTitle>- {delivery- ? t('orders.fulfillments.edit_tracking_title')- : t('orders.fulfillments.add_tracking_title')}- </DialogTitle>- <DialogDescription>{t('orders.fulfillments.tracking_description')}</DialogDescription>- </DialogHeader>-- <DialogBody className="flex flex-col gap-4">- {form.formState.errors.root?.message && (- <p className="text-sm text-destructive" role="alert">- {form.formState.errors.root.message}- </p>- )}-- <div className="grid grid-cols-1 gap-4 sm:grid-cols-2">- <Field>- <FieldLabel htmlFor="delivery-tracking-number">- {t('orders.tracking_label')}- </FieldLabel>- <Input- id="delivery-tracking-number"- placeholder={t('orders.tracking_placeholder')}- aria-invalid={!!form.formState.errors.tracking_number}- {...form.register('tracking_number')}- />- <FieldError errors={[form.formState.errors.tracking_number]} />- </Field>-- <Field>- <FieldLabel htmlFor="delivery-carrier">- {t('orders.fulfillments.carrier_label')}- </FieldLabel>- <Controller- control={form.control}- name="carrier"- render={({ field }) => (- <Combobox- items={carrierOptions.map((option) => option.value)}- value={field.value}- onValueChange={(value: string | null) => field.onChange(value ?? '')}- itemToStringLabel={carrierLabel}- >- <ComboboxButtonTrigger id="delivery-carrier" onBlur={field.onBlur}>- {field.value ? (- <ComboboxValue />- ) : (- <ComboboxTriggerPlaceholder>- {t('orders.fulfillments.carrier_auto')}- </ComboboxTriggerPlaceholder>- )}- </ComboboxButtonTrigger>- <ComboboxContent>- <ComboboxSearch placeholder={t('orders.fulfillments.carrier_search')} />- <ComboboxEmpty>{t('common.no_results')}</ComboboxEmpty>- <ComboboxList>- {(value: string) => (- <ComboboxItem key={value} value={value}>- {carrierLabel(value)}- </ComboboxItem>- )}- </ComboboxList>- </ComboboxContent>- </Combobox>- )}- />- </Field>- </div>- </DialogBody>-- <DialogFooter>- <Button type="button" variant="outline" onClick={() => onOpenChange(false)}>- {t('common.cancel')}- </Button>- <Button type="submit" disabled={pending}>- {pending ? t('common.saving') : t('common.save')}- </Button>- </DialogFooter>- </form>- </DialogContent>- </Dialog>+ <DeliveryFormDialog+ form={form}+ open={open}+ onOpenChange={onOpenChange}+ editing={!!delivery}+ carrierKeys={carrierKeys}+ carrierLabel={carrierLabel}+ onSubmit={onSubmit}+ pending={createDelivery.isPending || updateDelivery.isPending}+ />)}diff --git a/packages/seller-dashboard/src/components/orders/fulfillment-fulfill-form.tsx b/packages/seller-dashboard/src/components/orders/fulfillment-fulfill-form.tsxindex fce5d1e671..068fca57eb 100644--- a/packages/seller-dashboard/src/components/orders/fulfillment-fulfill-form.tsx+++ b/packages/seller-dashboard/src/components/orders/fulfillment-fulfill-form.tsx@@ -1,107 +1,73 @@import { zodResolver } from '@hookform/resolvers/zod'-import { mapSpreeErrorsToForm } from '@spree/dashboard-core'import {- Alert,- AlertDescription,- Button,- Checkbox,- Field,- FieldError,- FieldLabel,- Input,- Select,- SelectContent,- SelectItem,- SelectTrigger,- SelectValue,+ type FulfillmentItemRow,+ fulfillmentItemRows,+ mapSpreeErrorsToForm,+} from '@spree/dashboard-core'+import {+ type FulfillableRowData,+ FulfillItemsForm,+ type FulfillItemsValues,} from '@spree/dashboard-ui'-import type { Fulfillment } from '@spree/seller-sdk'+import type { Fulfillment, Order } from '@spree/seller-sdk'import { useEffect, useRef } from 'react'-import { Controller, useForm } from 'react-hook-form'+import { useForm } from 'react-hook-form'import { useTranslation } from 'react-i18next'import { useFulfillmentActions } from '../../hooks/use-fulfillments'import { useTrackingCarriers } from '../../hooks/use-reasons'import { type FulfillItemsFormValues, fulfillItemsFormSchema } from '../../schemas/fulfillment'-import { unitLabel } from './line-label'--type Row = { itemId: string; label: string; available: number }/**- * One row per line item, not per fulfillment item.- *- * A parcel routinely holds two rows for the same line item — the packer- * splits a partly-stocked line into an on-hand unit and a backordered one —- * and the server addresses what to ship by line item. Left unmerged, the two- * rows share a React key, one stepper silently moves the other, and the- * payload sends the same `item_id` twice, where last-wins makes a seller who- * selected everything ship only half of it.+ * Rows whose fulfillment item no longer maps to a line item are dropped: the+ * fulfill endpoint addresses items by line item, so there is nothing to send+ * for them. They still ship — selecting everything else sends no `items` at+ * all, which ships the whole parcel including them.*/-function fulfillableRows(fulfillment: Fulfillment): Row[] {- const byLineItem = new Map<string, Row>()-- for (const item of fulfillment.fulfillment_items ?? []) {- const itemId = item.line_item_id ?? item.id- const existing = byLineItem.get(itemId)-- if (existing) {- existing.available += item.quantity- } else {- byLineItem.set(itemId, {- itemId,- label: unitLabel(item),- available: item.quantity,- })- }- }-- return [...byLineItem.values()]+function fulfillableRows(rows: FulfillmentItemRow[]): FulfillableRowData[] {+ return rows.flatMap((row) => (row.lineItem ? [{ ...row, itemId: row.lineItem.id }] : []))}-/**- * Marking a parcel sent.- *- * Replaces the card's body rather than opening a dialog: the seller has the- * parcel and the tracking number in hand, and shipping part of it is a- * normal thing to do — what is left splits onto a parcel of its own.- */+/** What the seller sends out of one parcel. */export function FulfillmentFulfillForm({- orderId,+ order,fulfillment,onDone,}: {- orderId: string+ order: Orderfulfillment: FulfillmentonDone: () => void}) {const { t } = useTranslation()- const { fulfill } = useFulfillmentActions(orderId)+ const { fulfill } = useFulfillmentActions(order.id)const { data: carriersData } = useTrackingCarriers()const carrierOptions = [- { value: '', label: t('orders.fulfillments.carrier_auto') },- ...(carriersData?.data ?? []).map((option) => ({ value: option.id, label: option.name })),+ { value: '', label: t('admin.orders.detail.fulfillments.carrier_auto') },+ ...(carriersData?.data ?? []).map((carrier) => ({ value: carrier.id, label: carrier.name })),]- const rows = fulfillableRows(fulfillment)+ const idPrefix = `fulfill-${fulfillment.id}`+ const rows = fulfillableRows(fulfillmentItemRows(fulfillment, order.items ?? []))const form = useForm<FulfillItemsFormValues>({resolver: zodResolver(fulfillItemsFormSchema),defaultValues: {- items: rows.map((row) => ({ item_id: row.itemId, selected: true, quantity: row.available })),- tracking: '',+ items: rows.map((row) => ({ item_id: row.itemId, selected: true, quantity: row.quantity })),+ tracking: fulfillment.tracking ?? '',+ // Detected from the number, or picked in the tracking dialog once the+ // parcel has one.tracking_carrier: '',notify_customer: true,},})- const { errors } = form.formState- // Sending part of a parcel splits the rest onto a new one, and the source- // keeps its id with fewer units — so the values this form mirrors have to- // follow. Keyed on the parcel's composition rather than the rows array, so- // a refetch returning the same units does not wipe what was typed.+ // A refetch re-renders this form with fresh rows, so the values it mirrors+ // have to follow. The effect keys on the parcel's composition rather than on+ // the rows array, so a refetch returning the same units does not wipe what+ // the seller typed.const rowsRef = useRef(rows)rowsRef.current = rows- const rowsKey = rows.map((row) => `${row.itemId}:${row.available}`).join('|')+ const rowsKey = rows.map((row) => `${row.itemId}:${row.quantity}`).join('|')const seededKey = useRef(rowsKey)useEffect(() => {@@ -112,33 +78,25 @@ export function FulfillmentFulfillForm({items: rowsRef.current.map((row) => ({item_id: row.itemId,selected: true,- quantity: row.available,+ quantity: row.quantity,})),})}, [rowsKey, form])- const watched = form.watch('items')- const selectedUnits = watched.reduce(- (total, item) => total + (item.selected ? item.quantity || 0 : 0),- 0,- )- const totalUnits = rows.reduce((total, row) => total + row.available, 0)- const partial = selectedUnits > 0 && selectedUnits < totalUnits+ const totalAvailable = rows.reduce((sum, row) => sum + row.quantity, 0)- async function onSubmit(values: FulfillItemsFormValues) {+ async function onSubmit(values: FulfillItemsValues) {const items = values.items.filter((item) => item.selected && item.quantity > 0).map((item) => ({ item_id: item.item_id, quantity: item.quantity }))if (items.length === 0) return- // Recomputed from what is being sent rather than the watched total, so- // the branch is decided by exactly this payload.- const everything = items.reduce((total, item) => total + item.quantity, 0) === totalUnits+ const everything = items.reduce((sum, item) => sum + item.quantity, 0) === totalAvailableconst tracking = values.tracking.trim()try {- // Omitting `items` is how the whole parcel ships, and it avoids a- // pointless split when every unit was selected anyway.+ // Omitting `items` ships the whole parcel, avoiding a pointless split+ // when every unit was selected anyway.await fulfill.mutateAsync({fulfillmentId: fulfillment.id,items: everything ? undefined : items,@@ -153,132 +111,14 @@ export function FulfillmentFulfillForm({}return (- <form onSubmit={form.handleSubmit(onSubmit)} className="flex flex-col gap-4">- {errors.root?.message && (- <p className="text-sm text-destructive" role="alert">- {errors.root.message}- </p>- )}-- <div className="flex flex-col gap-2">- {rows.map((row, index) => (- <div key={row.itemId} className="flex items-center justify-between gap-3">- <label- className="flex min-w-0 items-center gap-2 text-sm"- htmlFor={`ship-${row.itemId}`}- >- <Controller- control={form.control}- name={`items.${index}.selected`}- render={({ field }) => (- <Checkbox- id={`ship-${row.itemId}`}- checked={field.value}- onCheckedChange={(checked) => field.onChange(!!checked)}- />- )}- />- <span className="truncate">{row.label}</span>- </label>- <Controller- control={form.control}- name={`items.${index}.quantity`}- render={({ field }) => (- <Input- type="number"- min={0}- max={row.available}- className="w-20"- aria-label={t('orders.fulfillments.quantity_for', { name: row.label })}- value={field.value}- onChange={(event) =>- field.onChange(- Math.max(0, Math.min(row.available, Number(event.target.value) || 0)),- )- }- />- )}- />- </div>- ))}- </div>-- <FieldError errors={[errors.items?.message ? errors.items : undefined]} />-- <p className="text-muted-foreground text-xs">- {t('orders.fulfillments.units_selected', { selected: selectedUnits, total: totalUnits })}- </p>-- {partial && (- <Alert>- <AlertDescription>{t('orders.fulfillments.partial_warning')}</AlertDescription>- </Alert>- )}-- <div className="grid grid-cols-1 gap-4 sm:grid-cols-2">- <Field>- <FieldLabel htmlFor={`fulfill-tracking-${fulfillment.id}`}>- {t('orders.tracking_label')}- </FieldLabel>- <Input- id={`fulfill-tracking-${fulfillment.id}`}- placeholder={t('orders.tracking_placeholder')}- {...form.register('tracking')}- />- </Field>-- <Field>- <FieldLabel htmlFor={`fulfill-carrier-${fulfillment.id}`}>- {t('orders.fulfillments.carrier_label')}- </FieldLabel>- <Controller- control={form.control}- name="tracking_carrier"- render={({ field }) => (- <Select- items={carrierOptions}- value={field.value}- onValueChange={(value) => field.onChange(value ?? '')}- >- <SelectTrigger id={`fulfill-carrier-${fulfillment.id}`}>- <SelectValue />- </SelectTrigger>- <SelectContent>- {carrierOptions.map((option) => (- <SelectItem key={option.value} value={option.value}>- {option.label}- </SelectItem>- ))}- </SelectContent>- </Select>- )}- />- </Field>- </div>-- <label className="flex items-center gap-2 text-sm" htmlFor={`notify-${fulfillment.id}`}>- <Controller- control={form.control}- name="notify_customer"- render={({ field }) => (- <Checkbox- id={`notify-${fulfillment.id}`}- checked={field.value}- onCheckedChange={(checked) => field.onChange(!!checked)}- />- )}- />- {t('orders.fulfillments.notify_customer')}- </label>-- <div className="flex justify-end gap-2">- <Button type="button" variant="outline" onClick={onDone}>- {t('common.cancel')}- </Button>- <Button type="submit" disabled={fulfill.isPending || selectedUnits === 0}>- {fulfill.isPending ? t('orders.fulfilling') : t('orders.fulfill')}- </Button>- </div>- </form>+ <FulfillItemsForm+ form={form}+ rows={rows}+ idPrefix={idPrefix}+ carrierOptions={carrierOptions}+ onSubmit={onSubmit}+ onCancel={onDone}+ pending={fulfill.isPending}+ />)}diff --git a/packages/seller-dashboard/src/components/orders/fulfillments-card.tsx b/packages/seller-dashboard/src/components/orders/fulfillments-card.tsxindex ebf359511a..fba1633475 100644--- a/packages/seller-dashboard/src/components/orders/fulfillments-card.tsx+++ b/packages/seller-dashboard/src/components/orders/fulfillments-card.tsx@@ -1,8 +1,11 @@+import { fulfillmentItemRows } from '@spree/dashboard-core'import {+ Badge,Button,Card,CardAction,CardContent,+ CardFooter,CardHeader,CardTitle,DropdownMenu,@@ -10,13 +13,15 @@ import {DropdownMenuItem,DropdownMenuSeparator,DropdownMenuTrigger,+ FulfillmentItemList,+ FulfillmentPanel,StatusBadge,useConfirm,} from '@spree/dashboard-ui'import {EllipsisVerticalIcon,- MapPinIcon,PencilIcon,+ PlusIcon,PrinterIcon,SplitIcon,TagIcon,@@ -34,12 +39,11 @@ import { FulfillmentEditDialog } from './fulfillment-edit-dialog'import { FulfillmentFulfillForm } from './fulfillment-fulfill-form'import { FulfillmentLabelUploadDialog } from './fulfillment-label-upload-dialog'import { FulfillmentSplitDialog } from './fulfillment-split-dialog'-import { unitLabel } from './line-label'import { ShippingLabelRow } from './shipping-label-row'-// A parcel that has not gone out is the only one still to ship or cancel;-// one that has is the only one that can be confirmed delivered. Reading-// these off "not unfulfilled" once badged a canceled parcel as a success.+// A parcel that has not gone out is the only one still to ship or cancel.+// Reading these off "not unfulfilled" once badged a canceled parcel as a+// success.const CAN_SHIP = ['unfulfilled']const CAN_CANCEL = ['unfulfilled']@@ -51,53 +55,45 @@ export function FulfillmentsCard({ order }: { order: Order }) {return (<Card><CardHeader>- <CardTitle className="flex items-center gap-2">+ <CardTitle><TruckIcon className="size-4" />{t('orders.fulfillments.title')}+ {fulfillments.length > 0 && <Badge variant="outline">{fulfillments.length}</Badge>}</CardTitle>- {order.fulfillment_status && (- <CardAction>+ <CardAction>+ {order.fulfillment_status && (<StatusBadgestatus={order.fulfillment_status}- label={t(`orders.fulfillment_statuses.${order.fulfillment_status}`)}+ label={t(`orders.fulfillment_statuses.${order.fulfillment_status}`, {+ defaultValue: order.fulfillment_status,+ })}/>- </CardAction>- )}+ )}+ </CardAction></CardHeader>- <CardContent className="flex flex-col gap-3">- {fulfillments.length === 0 ? (- <p className="text-muted-foreground text-sm">{t('orders.fulfillments.empty')}</p>- ) : (- fulfillments.map((fulfillment) => (- <FulfillmentRow- key={fulfillment.id}- order={order}- currency={order.currency}- fulfillment={fulfillment}- />- ))- )}- </CardContent>+ {fulfillments.length === 0 ? (+ <CardContent>+ <p className="py-8 text-center text-muted-foreground">{t('orders.fulfillments.empty')}</p>+ </CardContent>+ ) : (+ <CardContent className="flex flex-col gap-4">+ {fulfillments.map((fulfillment) => (+ <FulfillmentRow key={fulfillment.id} order={order} fulfillment={fulfillment} />+ ))}+ </CardContent>+ )}</Card>)}-function FulfillmentRow({- order,- currency,- fulfillment,-}: {- order: Order- currency: string- fulfillment: Fulfillment-}) {+function FulfillmentRow({ order, fulfillment }: { order: Order; fulfillment: Fulfillment }) {const orderId = order.idconst { t } = useTranslation()const confirm = useConfirm()const { cancel } = useFulfillmentActions(orderId)- const [shipping, setShipping] = useState(false)+ const [fulfilling, setFulfilling] = useState(false)const [deliveryOpen, setDeliveryOpen] = useState(false)const [editingDelivery, setEditingDelivery] = useState<Delivery | undefined>()const [labelOpen, setLabelOpen] = useState(false)@@ -108,6 +104,13 @@ function FulfillmentRow({const shippable = CAN_SHIP.includes(status)const cancelable = CAN_CANCEL.includes(status)const splittable = shippable && (fulfillment.fulfillment_items?.length ?? 0) > 0+ const deliveries = fulfillment.deliveries ?? []+ // At most one label binds a parcel: the workflows refuse a second while one+ // is active, and a refunded one stays as history.+ const activeLabel = (fulfillment.labels ?? []).find((label) => label.status !== 'refunded')+ // A seller buys postage elsewhere and uploads it, so the slot is offered+ // only while the parcel has no label and has not gone out.+ const canUploadLabel = shippable && !activeLabelasync function handleCancel() {const ok = await confirm({@@ -121,126 +124,124 @@ function FulfillmentRow({}return (- <Card variant="nested">- <CardHeader>- <CardTitle className="text-sm">{fulfillment.number}</CardTitle>- <CardAction className="flex items-center gap-2">- <StatusBadge- status={status}- label={t(`orders.fulfillment_statuses.${status}`, { defaultValue: status })}- />- <DropdownMenu>- <DropdownMenuTrigger- render={- <Button variant="ghost" size="icon" aria-label={t('common.actions')}>- <EllipsisVerticalIcon className="size-4" />- </Button>- }- />- <DropdownMenuContent align="end">- {shippable && (- <DropdownMenuItem onClick={() => setEditOpen(true)}>- <PencilIcon className="size-4" />- {t('admin.actions.edit')}- </DropdownMenuItem>- )}- {splittable && (- <DropdownMenuItem onClick={() => setSplitOpen(true)}>- <SplitIcon className="size-4" />- {t('orders.fulfillments.split')}- </DropdownMenuItem>- )}- <DropdownMenuItem onClick={() => printPackingSlip(order, fulfillment, t)}>- <PrinterIcon className="size-4" />- {t('orders.fulfillments.print_packing_slip')}+ <FulfillmentPanel+ status={status}+ statusLabel={t(`orders.fulfillment_statuses.${status}`, { defaultValue: status })}+ location={fulfillment.stock_location_name}+ actions={+ <DropdownMenu>+ <DropdownMenuTrigger asChild>+ <Button variant="ghost" size="icon-xs">+ <EllipsisVerticalIcon className="size-4" />+ <span className="sr-only">{t('admin.actions.actions_menu')}</span>+ </Button>+ </DropdownMenuTrigger>+ <DropdownMenuContent align="end">+ {shippable && (+ <DropdownMenuItem onClick={() => setEditOpen(true)}>+ <PencilIcon className="size-4" />+ {t('admin.actions.edit')}</DropdownMenuItem>- <DropdownMenuItem- onClick={() => {- setEditingDelivery(undefined)- setDeliveryOpen(true)- }}- >- <TruckIcon className="size-4" />- {t('orders.fulfillments.add_delivery')}+ )}+ {splittable && (+ <DropdownMenuItem onClick={() => setSplitOpen(true)}>+ <SplitIcon className="size-4" />+ {t('orders.fulfillments.split')}</DropdownMenuItem>+ )}+ <DropdownMenuItem onClick={() => printPackingSlip(order, fulfillment, t)}>+ <PrinterIcon className="size-4" />+ {t('orders.fulfillments.print_packing_slip')}+ </DropdownMenuItem>+ <DropdownMenuItem+ onClick={() => {+ setEditingDelivery(undefined)+ setDeliveryOpen(true)+ }}+ >+ <TruckIcon className="size-4" />+ {t('orders.fulfillments.add_delivery')}+ </DropdownMenuItem>+ {canUploadLabel && (<DropdownMenuItem onClick={() => setLabelOpen(true)}><TagIcon className="size-4" />{t('orders.fulfillments.upload_label')}</DropdownMenuItem>- {cancelable && (- <>- <DropdownMenuSeparator />- <DropdownMenuItem- variant="destructive"- disabled={cancel.isPending}- onClick={handleCancel}- >- <XCircleIcon className="size-4" />- {t('orders.fulfillments.cancel')}- </DropdownMenuItem>- </>- )}- </DropdownMenuContent>- </DropdownMenu>- </CardAction>- </CardHeader>+ )}+ {cancelable && (+ <>+ <DropdownMenuSeparator />+ <DropdownMenuItem+ variant="destructive"+ disabled={cancel.isPending}+ onClick={handleCancel}+ >+ <XCircleIcon className="size-4" />+ {t('orders.fulfillments.cancel')}+ </DropdownMenuItem>+ </>+ )}+ </DropdownMenuContent>+ </DropdownMenu>+ }+ >+ {fulfillment.delivery_method_name && (+ <CardContent className="flex items-center justify-between border-border-subtle border-b py-3 text-sm">+ <span className="text-muted-foreground">{fulfillment.delivery_method_name}</span>+ </CardContent>+ )}- {(fulfillment.labels ?? []).map((label) => (- <ShippingLabelRow- key={label.id}- orderId={orderId}- fulfillmentId={fulfillment.id}- label={label}- />- ))}+ {activeLabel && !fulfilling && (+ <ShippingLabelRow orderId={orderId} fulfillmentId={fulfillment.id} label={activeLabel} />+ )}<FulfillmentDeliveriesorderId={orderId}fulfillmentId={fulfillment.id}- deliveries={fulfillment.deliveries ?? []}+ deliveries={deliveries}onEdit={(delivery) => {setEditingDelivery(delivery)setDeliveryOpen(true)}}/>- <CardContent className="flex flex-col gap-3">- {fulfillment.stock_location_name && (- <p className="flex items-center gap-1.5 text-muted-foreground text-sm">- <MapPinIcon className="size-3.5 shrink-0" />- {t('orders.ships_from', { name: fulfillment.stock_location_name })}- </p>- )}-- {fulfillment.delivery_method_name && (- <p className="text-muted-foreground text-sm">{fulfillment.delivery_method_name}</p>- )}+ {fulfilling ? (+ <FulfillmentFulfillForm+ order={order}+ fulfillment={fulfillment}+ onDone={() => setFulfilling(false)}+ />+ ) : (+ <>+ <FulfillmentItemList rows={fulfillmentItemRows(fulfillment, order.items ?? [])} />- {shipping ? (- <FulfillmentFulfillForm- orderId={orderId}- fulfillment={fulfillment}- onDone={() => setShipping(false)}- />- ) : (- <>- {fulfillment.fulfillment_items?.map((item) => (- <div key={item.id} className="flex items-center justify-between gap-3 text-sm">- <span className="truncate">{unitLabel(item)}</span>- <span className="shrink-0 text-muted-foreground">× {item.quantity}</span>- </div>- ))}+ {shippable && (+ <CardFooter className="justify-end gap-2 py-3">+ <Button type="button" size="sm" onClick={() => setFulfilling(true)}>+ <TruckIcon data-icon="inline-start" />+ {t('orders.fulfill')}+ </Button>+ </CardFooter>+ )}- {shippable && (- <div className="flex justify-end">- <Button type="button" onClick={() => setShipping(true)}>- {t('orders.fulfill')}- </Button>- </div>- )}- </>- )}- </CardContent>+ {!shippable && deliveries.length === 0 && (+ <CardFooter className="justify-end gap-2 py-3">+ <Button+ type="button"+ size="sm"+ variant="outline"+ onClick={() => {+ setEditingDelivery(undefined)+ setDeliveryOpen(true)+ }}+ >+ <PlusIcon data-icon="inline-start" />+ {t('orders.fulfillments.add_tracking')}+ </Button>+ </CardFooter>+ )}+ </>+ )}{/* Mounted only while open, so each form seeds from the parcel as it isnow. Left mounted, their defaults froze at first render — and after@@ -270,7 +271,7 @@ function FulfillmentRow({<FulfillmentLabelUploadDialogorderId={orderId}fulfillmentId={fulfillment.id}- currency={currency}+ currency={order.currency}openonOpenChange={setLabelOpen}/>@@ -283,6 +284,6 @@ function FulfillmentRow({onOpenChange={setSplitOpen}/>)}- </Card>+ </FulfillmentPanel>)}diff --git a/packages/seller-dashboard/src/components/orders/order-cards.tsx b/packages/seller-dashboard/src/components/orders/order-cards.tsxindex 69b9373940..fea0c1b845 100644--- a/packages/seller-dashboard/src/components/orders/order-cards.tsx+++ b/packages/seller-dashboard/src/components/orders/order-cards.tsx@@ -71,14 +71,12 @@ export function OrderSummaryCard({ order }: { order: Order }) {const placed = Boolean(order.completed_at)return (- <Card className="py-0">- <CardHeader className="px-5 py-4">+ <Card>+ <CardHeader><CardTitle>{t('orders.summary.title')}</CardTitle></CardHeader>- <div className="flex flex-col pb-2">- <Separator />-+ <div className="py-1"><SummaryRow label={t('orders.summary.created_at')} value={formatDate(order.created_at)} />{order.completed_at && (<SummaryRowdiff --git a/packages/seller-dashboard/src/components/orders/post-sale-cards.tsx b/packages/seller-dashboard/src/components/orders/post-sale-cards.tsxindex c698059bb5..f03e99cd0c 100644--- a/packages/seller-dashboard/src/components/orders/post-sale-cards.tsx+++ b/packages/seller-dashboard/src/components/orders/post-sale-cards.tsx@@ -79,17 +79,17 @@ export function ExchangesCard({ order }: { order: Order }) {return (<Card><CardHeader>- <CardTitle className="flex items-center gap-2">+ <CardTitle><ArrowLeftRightIcon className="size-4" />{t('orders.post_sale.exchanges.title')}</CardTitle></CardHeader>- <CardContent className="flex flex-col gap-3">+ <CardContent className="flex flex-col gap-4">{exchanges.map((exchange) => (<Card key={exchange.id} variant="nested"><CardHeader>- <CardTitle className="text-sm">{exchange.number}</CardTitle>+ <CardTitle className="text-sm font-medium">{exchange.number}</CardTitle><CardAction className="flex items-center gap-2"><StatusBadgestatus={exchange.status}@@ -99,13 +99,12 @@ export function ExchangesCard({ order }: { order: Order }) {/>{EXCHANGE_ACTIONABLE.includes(exchange.status) && (<DropdownMenu>- <DropdownMenuTrigger- render={- <Button variant="ghost" size="icon" aria-label={t('common.actions')}>- <EllipsisVerticalIcon className="size-4" />- </Button>- }- />+ <DropdownMenuTrigger asChild>+ <Button variant="ghost" size="icon-xs">+ <EllipsisVerticalIcon className="size-4" />+ <span className="sr-only">{t('admin.actions.actions_menu')}</span>+ </Button>+ </DropdownMenuTrigger><DropdownMenuContent align="end">{exchange.status === 'requested' && (<DropdownMenuItem onClick={() => approve.mutate(exchange.id)}>@@ -139,7 +138,7 @@ export function ExchangesCard({ order }: { order: Order }) {</CardAction></CardHeader>- <CardContent className="flex flex-col gap-2">+ <CardContent className="flex flex-col gap-1.5">{exchange.exchange_line_items?.map((line) => (<div key={line.id} className="flex items-center justify-between gap-3 text-sm"><span className="truncate">@@ -200,7 +199,7 @@ export function ClaimsCard({ order }: { order: Order }) {return (<Card><CardHeader>- <CardTitle className="flex items-center gap-2">+ <CardTitle><ShieldAlertIcon className="size-4" />{t('orders.post_sale.claims.title')}</CardTitle>@@ -214,14 +213,14 @@ export function ClaimsCard({ order }: { order: Order }) {)}</CardHeader>- <CardContent className="flex flex-col gap-3">+ <CardContent className="flex flex-col gap-4">{claims.length === 0 ? (<p className="text-muted-foreground text-sm">{t('orders.post_sale.claims.empty')}</p>) : (claims.map((claim) => (<Card key={claim.id} variant="nested"><CardHeader>- <CardTitle className="text-sm">{claim.number}</CardTitle>+ <CardTitle className="text-sm font-medium">{claim.number}</CardTitle><CardAction className="flex items-center gap-2"><StatusBadgestatus={claim.status}@@ -231,13 +230,12 @@ export function ClaimsCard({ order }: { order: Order }) {/>{CLAIM_ACTIONABLE.includes(claim.status) && (<DropdownMenu>- <DropdownMenuTrigger- render={- <Button variant="ghost" size="icon" aria-label={t('common.actions')}>- <EllipsisVerticalIcon className="size-4" />- </Button>- }- />+ <DropdownMenuTrigger asChild>+ <Button variant="ghost" size="icon-xs">+ <EllipsisVerticalIcon className="size-4" />+ <span className="sr-only">{t('admin.actions.actions_menu')}</span>+ </Button>+ </DropdownMenuTrigger><DropdownMenuContent align="end">{claim.status === 'open' && (<DropdownMenuItem onClick={() => approve.mutate(claim.id)}>@@ -266,7 +264,7 @@ export function ClaimsCard({ order }: { order: Order }) {</CardAction></CardHeader>- <CardContent className="flex flex-col gap-2">+ <CardContent className="flex flex-col gap-1.5">{claim.claim_line_items?.map((line) => (<div key={line.id} className="flex items-center justify-between gap-3 text-sm"><span className="min-w-0 truncate">diff --git a/packages/seller-dashboard/src/components/orders/returns-card.tsx b/packages/seller-dashboard/src/components/orders/returns-card.tsxindex 60d6c50c66..2735df6db9 100644--- a/packages/seller-dashboard/src/components/orders/returns-card.tsx+++ b/packages/seller-dashboard/src/components/orders/returns-card.tsx@@ -75,7 +75,7 @@ export function ReturnsCard({ order }: { order: Order }) {return (<Card><CardHeader>- <CardTitle className="flex items-center gap-2">+ <CardTitle><RotateCcwIcon className="size-4" />{t('orders.post_sale.returns.title')}</CardTitle>@@ -89,14 +89,14 @@ export function ReturnsCard({ order }: { order: Order }) {)}</CardHeader>- <CardContent className="flex flex-col gap-3">+ <CardContent className="flex flex-col gap-4">{returns.length === 0 ? (<p className="text-muted-foreground text-sm">{t('orders.post_sale.returns.empty')}</p>) : (returns.map((returnRecord) => (<Card key={returnRecord.id} variant="nested"><CardHeader>- <CardTitle className="text-sm">{returnRecord.number}</CardTitle>+ <CardTitle className="text-sm font-medium">{returnRecord.number}</CardTitle><CardAction className="flex items-center gap-2"><StatusBadgestatus={returnRecord.status}@@ -106,13 +106,12 @@ export function ReturnsCard({ order }: { order: Order }) {/>{ACTIONABLE.includes(returnRecord.status) && (<DropdownMenu>- <DropdownMenuTrigger- render={- <Button variant="ghost" size="icon" aria-label={t('common.actions')}>- <EllipsisVerticalIcon className="size-4" />- </Button>- }- />+ <DropdownMenuTrigger asChild>+ <Button variant="ghost" size="icon-xs">+ <EllipsisVerticalIcon className="size-4" />+ <span className="sr-only">{t('admin.actions.actions_menu')}</span>+ </Button>+ </DropdownMenuTrigger><DropdownMenuContent align="end">{returnRecord.status === 'requested' && (<DropdownMenuItem onClick={() => approve.mutate(returnRecord.id)}>@@ -142,7 +141,7 @@ export function ReturnsCard({ order }: { order: Order }) {</CardAction></CardHeader>- <CardContent className="flex flex-col gap-2">+ <CardContent className="flex flex-col gap-1.5">{returnRecord.return_line_items?.map((line) => (<ReturnLineRow key={line.id} line={line} />))}diff --git a/packages/seller-dashboard/src/components/orders/shipping-label-row.tsx b/packages/seller-dashboard/src/components/orders/shipping-label-row.tsxindex 8363acc0d1..a4a7b7d57a 100644--- a/packages/seller-dashboard/src/components/orders/shipping-label-row.tsx+++ b/packages/seller-dashboard/src/components/orders/shipping-label-row.tsx@@ -6,7 +6,6 @@ import {DropdownMenu,DropdownMenuContent,DropdownMenuItem,- DropdownMenuSeparator,DropdownMenuTrigger,useConfirm,} from '@spree/dashboard-ui'@@ -66,7 +65,7 @@ export function ShippingLabelRow({}return (- <CardContent className="flex flex-wrap items-center justify-between gap-2 border-b py-3 text-sm">+ <CardContent className="flex flex-wrap items-center justify-between gap-2 border-border-subtle border-b py-3 text-sm"><div className="flex flex-wrap items-center gap-2"><ReceiptTextIcon className="size-4 text-muted-foreground" /><span className="text-muted-foreground">{t('orders.fulfillments.label_title')}</span>@@ -80,25 +79,23 @@ export function ShippingLabelRow({)}</div>- <div className="flex items-center gap-1">+ <div className="flex items-center gap-2">{label.download_url && (<Button type="button" variant="outline" size="sm" onClick={print}>- <PrinterIcon className="size-4" />+ <PrinterIcon data-icon="inline-start" />{t('orders.fulfillments.print_label')}</Button>)}{deletable && (<DropdownMenu>- <DropdownMenuTrigger- render={- <Button variant="ghost" size="icon" aria-label={t('common.actions')}>- <EllipsisVerticalIcon className="size-4" />- </Button>- }- />+ <DropdownMenuTrigger asChild>+ <Button variant="ghost" size="icon-xs">+ <EllipsisVerticalIcon className="size-4" />+ <span className="sr-only">{t('admin.actions.actions_menu')}</span>+ </Button>+ </DropdownMenuTrigger><DropdownMenuContent align="end">- <DropdownMenuSeparator /><DropdownMenuItemvariant="destructive"disabled={deleteLabel.isPending}diff --git a/packages/seller-dashboard/src/locales/en.json b/packages/seller-dashboard/src/locales/en.jsonindex f40dd79c4d..e9d585d5ad 100644--- a/packages/seller-dashboard/src/locales/en.json+++ b/packages/seller-dashboard/src/locales/en.json@@ -46,6 +46,37 @@}}},+ "orders": {+ "detail": {+ "fulfillments": {+ "add_tracking_title": "Add tracking",+ "carrier_auto": "Detect automatically",+ "carrier_label": "Shipping carrier",+ "carrier_search": "Search carriers",+ "delivery_method": "Delivery method",+ "edit_description": "Change where this fulfillment ships from and which delivery method carries it.",+ "edit_title": "Edit fulfillment",+ "edit_tracking_title": "Edit tracking",+ "move_and_requote": "Move and re-quote",+ "no_rates": "No delivery methods are quoted for this fulfillment.",+ "rates_pending_origin": "Save the new origin to see the delivery methods it offers.",+ "ships_from": "Ships from",+ "tracking_description": "The carrier tracking number, or a full tracking link."+ }+ },+ "fulfill": {+ "include_item": "Ship {{name}}",+ "quantity_for": "Quantity to ship of {{name}}",+ "of_units": "of {{count}}",+ "empty": "This fulfillment holds no items that can be fulfilled.",+ "tracking_label": "Tracking number",+ "tracking_placeholder": "Tracking number or link",+ "notify_customer": "Send shipment notification to customer",+ "partial_hint": "The units you picked move into a new fulfillment that ships now. The rest stay on this one, still open.",+ "units_selected": "Units to ship",+ "submit": "Fulfill items"+ }+ },"tax_identifiers": {"add_cta": "Add registration","add_title": "Add tax registration",@@ -83,19 +114,6 @@"unverified": "Not valid","verified": "Verified"}- },- "orders": {- "detail": {- "fulfillments": {- "delivery_method": "Delivery method",- "edit_description": "Change where this fulfillment ships from and which delivery method carries it.",- "edit_title": "Edit fulfillment",- "move_and_requote": "Move and re-quote",- "no_rates": "No delivery methods are quoted for this fulfillment.",- "rates_pending_origin": "Save the new origin to see the delivery methods it offers.",- "ships_from": "Ships from"- }- }}},"app": {@@ -285,9 +303,7 @@},"customer_note": "Customer note","empty": "No orders yet. They appear here as customers buy from you.",- "fulfill": "Mark as shipped",- "fulfilled": "Marked as shipped",- "fulfilling": "Marking…",+ "fulfill": "Mark as fulfilled","fulfillment_statuses": {"backorder": "Backorder","canceled": "Canceled",@@ -297,9 +313,8 @@"unfulfilled": "Unfulfilled"},"fulfillments": {- "add_delivery": "Add tracking number",+ "add_delivery": "Add tracking","add_tracking": "Add tracking",- "add_tracking_title": "Add tracking","cancel": "Cancel parcel","cancel_message": "The goods go back on the shelf and the carrier is stood down.","cancel_title": "Cancel this parcel?",@@ -308,31 +323,26 @@"carrier_search": "Search carriers…","carrier_status_available_for_pickup": "Available for pickup","carrier_status_delivered": "Delivered",- "carrier_status_failure": "Failed",+ "carrier_status_failure": "Delivery failed","carrier_status_in_transit": "In transit","carrier_status_out_for_delivery": "Out for delivery",- "carrier_status_pending": "Pending",- "carrier_status_pre_transit": "Pre-transit",- "carrier_status_return_to_sender": "Return to sender",- "carrier_status_unknown": "Unknown",+ "carrier_status_pending": "Awaiting carrier",+ "carrier_status_pre_transit": "Label created",+ "carrier_status_return_to_sender": "Returning to sender",+ "carrier_status_unknown": "Status unknown","confirm_delete_delivery": "Remove this tracking number?","confirm_delete_label": "Remove this label? The file is deleted and cannot be printed again.","confirm_split": "This takes effect immediately.","delete_label": "Remove label",- "edit_tracking": "Edit tracking",- "edit_tracking_title": "Edit tracking","empty": "Nothing to send on this order.","free": "Free","label_cost": "Cost {{amount}}","label_cost_label": "What it cost",- "label_title": "Label",+ "label_title": "Shipping label","label_uploaded": "Uploaded",- "notify_customer": "Email the customer","packing_slip_title": "Packing slip — order {{number}}",- "partial_warning": "Sending part of this parcel moves the rest onto a new one.","print_label": "Print label","print_packing_slip": "Print packing slip",- "quantity_for": "Quantity for {{name}}","ship_to": "Ship to","ships_from_label": "Ships from","split": "Split",@@ -342,11 +352,8 @@"split_title": "Split this parcel","split_would_empty": "Moving everything would leave this parcel empty.","splitting": "Splitting…",- "title": "Parcels",- "track_parcel": "Track parcel",- "tracking_description": "The number the customer follows the parcel with.",- "units_selected": "{{selected}} of {{total}} units selected",- "upload_label": "Upload postage",+ "title": "Fulfillments",+ "upload_label": "Upload label","upload_label_description": "Record a label you bought elsewhere, so the parcel carries its file and tracking number.","upload_label_file": "Label file","upload_label_title": "Upload postage"