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
Put a transfer's and an order's actions where the others are
Łukasz Adamczyk0545fc49f40e
diff --git a/packages/dashboard/e2e/stock-transfers.spec.ts b/packages/dashboard/e2e/stock-transfers.spec.tsindex 97ebfe5258..4ecd0ff3dc 100644--- a/packages/dashboard/e2e/stock-transfers.spec.ts+++ b/packages/dashboard/e2e/stock-transfers.spec.ts@@ -72,13 +72,24 @@ test.describe('stock transfers', () => {timeout: 15_000,})- // The units are physically gone from the source, so the screen offers- // restock or write-off rather than guessing.- await expect(page.getByText(/the units have already left/i)).toBeVisible()- await expect(page.locator('#in-transit-resolution')).toBeVisible()- await expect(page.getByRole('button', { name: /cancel transfer/i })).toBeVisible()- // Nothing to mark ready or send any more.+ // Nothing left to send, so the header offers no forward action.await expect(page.getByRole('button', { name: /mark in transit/i })).toHaveCount(0)++ await page.getByRole('button', { name: /more actions/i }).click()+ await page.getByRole('menuitem', { name: /cancel transfer/i }).click()++ // The units are physically gone from the source, so the dialog asks what+ // happened to them and refuses to proceed until it is told.+ const dialog = page.getByRole('dialog')+ await expect(dialog.getByText(/the units have already left/i)).toBeVisible()+ const confirmCancel = dialog.getByRole('button', { name: /^cancel transfer$/i })+ await expect(confirmCancel).toBeDisabled()++ await dialog.getByText(/put the units back at the source/i).click()+ await expect(confirmCancel).toBeEnabled()+ await confirmCancel.click()++ await expect(page.getByText(/^cancelled$/i).first()).toBeVisible({ timeout: 15_000 })})})diff --git a/packages/dashboard/src/components/spree/transfer-cancel-dialog.tsx b/packages/dashboard/src/components/spree/transfer-cancel-dialog.tsxnew file mode 100644index 0000000000..67f4a4836d--- /dev/null+++ b/packages/dashboard/src/components/spree/transfer-cancel-dialog.tsx@@ -0,0 +1,99 @@+import type { StockTransfer } from '@spree/admin-sdk'+import {+ Button,+ Dialog,+ DialogBody,+ DialogContent,+ DialogDescription,+ DialogFooter,+ DialogHeader,+ DialogTitle,+} from '@spree/dashboard-ui'+import { useState } from 'react'+import { useTranslation } from 'react-i18next'+import { useCancelStockTransfer } from '../../hooks/use-stock-transfers'+import {+ IN_TRANSIT_RESOLUTIONS,+ type InTransitResolution,+ isInFlight,+} from '../../schemas/inventory-operations'+import { ChoiceCardPicker } from './choice-card-picker'++/**+ * Calling a transfer off, and — once the van has gone — what happened to the+ * units.+ *+ * Nothing is preselected while the transfer is in flight. The two answers put+ * stock in different places, and the workflow refuses to guess between them,+ * so neither does this dialog: the merchant chooses before Cancel is live.+ */+export function TransferCancelDialog({+ transfer,+ onClose,+}: {+ transfer: StockTransfer+ onClose: () => void+}) {+ const { t } = useTranslation()+ const cancelTransfer = useCancelStockTransfer(transfer.id)+ const inFlight = isInFlight(transfer.status)+ const [resolution, setResolution] = useState<InTransitResolution | ''>('')++ const options = IN_TRANSIT_RESOLUTIONS.map((value) => ({+ value,+ label: t(`admin.stock_transfers.in_transit_resolutions.${value}`),+ description: t(`admin.stock_transfers.cancel_confirm.in_flight_${value}`),+ }))++ async function handleConfirm() {+ try {+ await cancelTransfer.mutateAsync(+ inFlight ? { on_in_transit: resolution as InTransitResolution } : {},+ )+ onClose()+ } catch {+ // The mutation hook surfaces the refusal; the dialog stays open so the+ // merchant can answer differently.+ }+ }++ return (+ <Dialog open onOpenChange={(open) => !open && onClose()}>+ <DialogContent>+ <DialogHeader>+ <DialogTitle>{t('admin.stock_transfers.cancel_confirm.title')}</DialogTitle>+ {!inFlight && (+ <DialogDescription>+ {t('admin.stock_transfers.cancel_confirm.message')}+ </DialogDescription>+ )}+ </DialogHeader>++ {inFlight && (+ <DialogBody>+ <ChoiceCardPicker<InTransitResolution | ''>+ label={t('admin.stock_transfers.fields.in_transit_resolution')}+ options={options}+ value={resolution}+ onChange={setResolution}+ />+ </DialogBody>+ )}++ <DialogFooter>+ <Button type="button" variant="outline" onClick={onClose}>+ {t('admin.actions.close')}+ </Button>+ <Button+ type="button"+ variant="destructive"+ onClick={handleConfirm}+ disabled={cancelTransfer.isPending || (inFlight && resolution === '')}+ >+ {t('admin.stock_transfers.actions.cancel_transfer')}+ </Button>+ </DialogFooter>+ </DialogContent>+ </Dialog>+ )+}diff --git a/packages/dashboard/src/locales/ar.json b/packages/dashboard/src/locales/ar.jsonindex f508afe948..760fb6a5b5 100644--- a/packages/dashboard/src/locales/ar.json+++ b/packages/dashboard/src/locales/ar.json@@ -5108,7 +5108,6 @@"items_title": "البنود","items_empty": "لا توجد بنود بعد — أضف منتجًا لإرساله.","receive_title": "الاستلام",- "actions_title": "الإجراءات","history_title": "الحركة في المستودع المستقبِل","units_summary": "تم استلام {{received}} من {{shipped}} وحدة مُرسَلة","receive_running_total": "تم عدّ {{counted}} من {{shipped}} وحدة مُرسَلة",@@ -5488,7 +5487,6 @@"items_title": "البنود","items_empty": "لا توجد بنود بعد — أضف منتجًا لطلبه.","receive_title": "الاستلام",- "actions_title": "الإجراءات","history_title": "الحركة في المستودع المستقبِل","units_summary": "تم استلام {{received}} من {{ordered}} وحدة مطلوبة","receive_running_total": "تم عدّ {{counted}} من {{ordered}} وحدة مطلوبة",diff --git a/packages/dashboard/src/locales/de.json b/packages/dashboard/src/locales/de.jsonindex 3f8dfd361e..1f74b753b7 100644--- a/packages/dashboard/src/locales/de.json+++ b/packages/dashboard/src/locales/de.json@@ -5086,7 +5086,6 @@"items_title": "Positionen","items_empty": "Noch keine Positionen – fügen Sie ein Produkt hinzu.","receive_title": "Wareneingang",- "actions_title": "Aktionen","history_title": "Bewegungen im Ziellager","units_summary": "{{received}} von {{shipped}} versandten Einheiten eingegangen","receive_running_total": "{{counted}} von {{shipped}} versandten Einheiten gezählt",@@ -5459,7 +5458,6 @@"items_title": "Positionen","items_empty": "Noch keine Positionen – fügen Sie ein Produkt hinzu.","receive_title": "Wareneingang",- "actions_title": "Aktionen","history_title": "Bewegungen im Ziellager","units_summary": "{{received}} von {{ordered}} bestellten Einheiten eingegangen","receive_running_total": "{{counted}} von {{ordered}} bestellten Einheiten gezählt",diff --git a/packages/dashboard/src/locales/en.json b/packages/dashboard/src/locales/en.jsonindex 72e3452f1f..54a2aaafa5 100644--- a/packages/dashboard/src/locales/en.json+++ b/packages/dashboard/src/locales/en.json@@ -5086,7 +5086,6 @@"items_title": "Items","items_empty": "No items yet — add a product to send.","receive_title": "Receive",- "actions_title": "Actions","history_title": "Activity at the destination","units_summary": "{{received}} received of {{shipped}} shipped","receive_running_total": "{{counted}} counted of {{shipped}} shipped",@@ -5459,7 +5458,6 @@"items_title": "Items","items_empty": "No items yet — add a product to order.","receive_title": "Receive",- "actions_title": "Actions","history_title": "Activity at the destination","units_summary": "{{received}} received of {{ordered}} ordered","receive_running_total": "{{counted}} counted of {{ordered}} ordered",diff --git a/packages/dashboard/src/locales/fr.json b/packages/dashboard/src/locales/fr.jsonindex 3957fd1fda..37e16d955b 100644--- a/packages/dashboard/src/locales/fr.json+++ b/packages/dashboard/src/locales/fr.json@@ -5086,7 +5086,6 @@"items_title": "Articles","items_empty": "Aucun article — ajoutez un produit à envoyer.","receive_title": "Réception",- "actions_title": "Actions","history_title": "Activité à destination","units_summary": "{{received}} reçues sur {{shipped}} expédiées","receive_running_total": "{{counted}} comptées sur {{shipped}} expédiées",@@ -5459,7 +5458,6 @@"items_title": "Articles","items_empty": "Aucun article — ajoutez un produit à commander.","receive_title": "Réception",- "actions_title": "Actions","history_title": "Activité à destination","units_summary": "{{received}} reçues sur {{ordered}} commandées","receive_running_total": "{{counted}} comptées sur {{ordered}} commandées",diff --git a/packages/dashboard/src/locales/pl.json b/packages/dashboard/src/locales/pl.jsonindex 7b67775059..31819d6ef7 100644--- a/packages/dashboard/src/locales/pl.json+++ b/packages/dashboard/src/locales/pl.json@@ -5144,7 +5144,6 @@"items_title": "Pozycje","items_empty": "Brak pozycji — dodaj produkt do wysłania.","receive_title": "Przyjęcie",- "actions_title": "Akcje","history_title": "Ruchy w magazynie docelowym","units_summary": "przyjęto {{received}} z {{shipped}} wysłanych","receive_running_total": "policzono {{counted}} z {{shipped}} wysłanych",@@ -5521,7 +5520,6 @@"items_title": "Pozycje","items_empty": "Brak pozycji — dodaj produkt do zamówienia.","receive_title": "Przyjęcie",- "actions_title": "Akcje","history_title": "Ruchy w magazynie docelowym","units_summary": "przyjęto {{received}} z {{ordered}} zamówionych","receive_running_total": "policzono {{counted}} z {{ordered}} zamówionych",diff --git a/packages/dashboard/src/locales/zh-CN.json b/packages/dashboard/src/locales/zh-CN.jsonindex c0e3085c95..f83b73806d 100644--- a/packages/dashboard/src/locales/zh-CN.json+++ b/packages/dashboard/src/locales/zh-CN.json@@ -5077,7 +5077,6 @@"items_title": "明细","items_empty": "暂无明细 — 请添加要发出的商品。","receive_title": "收货",- "actions_title": "操作","history_title": "目标仓库的变动","units_summary": "已发出 {{shipped}} 件,已收到 {{received}} 件","receive_running_total": "已发出 {{shipped}} 件,已清点 {{counted}} 件",@@ -5448,7 +5447,6 @@"items_title": "明细","items_empty": "暂无明细 — 请添加要订购的商品。","receive_title": "收货",- "actions_title": "操作","history_title": "目标仓库的变动","units_summary": "已订购 {{ordered}} 件,已收到 {{received}} 件","receive_running_total": "已订购 {{ordered}} 件,已清点 {{counted}} 件",diff --git a/packages/dashboard/src/routes/_authenticated/$storeId/products/purchase-orders/$purchaseOrderId.tsx b/packages/dashboard/src/routes/_authenticated/$storeId/products/purchase-orders/$purchaseOrderId.tsxindex 34256670cb..2e7c3ae0db 100644--- a/packages/dashboard/src/routes/_authenticated/$storeId/products/purchase-orders/$purchaseOrderId.tsx+++ b/packages/dashboard/src/routes/_authenticated/$storeId/products/purchase-orders/$purchaseOrderId.tsx@@ -6,6 +6,7 @@ import {CardContent,CardHeader,CardTitle,+ DropdownMenuItem,Input,RelativeTime,Table,@@ -16,6 +17,7 @@ import {TableRow,useConfirm,} from '@spree/dashboard-ui'+import { XCircleIcon } from '@spree/dashboard-ui/icons'import { createFileRoute, Link } from '@tanstack/react-router'import { useState } from 'react'import { useTranslation } from 'react-i18next'@@ -28,6 +30,7 @@ import {usePurchaseOrder,useReceivePurchaseOrder,} from '../../../../../hooks/use-purchase-orders'+import { isClosed } from '../../../../../schemas/inventory-operations'export const Route = createFileRoute('/_authenticated/$storeId/products/purchase-orders/$purchaseOrderId',@@ -46,15 +49,10 @@ function PurchaseOrderDetailPage() {return (<div className="mx-auto flex w-full max-w-4xl flex-col gap-4 p-4">- <PageHeader- title={purchaseOrder.number}- backTo="products/purchase-orders"- badges={<InventoryStatusBadge status={purchaseOrder.status} resource="purchase_orders" />}- />+ <PurchaseOrderHeader purchaseOrder={purchaseOrder} /><SummaryCard purchaseOrder={purchaseOrder} /><ItemsCard purchaseOrder={purchaseOrder} />- <Actions purchaseOrder={purchaseOrder} /><StockHistoryCardstockLocationId={purchaseOrder.destination_location_id}@@ -299,13 +297,17 @@ function ItemRow({)}-function Actions({ purchaseOrder }: { purchaseOrder: PurchaseOrder }) {+/**+ * Title, status, and the transitions — the same layout an order's header uses:+ * placing the order is the button, calling it off is in the menu.+ */+function PurchaseOrderHeader({ purchaseOrder }: { purchaseOrder: PurchaseOrder }) {const { t } = useTranslation()const confirm = useConfirm()const markOrdered = useMarkPurchaseOrderOrdered(purchaseOrder.id)const cancelOrder = useCancelPurchaseOrder(purchaseOrder.id)- if (purchaseOrder.status === 'received' || purchaseOrder.status === 'canceled') return null+ const open = !isClosed(purchaseOrder.status)async function handleOrder() {const ok = await confirm({@@ -331,13 +333,14 @@ function Actions({ purchaseOrder }: { purchaseOrder: PurchaseOrder }) {}return (- <Card>- <CardHeader>- <CardTitle>{t('admin.purchase_orders.actions_title')}</CardTitle>- </CardHeader>- <CardContent className="flex flex-wrap gap-2">- <Can I="update" a={Subject.PurchaseOrder}>- {purchaseOrder.status === 'draft' && (+ <PageHeader+ title={purchaseOrder.number}+ backTo="products/purchase-orders"+ badges={<InventoryStatusBadge status={purchaseOrder.status} resource="purchase_orders" />}+ actions={+ open &&+ purchaseOrder.status === 'draft' && (+ <Can I="update" a={Subject.PurchaseOrder}><Buttontype="button"onClick={handleOrder}@@ -345,17 +348,24 @@ function Actions({ purchaseOrder }: { purchaseOrder: PurchaseOrder }) {>{t('admin.purchase_orders.actions.mark_ordered')}</Button>- )}- <Button- type="button"- variant="destructive"- onClick={handleCancel}- disabled={cancelOrder.isPending}- >- {t('admin.purchase_orders.actions.cancel_order')}- </Button>- </Can>- </CardContent>- </Card>+ </Can>+ )+ }+ destructiveItems={+ open && (+ <Can I="update" a={Subject.PurchaseOrder}>+ <DropdownMenuItem+ variant="destructive"+ onClick={handleCancel}+ disabled={cancelOrder.isPending}+ >+ <XCircleIcon className="size-4" />+ {t('admin.purchase_orders.actions.cancel_order')}+ </DropdownMenuItem>+ </Can>+ )+ }+ resource={{ id: purchaseOrder.id, number: purchaseOrder.number }}+ />)}diff --git a/packages/dashboard/src/routes/_authenticated/$storeId/products/transfers/$transferId.tsx b/packages/dashboard/src/routes/_authenticated/$storeId/products/transfers/$transferId.tsxindex d907d6b680..240e8a580b 100644--- a/packages/dashboard/src/routes/_authenticated/$storeId/products/transfers/$transferId.tsx+++ b/packages/dashboard/src/routes/_authenticated/$storeId/products/transfers/$transferId.tsx@@ -6,8 +6,7 @@ import {CardContent,CardHeader,CardTitle,- Field,- FieldLabel,+ DropdownMenuItem,Input,RelativeTime,Select,@@ -23,14 +22,15 @@ import {TableRow,useConfirm,} from '@spree/dashboard-ui'+import { XCircleIcon } from '@spree/dashboard-ui/icons'import { createFileRoute, Link } from '@tanstack/react-router'import { useMemo, useState } from 'react'import { useTranslation } from 'react-i18next'import { InventoryStatusBadge } from '../../../../../components/spree/inventory-status-badge'import { StockHistoryCard } from '../../../../../components/spree/stock-history-card'+import { TransferCancelDialog } from '../../../../../components/spree/transfer-cancel-dialog'import { VariantLink } from '../../../../../components/spree/variant-link'import {- useCancelStockTransfer,useMarkStockTransferInTransit,useMarkStockTransferReady,useReceiveStockTransfer,@@ -38,8 +38,7 @@ import {} from '../../../../../hooks/use-stock-transfers'import {DISCREPANCY_REASONS,- IN_TRANSIT_RESOLUTIONS,- type InTransitResolution,+ isClosed,isInFlight,} from '../../../../../schemas/inventory-operations'@@ -58,11 +57,7 @@ function StockTransferDetailPage() {return (<div className="mx-auto flex w-full max-w-4xl flex-col gap-4 p-4">- <PageHeader- title={transfer.number}- backTo="products/transfers"- badges={<InventoryStatusBadge status={transfer.status} resource="stock_transfers" />}- />+ <TransferHeader transfer={transfer} /><SummaryCard transfer={transfer} />@@ -72,8 +67,6 @@ function StockTransferDetailPage() {<ReceiveCard transfer={transfer} />)}- <Actions transfer={transfer} />-{/* Where the units on this trip came from and went — read on thedestination warehouse, which is the shelf the merchant isreconciling. */}@@ -420,18 +413,20 @@ function ReceiveRow({)}-function Actions({ transfer }: { transfer: StockTransfer }) {+/**+ * Title, status, and the transitions — laid out the way an order's header is:+ * the move that carries the transfer forward as a button on the right, the+ * cancellation in the menu beside it.+ */+function TransferHeader({ transfer }: { transfer: StockTransfer }) {const { t } = useTranslation()const confirm = useConfirm()const markReady = useMarkStockTransferReady(transfer.id)const markInTransit = useMarkStockTransferInTransit(transfer.id)- const cancelTransfer = useCancelStockTransfer(transfer.id)- const [resolution, setResolution] = useState<InTransitResolution>('restock')+ const [cancelOpen, setCancelOpen] = useState(false)- const inFlight = isInFlight(transfer.status)- const closed = transfer.status === 'received' || transfer.status === 'canceled'-- if (closed) return null+ const open = !isClosed(transfer.status)+ const shippable = transfer.status === 'draft' || transfer.status === 'ready_to_ship'async function handleShip() {const ok = await confirm({@@ -445,82 +440,51 @@ function Actions({ transfer }: { transfer: StockTransfer }) {await markInTransit.mutateAsync({}).catch(() => undefined)}- async function handleCancel() {- const ok = await confirm({- title: t('admin.stock_transfers.cancel_confirm.title'),- message: inFlight- ? t(`admin.stock_transfers.cancel_confirm.in_flight_${resolution}`)- : t('admin.stock_transfers.cancel_confirm.message'),- variant: 'destructive',- confirmLabel: t('admin.stock_transfers.actions.cancel_transfer'),- })- if (!ok) return- await cancelTransfer- .mutateAsync(inFlight ? { on_in_transit: resolution } : {})- .catch(() => undefined)- }-return (- <Card>- <CardHeader>- <CardTitle>{t('admin.stock_transfers.actions_title')}</CardTitle>- </CardHeader>- <CardContent className="flex flex-col gap-4">- {/* The merchant has to say what happened to units already gone from- the source: guessing would either invent stock or destroy it. */}- {inFlight && (- <Field>- <FieldLabel htmlFor="in-transit-resolution">- {t('admin.stock_transfers.fields.in_transit_resolution')}- </FieldLabel>- <Select- value={resolution}- onValueChange={(value) => setResolution(value as InTransitResolution)}- >- <SelectTrigger id="in-transit-resolution">- <SelectValue>- {(value) => t(`admin.stock_transfers.in_transit_resolutions.${value}`)}- </SelectValue>- </SelectTrigger>- <SelectContent>- {IN_TRANSIT_RESOLUTIONS.map((value) => (- <SelectItem key={value} value={value}>- {t(`admin.stock_transfers.in_transit_resolutions.${value}`)}- </SelectItem>- ))}- </SelectContent>- </Select>- </Field>- )}-- <div className="flex flex-wrap gap-2">- <Can I="update" a={Subject.StockTransfer}>- {transfer.status === 'draft' && (- <Button- type="button"- variant="outline"- onClick={() => markReady.mutateAsync().catch(() => undefined)}- disabled={markReady.isPending || (transfer.items_count ?? 0) === 0}- >- {t('admin.stock_transfers.actions.mark_ready')}- </Button>- )}- {(transfer.status === 'draft' || transfer.status === 'ready_to_ship') && (- <Button type="button" onClick={handleShip} disabled={markInTransit.isPending}>- {t('admin.stock_transfers.actions.mark_in_transit')}- </Button>- )}- <Button- type="button"- variant="destructive"- onClick={handleCancel}- disabled={cancelTransfer.isPending}- >- {t('admin.stock_transfers.actions.cancel_transfer')}- </Button>- </Can>- </div>- </CardContent>- </Card>+ <>+ {cancelOpen && (+ <TransferCancelDialog transfer={transfer} onClose={() => setCancelOpen(false)} />+ )}+ <PageHeader+ title={transfer.number}+ backTo="products/transfers"+ badges={<InventoryStatusBadge status={transfer.status} resource="stock_transfers" />}+ actions={+ open && (+ <Can I="update" a={Subject.StockTransfer}>+ {/* Packing a draft is optional — a merchant already loading the+ van can go straight to in transit — so it is the quieter of+ the two. */}+ {transfer.status === 'draft' && (+ <Button+ type="button"+ variant="outline"+ onClick={() => markReady.mutateAsync().catch(() => undefined)}+ disabled={markReady.isPending || (transfer.items_count ?? 0) === 0}+ >+ {t('admin.stock_transfers.actions.mark_ready')}+ </Button>+ )}+ {shippable && (+ <Button type="button" onClick={handleShip} disabled={markInTransit.isPending}>+ {t('admin.stock_transfers.actions.mark_in_transit')}+ </Button>+ )}+ </Can>+ )+ }+ destructiveItems={+ open && (+ <Can I="update" a={Subject.StockTransfer}>+ <DropdownMenuItem variant="destructive" onClick={() => setCancelOpen(true)}>+ <XCircleIcon className="size-4" />+ {t('admin.stock_transfers.actions.cancel_transfer')}+ </DropdownMenuItem>+ </Can>+ )+ }+ resource={{ id: transfer.id, number: transfer.number }}+ />+ </>)}