Skip to content

armgit / spree

Public Imported from GitHub
0

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

Show delivery in the dashboard

Damian Legawiece57de37ff379
diff --git a/packages/dashboard-ui/src/ui/badge.tsx b/packages/dashboard-ui/src/ui/badge.tsx
index e060cb0799..6027a3424a 100644
--- a/packages/dashboard-ui/src/ui/badge.tsx
+++ b/packages/dashboard-ui/src/ui/badge.tsx
@@ -62,6 +62,8 @@ const statusVariantMap: Record<string, VariantProps<typeof badgeVariants>['varia
completed: 'success',
paid: 'success',
fulfilled: 'success',
+ delivered: 'success',
+ unfulfilled: 'warning',
published: 'success',
approved: 'success',
ready: 'warning',
diff --git a/packages/dashboard/src/components/spree/orders/fulfillments-card.tsx b/packages/dashboard/src/components/spree/orders/fulfillments-card.tsx
index 4b9e67eb39..532e393b2f 100644
--- a/packages/dashboard/src/components/spree/orders/fulfillments-card.tsx
+++ b/packages/dashboard/src/components/spree/orders/fulfillments-card.tsx
@@ -36,6 +36,7 @@ import {
import {
EllipsisVerticalIcon,
MapPinIcon,
+ PackageCheckIcon,
PackageIcon,
PencilIcon,
PlusIcon,
@@ -382,17 +383,19 @@ function CreateFulfillmentDialog({
)
}
-// Which transitions the backend's state machine actually offers, so the card
-// does not present an action that can only 422.
-const CAN_SHIP = ['ready', 'ready_for_pickup']
-const CAN_CANCEL = ['pending', 'ready', 'ready_for_pickup']
-const CAN_EDIT = ['pending', 'ready', 'ready_for_pickup']
+// Which transitions the workflows actually accept, so the card does not
+// present an action that can only 422.
+const CAN_SHIP = ['unfulfilled']
+const CAN_CANCEL = ['unfulfilled']
+const CAN_EDIT = ['unfulfilled']
+// Receipt is confirmed after handover, never before.
+const CAN_MARK_DELIVERED = ['fulfilled']
function FulfillmentRow({ order, fulfillment }: { order: Order; fulfillment: Fulfillment }) {
const { t } = useTranslation()
const confirm = useConfirm()
const orderId = order.id
- const { cancel, resume } = useFulfillmentActions(orderId)
+ const { cancel, resume, markDelivered } = useFulfillmentActions(orderId)
const [editOpen, setEditOpen] = useState(false)
const [splitOpen, setSplitOpen] = useState(false)
@@ -445,6 +448,13 @@ function FulfillmentRow({ order, fulfillment }: { order: Order; fulfillment: Ful
</DropdownMenuItem>
)}
+ {CAN_MARK_DELIVERED.includes(fulfillment.status) && (
+ <DropdownMenuItem onClick={() => markDelivered.mutate(fulfillment.id)}>
+ <PackageCheckIcon className="size-4" />
+ {t('admin.orders.detail.fulfillments.mark_delivered')}
+ </DropdownMenuItem>
+ )}
+
{fulfillment.status === 'canceled' && (
<DropdownMenuItem onClick={() => resume.mutate(fulfillment.id)}>
<RotateCcwIcon className="size-4" />
diff --git a/packages/dashboard/src/components/spree/orders/order-header.tsx b/packages/dashboard/src/components/spree/orders/order-header.tsx
index 8663b47756..a6d49b212d 100644
--- a/packages/dashboard/src/components/spree/orders/order-header.tsx
+++ b/packages/dashboard/src/components/spree/orders/order-header.tsx
@@ -160,7 +160,7 @@ export function OrderHeader({ order }: { order: Order }) {
<>
{/* Fully fulfilled means every unit has shipped, so there is
nothing left an edit could lawfully change. */}
- {order.fulfillment_status !== 'fulfilled' && (
+ {!['fulfilled', 'delivered'].includes(order.fulfillment_status ?? '') && (
<Button variant="outline" size="sm" asChild>
<Link to="/$storeId/orders/$orderId/edit" params={{ storeId, orderId }}>
<PencilIcon className="size-4" />
diff --git a/packages/dashboard/src/hooks/use-fulfillments.ts b/packages/dashboard/src/hooks/use-fulfillments.ts
index 4c41d5f8eb..ce74f1953a 100644
--- a/packages/dashboard/src/hooks/use-fulfillments.ts
+++ b/packages/dashboard/src/hooks/use-fulfillments.ts
@@ -87,5 +87,9 @@ export function useFulfillmentActions(orderId: string) {
adminClient.orders.fulfillments.resume(orderId, fulfillmentId),
)
- return { create, update, split, fulfill, cancel, resume }
+ const markDelivered = useFulfillmentMutation(orderId, (fulfillmentId: string) =>
+ adminClient.orders.fulfillments.markDelivered(orderId, fulfillmentId),
+ )
+
+ return { create, update, split, fulfill, cancel, resume, markDelivered }
}
diff --git a/packages/dashboard/src/lib/fulfillment-items.test.ts b/packages/dashboard/src/lib/fulfillment-items.test.ts
index 21b0f8c1aa..52a7da1c40 100644
--- a/packages/dashboard/src/lib/fulfillment-items.test.ts
+++ b/packages/dashboard/src/lib/fulfillment-items.test.ts
@@ -186,6 +186,20 @@ describe('fulfilledQuantities', () => {
expect(quantities.size).toBe(0)
})
+ // Delivered is downstream of fulfilled — those units are just as gone, and
+ // treating them as available would let an edit remove goods the customer
+ // already has.
+ it('counts units in delivered fulfillments', () => {
+ const quantities = fulfilledQuantities([
+ fulfillment({
+ status: 'delivered',
+ fulfillment_items: [{ line_item_id: 'li_1', variant_id: 'variant_1', quantity: 2 }],
+ }),
+ ])
+
+ expect(quantities.get('li_1')).toBe(2)
+ })
+
it('skips fulfillment items that reference no line item', () => {
const quantities = fulfilledQuantities([
fulfillment({
diff --git a/packages/dashboard/src/lib/fulfillment-items.ts b/packages/dashboard/src/lib/fulfillment-items.ts
index d688e0f812..5d8c9f70d2 100644
--- a/packages/dashboard/src/lib/fulfillment-items.ts
+++ b/packages/dashboard/src/lib/fulfillment-items.ts
@@ -67,16 +67,18 @@ function claimedQuantities(fulfillments: GroupableFulfillment[]): Map<string, nu
}
/**
- * Sums, per line item, how many units sit in fulfilled fulfillments. Those
- * units have left the building, so an edit can neither remove the row nor push
- * its quantity below them. Canceled fulfillments restock their units and do
- * not count.
+ * Sums, per line item, how many units have left the merchant's hands. Those
+ * units are gone, so an edit can neither remove the row nor push its quantity
+ * below them. Delivered counts too — it is downstream of fulfilled. Canceled
+ * fulfillments restock their units and do not count.
*/
+const GONE_STATUSES = ['fulfilled', 'delivered']
+
export function fulfilledQuantities(fulfillments: GroupableFulfillment[]): Map<string, number> {
const fulfilled = new Map<string, number>()
for (const fulfillment of fulfillments) {
- if (fulfillment.status !== 'fulfilled') continue
+ if (!GONE_STATUSES.includes(fulfillment.status)) continue
for (const item of fulfillment.fulfillment_items ?? []) {
if (!item.line_item_id) continue
diff --git a/packages/dashboard/src/locales/ar.json b/packages/dashboard/src/locales/ar.json
index 6f79ab8539..a2174eab1b 100644
--- a/packages/dashboard/src/locales/ar.json
+++ b/packages/dashboard/src/locales/ar.json
@@ -1838,7 +1838,8 @@
"split_quantity": "الكمية المراد نقلها",
"split_title": "تقسيم الشحنة",
"split_would_empty": "اترك وحدة واحدة على الأقل، أو غيّر مصدر الشحنة بالكامل بدلاً من ذلك.",
- "unfulfilled_other": "غير مُنفَّذ ({{count}})"
+ "unfulfilled_other": "غير مُنفَّذ ({{count}})",
+ "mark_delivered": "وضع علامة كمُسلَّم"
},
"gift_card_section": {
"applied_suffix": "مُطبَّق",
@@ -1959,7 +1960,9 @@
"fulfilled": "تم الوفاء به",
"partial": "جزئي",
"pending": "قيد الانتظار",
- "ready": "مستعد"
+ "ready": "مستعد",
+ "unfulfilled": "لم يتم الوفاء به",
+ "delivered": "تم التسليم"
},
"item_count_one": "{{count}} البند",
"item_count_other": "{{count}} العناصر",
diff --git a/packages/dashboard/src/locales/de.json b/packages/dashboard/src/locales/de.json
index d4728c01c9..be09d6faea 100644
--- a/packages/dashboard/src/locales/de.json
+++ b/packages/dashboard/src/locales/de.json
@@ -1828,7 +1828,8 @@
"split_title": "Sendung aufteilen",
"split_would_empty": "Lassen Sie mindestens eine Einheit zurück oder ändern Sie stattdessen den Ursprung der gesamten Sendung.",
"unfulfilled_one": "Nicht versandt ({{count}})",
- "unfulfilled_other": "Nicht versandt ({{count}})"
+ "unfulfilled_other": "Nicht versandt ({{count}})",
+ "mark_delivered": "Als zugestellt markieren"
},
"gift_card_section": {
"applied_suffix": "angewendet",
@@ -1949,7 +1950,9 @@
"fulfilled": "Abgewickelt",
"partial": "Teilweise",
"pending": "Ausstehend",
- "ready": "Bereit"
+ "ready": "Bereit",
+ "unfulfilled": "Nicht abgewickelt",
+ "delivered": "Zugestellt"
},
"item_count_one": "{{count}} Artikel",
"item_count_other": "{{count}} Artikel",
diff --git a/packages/dashboard/src/locales/en.json b/packages/dashboard/src/locales/en.json
index 6bf307ab91..5a44b4b989 100644
--- a/packages/dashboard/src/locales/en.json
+++ b/packages/dashboard/src/locales/en.json
@@ -1828,7 +1828,8 @@
"split_title": "Split fulfillment",
"split_would_empty": "Leave at least one unit behind, or change the origin of the whole fulfillment instead.",
"unfulfilled_one": "Unfulfilled ({{count}})",
- "unfulfilled_other": "Unfulfilled ({{count}})"
+ "unfulfilled_other": "Unfulfilled ({{count}})",
+ "mark_delivered": "Mark as delivered"
},
"gift_card_section": {
"applied_suffix": "applied",
@@ -1949,7 +1950,9 @@
"fulfilled": "Fulfilled",
"partial": "Partial",
"pending": "Pending",
- "ready": "Ready"
+ "ready": "Ready",
+ "unfulfilled": "Unfulfilled",
+ "delivered": "Delivered"
},
"item_count_one": "{{count}} item",
"item_count_other": "{{count}} items",
diff --git a/packages/dashboard/src/locales/fr.json b/packages/dashboard/src/locales/fr.json
index edb9cfe599..c229350c6a 100644
--- a/packages/dashboard/src/locales/fr.json
+++ b/packages/dashboard/src/locales/fr.json
@@ -1828,7 +1828,8 @@
"split_title": "Diviser l'expédition",
"split_would_empty": "Laissez au moins une unité, ou modifiez plutôt l'origine de toute l'expédition.",
"unfulfilled_one": "Non expédié ({{count}})",
- "unfulfilled_other": "Non expédiés ({{count}})"
+ "unfulfilled_other": "Non expédiés ({{count}})",
+ "mark_delivered": "Marquer comme livré"
},
"gift_card_section": {
"applied_suffix": "appliqué",
@@ -1949,7 +1950,9 @@
"fulfilled": "Traité",
"partial": "Partiel",
"pending": "En attente",
- "ready": "Prêt"
+ "ready": "Prêt",
+ "unfulfilled": "Non traité",
+ "delivered": "Livré"
},
"item_count_one": "{{count}} article",
"item_count_other": "{{count}} articles",
diff --git a/packages/dashboard/src/locales/pl.json b/packages/dashboard/src/locales/pl.json
index 19e0e98258..c94c3e6cca 100644
--- a/packages/dashboard/src/locales/pl.json
+++ b/packages/dashboard/src/locales/pl.json
@@ -1846,7 +1846,8 @@
"unfulfilled_few": "Niezrealizowane ({{count}})",
"unfulfilled_many": "Niezrealizowane ({{count}})",
"unfulfilled_one": "Niezrealizowane ({{count}})",
- "unfulfilled_other": "Niezrealizowane ({{count}})"
+ "unfulfilled_other": "Niezrealizowane ({{count}})",
+ "mark_delivered": "Oznacz jako dostarczone"
},
"gift_card_section": {
"applied_suffix": "zastosowano",
@@ -1971,7 +1972,9 @@
"fulfilled": "Zrealizowane",
"partial": "Częściowa",
"pending": "Oczekująca",
- "ready": "Gotowe"
+ "ready": "Gotowe",
+ "unfulfilled": "Niezrealizowane",
+ "delivered": "Dostarczone"
},
"item_count_few": "{{count}} pozycje",
"item_count_many": "{{count}} pozycji",
diff --git a/packages/dashboard/src/locales/zh-CN.json b/packages/dashboard/src/locales/zh-CN.json
index 383e505e72..01fe8abad4 100644
--- a/packages/dashboard/src/locales/zh-CN.json
+++ b/packages/dashboard/src/locales/zh-CN.json
@@ -1824,7 +1824,8 @@
"split_quantity": "移动数量",
"split_title": "拆分发货单",
"split_would_empty": "请至少保留一件,或改为修改整个发货单的发货地。",
- "unfulfilled_other": "未发货({{count}})"
+ "unfulfilled_other": "未发货({{count}})",
+ "mark_delivered": "标记为已送达"
},
"gift_card_section": {
"applied_suffix": "已应用",
@@ -1945,7 +1946,9 @@
"fulfilled": "已履行",
"partial": "部分完成",
"pending": "待处理",
- "ready": "已就绪"
+ "ready": "已就绪",
+ "unfulfilled": "未履行",
+ "delivered": "已送达"
},
"item_count_one": "{{count}} 件商品",
"item_count_other": "{{count}} 件商品",
diff --git a/packages/dashboard/src/routes/_authenticated/$storeId/orders/$orderId/edit.tsx b/packages/dashboard/src/routes/_authenticated/$storeId/orders/$orderId/edit.tsx
index 3163eae904..45c9ade14d 100644
--- a/packages/dashboard/src/routes/_authenticated/$storeId/orders/$orderId/edit.tsx
+++ b/packages/dashboard/src/routes/_authenticated/$storeId/orders/$orderId/edit.tsx
@@ -215,7 +215,7 @@ function OrderEditPage() {
// The header hides its edit link on fulfilled orders, but the URL stays
// reachable — and the per-row clamps below would still allow additions.
- if (order.fulfillment_status === 'fulfilled') {
+ if (['fulfilled', 'delivered'].includes(order.fulfillment_status ?? '')) {
return (
<ResourceLayout
header={
diff --git a/packages/dashboard/src/tables/orders.tsx b/packages/dashboard/src/tables/orders.tsx
index 20af0a09a8..3397d7298b 100644
--- a/packages/dashboard/src/tables/orders.tsx
+++ b/packages/dashboard/src/tables/orders.tsx
@@ -104,9 +104,9 @@ defineTable('orders', {
{ value: 'backorder', label: i18n.t('admin.orders.fulfillment_statuses.backorder') },
{ value: 'canceled', label: i18n.t('admin.orders.fulfillment_statuses.canceled') },
{ value: 'partial', label: i18n.t('admin.orders.fulfillment_statuses.partial') },
- { value: 'pending', label: i18n.t('admin.orders.fulfillment_statuses.pending') },
- { value: 'ready', label: i18n.t('admin.orders.fulfillment_statuses.ready') },
+ { value: 'unfulfilled', label: i18n.t('admin.orders.fulfillment_statuses.unfulfilled') },
{ value: 'fulfilled', label: i18n.t('admin.orders.fulfillment_statuses.fulfilled') },
+ { value: 'delivered', label: i18n.t('admin.orders.fulfillment_statuses.delivered') },
],
render: (order) =>
order.fulfillment_status ? (