Skip to content

armgit / spree

Public Imported from GitHub
0

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

Let a merchant choose where a return comes back to

Damian Legawiecbff369e7d525
diff --git a/packages/dashboard/src/components/spree/post-sale-create-dialogs.tsx b/packages/dashboard/src/components/spree/post-sale-create-dialogs.tsx
index 999b16de34..f18a7f6984 100644
--- a/packages/dashboard/src/components/spree/post-sale-create-dialogs.tsx
+++ b/packages/dashboard/src/components/spree/post-sale-create-dialogs.tsx
@@ -1,5 +1,11 @@
import type { Claim, Order, Variant } from '@spree/admin-sdk'
-import { adminClient, currencyParts, ResourceCombobox, useStore } from '@spree/dashboard-core'
+import {
+ adminClient,
+ currencyParts,
+ ResourceCombobox,
+ useStockLocations,
+ useStore,
+} from '@spree/dashboard-core'
import {
Button,
Dialog,
@@ -109,6 +115,7 @@ export function CreateReturnDialog({
items: Array<{ fulfillment_item_id: string; quantity: number }>
memo?: string
reasonId?: string
+ stockLocationId?: string
}) => void
}) {
const { t } = useTranslation()
@@ -116,6 +123,22 @@ export function CreateReturnDialog({
const [selection, setSelection] = useState<Selection>({})
const [memo, setMemo] = useState('')
const [reasonId, setReasonId] = useState('')
+ const [stockLocationId, setStockLocationId] = useState('')
+ const { data: stockLocationData } = useStockLocations()
+
+ // Locations that accept returns lead, and one of them is the default: a
+ // merchant sending goods anywhere else is making a deliberate exception.
+ // The rest stay selectable, since a one-off return has to be routable
+ // somewhere even when no location is flagged.
+ const locationOptions = (stockLocationData?.data ?? [])
+ .filter((location) => location.active)
+ .sort((a, b) => Number(b.returns_enabled) - Number(a.returns_enabled))
+ .map((location) => ({
+ value: location.id,
+ label: location.returns_enabled
+ ? location.name
+ : t('admin.pages.orders.detail.returns.location_no_returns', { name: location.name }),
+ }))
const chosen = selectedItems(selection)
@@ -128,6 +151,29 @@ export function CreateReturnDialog({
<DialogBody className="flex flex-col gap-4">
<QuantityPicker units={units} selection={selection} onChange={setSelection} />
<ReasonField kind="return-reasons" value={reasonId} onChange={setReasonId} />
+ <Field>
+ <FieldLabel htmlFor="return-location">
+ {t('admin.pages.orders.detail.returns.location')}
+ </FieldLabel>
+ <Select
+ items={locationOptions}
+ value={stockLocationId}
+ onValueChange={(value) => setStockLocationId(value as string)}
+ >
+ <SelectTrigger id="return-location">
+ <SelectValue
+ placeholder={t('admin.pages.orders.detail.returns.location_default')}
+ />
+ </SelectTrigger>
+ <SelectContent>
+ {locationOptions.map((option) => (
+ <SelectItem key={option.value} value={option.value}>
+ {option.label}
+ </SelectItem>
+ ))}
+ </SelectContent>
+ </Select>
+ </Field>
<Field>
<FieldLabel htmlFor="return-memo">
{t('admin.pages.orders.detail.returns.memo')}
@@ -153,6 +199,7 @@ export function CreateReturnDialog({
})),
memo: memo || undefined,
reasonId: reasonId || undefined,
+ stockLocationId: stockLocationId || undefined,
})
}
>
diff --git a/packages/dashboard/src/hooks/use-returns.ts b/packages/dashboard/src/hooks/use-returns.ts
index d29d30e996..aceed8ff99 100644
--- a/packages/dashboard/src/hooks/use-returns.ts
+++ b/packages/dashboard/src/hooks/use-returns.ts
@@ -61,12 +61,19 @@ export function useReturnActions(orderId: string) {
orderId,
({
reasonId,
+ stockLocationId,
...params
}: {
items: Array<{ fulfillment_item_id: string; quantity: number }>
memo?: string
reasonId?: string
- }) => adminClient.orders.returns.create(orderId, { ...params, reason_id: reasonId }),
+ stockLocationId?: string
+ }) =>
+ adminClient.orders.returns.create(orderId, {
+ ...params,
+ reason_id: reasonId,
+ stock_location_id: stockLocationId,
+ }),
)
const approve = useReturnMutation(orderId, (returnId: string) =>
diff --git a/packages/dashboard/src/locales/ar.json b/packages/dashboard/src/locales/ar.json
index 9224e4add9..b7be07fead 100644
--- a/packages/dashboard/src/locales/ar.json
+++ b/packages/dashboard/src/locales/ar.json
@@ -3168,6 +3168,9 @@
"create_title": "مرتجع جديد",
"empty": "لا توجد مرتجعات لهذا الطلب.",
"empty_no_units": "لا توجد سجلات تنفيذ في هذا الطلب يمكن الرجوع إليها.",
+ "location": "إرجاع إلى",
+ "location_default": "موقع الإرجاع الافتراضي",
+ "location_no_returns": "{{name}} (لا يقبل المرتجعات)",
"memo": "ملاحظة",
"no_label": "لا يوجد ملصق إرجاع بعد.",
"not_resellable": "غير قابل لإعادة البيع",
diff --git a/packages/dashboard/src/locales/de.json b/packages/dashboard/src/locales/de.json
index 6f8f64f7fc..9c49586cfc 100644
--- a/packages/dashboard/src/locales/de.json
+++ b/packages/dashboard/src/locales/de.json
@@ -3151,6 +3151,9 @@
"create_title": "Neue Retoure",
"empty": "Keine Retouren für diese Bestellung.",
"empty_no_units": "Für diese Bestellung gibt es keine Fulfillment-Einträge, auf die sich eine Retoure beziehen könnte.",
+ "location": "Rücksendung an",
+ "location_default": "Standard-Rücksendeort",
+ "location_no_returns": "{{name}} (nimmt keine Rücksendungen an)",
"memo": "Notiz",
"no_label": "Noch kein Rücksendeetikett.",
"not_resellable": "Nicht wiederverkäuflich",
diff --git a/packages/dashboard/src/locales/en.json b/packages/dashboard/src/locales/en.json
index 156b542255..ba7c4413f8 100644
--- a/packages/dashboard/src/locales/en.json
+++ b/packages/dashboard/src/locales/en.json
@@ -3151,6 +3151,9 @@
"create_title": "New return",
"empty": "No returns for this order.",
"empty_no_units": "This order has no fulfillment records to return against.",
+ "location": "Return to",
+ "location_default": "Default returns location",
+ "location_no_returns": "{{name}} (does not accept returns)",
"memo": "Note",
"no_label": "No return label yet.",
"not_resellable": "Not resellable",
diff --git a/packages/dashboard/src/locales/fr.json b/packages/dashboard/src/locales/fr.json
index 78ed74d16e..267bd2fd65 100644
--- a/packages/dashboard/src/locales/fr.json
+++ b/packages/dashboard/src/locales/fr.json
@@ -3151,6 +3151,9 @@
"create_title": "Nouveau retour",
"empty": "Aucun retour pour cette commande.",
"empty_no_units": "Cette commande n’a aucun enregistrement de traitement sur lequel baser un retour.",
+ "location": "Retourner à",
+ "location_default": "Lieu de retour par défaut",
+ "location_no_returns": "{{name}} (n'accepte pas les retours)",
"memo": "Note",
"no_label": "Pas encore d'étiquette de retour.",
"not_resellable": "Non revendable",
diff --git a/packages/dashboard/src/locales/pl.json b/packages/dashboard/src/locales/pl.json
index 0329f83b91..d98fe2023a 100644
--- a/packages/dashboard/src/locales/pl.json
+++ b/packages/dashboard/src/locales/pl.json
@@ -3179,6 +3179,9 @@
"create_title": "Nowy zwrot",
"empty": "Brak zwrotów dla tego zamówienia.",
"empty_no_units": "To zamówienie nie ma pozycji realizacji, do których można odnieść zwrot.",
+ "location": "Zwrot do",
+ "location_default": "Domyślne miejsce zwrotów",
+ "location_no_returns": "{{name}} (nie przyjmuje zwrotów)",
"memo": "Notatka",
"no_label": "Brak etykiety zwrotnej.",
"not_resellable": "Nie nadaje się do sprzedaży",
diff --git a/packages/dashboard/src/locales/zh-CN.json b/packages/dashboard/src/locales/zh-CN.json
index f51c716ab0..0166d9ce3d 100644
--- a/packages/dashboard/src/locales/zh-CN.json
+++ b/packages/dashboard/src/locales/zh-CN.json
@@ -3143,6 +3143,9 @@
"create_title": "新建退货",
"empty": "此订单暂无退货。",
"empty_no_units": "此订单没有可用于退货的履约记录。",
+ "location": "退货至",
+ "location_default": "默认退货地点",
+ "location_no_returns": "{{name}}(不接受退货)",
"memo": "备注",
"no_label": "尚无退货面单。",
"not_resellable": "不可再销售",