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.

Give inventory its own place in the sidebar

Damian Legawiec61982937c771
diff --git a/packages/dashboard-starter/src/routeTree.gen.ts b/packages/dashboard-starter/src/routeTree.gen.ts
index 2a4e8eb1d2..90fb72c483 100644
--- a/packages/dashboard-starter/src/routeTree.gen.ts
+++ b/packages/dashboard-starter/src/routeTree.gen.ts
@@ -34,7 +34,6 @@ import { Route as CompaniesIndexRouteImport } from './../../dashboard/src/routes
import { Route as BrandsDotindexRouteImport } from './../../dashboard-plugin-example/src/routes/brands.index'
import { Route as SettingsTaxRatesRouteImport } from './../../dashboard/src/routes/_authenticated/$storeId/settings/tax-rates'
import { Route as SettingsTaxCategoriesRouteImport } from './../../dashboard/src/routes/_authenticated/$storeId/settings/tax-categories'
-import { Route as SettingsSuppliersRouteImport } from './../../dashboard/src/routes/_authenticated/$storeId/settings/suppliers'
import { Route as SettingsStoreRouteImport } from './../../dashboard/src/routes/_authenticated/$storeId/settings/store'
import { Route as SettingsStockLocationsRouteImport } from './../../dashboard/src/routes/_authenticated/$storeId/settings/stock-locations'
import { Route as SettingsStaffRouteImport } from './../../dashboard/src/routes/_authenticated/$storeId/settings/staff'
@@ -60,6 +59,7 @@ import { Route as PromotionsNewRouteImport } from './../../dashboard/src/routes/
import { Route as PromotionsGiftCardsRouteImport } from './../../dashboard/src/routes/_authenticated/$storeId/promotions/gift-cards'
import { Route as PromotionsPromotionIdRouteImport } from './../../dashboard/src/routes/_authenticated/$storeId/promotions/$promotionId'
import { Route as ProductsTranslationsRouteImport } from './../../dashboard/src/routes/_authenticated/$storeId/products/translations'
+import { Route as ProductsSuppliersRouteImport } from './../../dashboard/src/routes/_authenticated/$storeId/products/suppliers'
import { Route as ProductsOptionsRouteImport } from './../../dashboard/src/routes/_authenticated/$storeId/products/options'
import { Route as ProductsNewRouteImport } from './../../dashboard/src/routes/_authenticated/$storeId/products/new'
import { Route as ProductsMediaRouteImport } from './../../dashboard/src/routes/_authenticated/$storeId/products/media'
@@ -226,11 +226,6 @@ const SettingsTaxCategoriesRoute = SettingsTaxCategoriesRouteImport.update({
path: '/tax-categories',
getParentRoute: () => SettingsRoute,
} as any)
-const SettingsSuppliersRoute = SettingsSuppliersRouteImport.update({
- id: '/suppliers',
- path: '/suppliers',
- getParentRoute: () => SettingsRoute,
-} as any)
const SettingsStoreRoute = SettingsStoreRouteImport.update({
id: '/store',
path: '/store',
@@ -358,6 +353,11 @@ const ProductsTranslationsRoute = ProductsTranslationsRouteImport.update({
path: '/products/translations',
getParentRoute: () => authenticatedStoreIdRoute,
} as any)
+const ProductsSuppliersRoute = ProductsSuppliersRouteImport.update({
+ id: '/products/suppliers',
+ path: '/products/suppliers',
+ getParentRoute: () => authenticatedStoreIdRoute,
+} as any)
const ProductsOptionsRoute = ProductsOptionsRouteImport.update({
id: '/products/options',
path: '/products/options',
@@ -600,6 +600,7 @@ export interface FileRoutesByFullPath {
'/$storeId/products/media': typeof ProductsMediaRoute
'/$storeId/products/new': typeof ProductsNewRoute
'/$storeId/products/options': typeof ProductsOptionsRoute
+ '/$storeId/products/suppliers': typeof ProductsSuppliersRoute
'/$storeId/products/translations': typeof ProductsTranslationsRoute
'/$storeId/promotions/$promotionId': typeof PromotionsPromotionIdRoute
'/$storeId/promotions/gift-cards': typeof PromotionsGiftCardsRoute
@@ -625,7 +626,6 @@ export interface FileRoutesByFullPath {
'/$storeId/settings/staff': typeof SettingsStaffRoute
'/$storeId/settings/stock-locations': typeof SettingsStockLocationsRoute
'/$storeId/settings/store': typeof SettingsStoreRoute
- '/$storeId/settings/suppliers': typeof SettingsSuppliersRoute
'/$storeId/settings/tax-categories': typeof SettingsTaxCategoriesRoute
'/$storeId/settings/tax-rates': typeof SettingsTaxRatesRoute
'/$storeId/brands/': typeof BrandsDotindexRoute
@@ -690,6 +690,7 @@ export interface FileRoutesByTo {
'/$storeId/products/media': typeof ProductsMediaRoute
'/$storeId/products/new': typeof ProductsNewRoute
'/$storeId/products/options': typeof ProductsOptionsRoute
+ '/$storeId/products/suppliers': typeof ProductsSuppliersRoute
'/$storeId/products/translations': typeof ProductsTranslationsRoute
'/$storeId/promotions/$promotionId': typeof PromotionsPromotionIdRoute
'/$storeId/promotions/gift-cards': typeof PromotionsGiftCardsRoute
@@ -715,7 +716,6 @@ export interface FileRoutesByTo {
'/$storeId/settings/staff': typeof SettingsStaffRoute
'/$storeId/settings/stock-locations': typeof SettingsStockLocationsRoute
'/$storeId/settings/store': typeof SettingsStoreRoute
- '/$storeId/settings/suppliers': typeof SettingsSuppliersRoute
'/$storeId/settings/tax-categories': typeof SettingsTaxCategoriesRoute
'/$storeId/settings/tax-rates': typeof SettingsTaxRatesRoute
'/$storeId/brands': typeof BrandsDotindexRoute
@@ -784,6 +784,7 @@ export interface FileRoutesById {
'/_authenticated/$storeId/products/media': typeof ProductsMediaRoute
'/_authenticated/$storeId/products/new': typeof ProductsNewRoute
'/_authenticated/$storeId/products/options': typeof ProductsOptionsRoute
+ '/_authenticated/$storeId/products/suppliers': typeof ProductsSuppliersRoute
'/_authenticated/$storeId/products/translations': typeof ProductsTranslationsRoute
'/_authenticated/$storeId/promotions/$promotionId': typeof PromotionsPromotionIdRoute
'/_authenticated/$storeId/promotions/gift-cards': typeof PromotionsGiftCardsRoute
@@ -809,7 +810,6 @@ export interface FileRoutesById {
'/_authenticated/$storeId/settings/staff': typeof SettingsStaffRoute
'/_authenticated/$storeId/settings/stock-locations': typeof SettingsStockLocationsRoute
'/_authenticated/$storeId/settings/store': typeof SettingsStoreRoute
- '/_authenticated/$storeId/settings/suppliers': typeof SettingsSuppliersRoute
'/_authenticated/$storeId/settings/tax-categories': typeof SettingsTaxCategoriesRoute
'/_authenticated/$storeId/settings/tax-rates': typeof SettingsTaxRatesRoute
'/_authenticated/$storeId/brands/': typeof BrandsDotindexRoute
@@ -878,6 +878,7 @@ export interface FileRouteTypes {
| '/$storeId/products/media'
| '/$storeId/products/new'
| '/$storeId/products/options'
+ | '/$storeId/products/suppliers'
| '/$storeId/products/translations'
| '/$storeId/promotions/$promotionId'
| '/$storeId/promotions/gift-cards'
@@ -903,7 +904,6 @@ export interface FileRouteTypes {
| '/$storeId/settings/staff'
| '/$storeId/settings/stock-locations'
| '/$storeId/settings/store'
- | '/$storeId/settings/suppliers'
| '/$storeId/settings/tax-categories'
| '/$storeId/settings/tax-rates'
| '/$storeId/brands/'
@@ -968,6 +968,7 @@ export interface FileRouteTypes {
| '/$storeId/products/media'
| '/$storeId/products/new'
| '/$storeId/products/options'
+ | '/$storeId/products/suppliers'
| '/$storeId/products/translations'
| '/$storeId/promotions/$promotionId'
| '/$storeId/promotions/gift-cards'
@@ -993,7 +994,6 @@ export interface FileRouteTypes {
| '/$storeId/settings/staff'
| '/$storeId/settings/stock-locations'
| '/$storeId/settings/store'
- | '/$storeId/settings/suppliers'
| '/$storeId/settings/tax-categories'
| '/$storeId/settings/tax-rates'
| '/$storeId/brands'
@@ -1061,6 +1061,7 @@ export interface FileRouteTypes {
| '/_authenticated/$storeId/products/media'
| '/_authenticated/$storeId/products/new'
| '/_authenticated/$storeId/products/options'
+ | '/_authenticated/$storeId/products/suppliers'
| '/_authenticated/$storeId/products/translations'
| '/_authenticated/$storeId/promotions/$promotionId'
| '/_authenticated/$storeId/promotions/gift-cards'
@@ -1086,7 +1087,6 @@ export interface FileRouteTypes {
| '/_authenticated/$storeId/settings/staff'
| '/_authenticated/$storeId/settings/stock-locations'
| '/_authenticated/$storeId/settings/store'
- | '/_authenticated/$storeId/settings/suppliers'
| '/_authenticated/$storeId/settings/tax-categories'
| '/_authenticated/$storeId/settings/tax-rates'
| '/_authenticated/$storeId/brands/'
@@ -1315,13 +1315,6 @@ declare module '@tanstack/react-router' {
preLoaderRoute: typeof SettingsTaxCategoriesRouteImport
parentRoute: typeof SettingsRoute
}
- '/_authenticated/$storeId/settings/suppliers': {
- id: '/_authenticated/$storeId/settings/suppliers'
- path: '/suppliers'
- fullPath: '/$storeId/settings/suppliers'
- preLoaderRoute: typeof SettingsSuppliersRouteImport
- parentRoute: typeof SettingsRoute
- }
'/_authenticated/$storeId/settings/store': {
id: '/_authenticated/$storeId/settings/store'
path: '/store'
@@ -1497,6 +1490,13 @@ declare module '@tanstack/react-router' {
preLoaderRoute: typeof ProductsTranslationsRouteImport
parentRoute: typeof authenticatedStoreIdRoute
}
+ '/_authenticated/$storeId/products/suppliers': {
+ id: '/_authenticated/$storeId/products/suppliers'
+ path: '/products/suppliers'
+ fullPath: '/$storeId/products/suppliers'
+ preLoaderRoute: typeof ProductsSuppliersRouteImport
+ parentRoute: typeof authenticatedStoreIdRoute
+ }
'/_authenticated/$storeId/products/options': {
id: '/_authenticated/$storeId/products/options'
path: '/products/options'
@@ -1800,7 +1800,6 @@ interface SettingsRouteChildren {
SettingsStaffRoute: typeof SettingsStaffRoute
SettingsStockLocationsRoute: typeof SettingsStockLocationsRoute
SettingsStoreRoute: typeof SettingsStoreRoute
- SettingsSuppliersRoute: typeof SettingsSuppliersRoute
SettingsTaxCategoriesRoute: typeof SettingsTaxCategoriesRoute
SettingsTaxRatesRoute: typeof SettingsTaxRatesRoute
SettingsIndexRoute: typeof SettingsIndexRoute
@@ -1833,7 +1832,6 @@ const SettingsRouteChildren: SettingsRouteChildren = {
SettingsStaffRoute: SettingsStaffRoute,
SettingsStockLocationsRoute: SettingsStockLocationsRoute,
SettingsStoreRoute: SettingsStoreRoute,
- SettingsSuppliersRoute: SettingsSuppliersRoute,
SettingsTaxCategoriesRoute: SettingsTaxCategoriesRoute,
SettingsTaxRatesRoute: SettingsTaxRatesRoute,
SettingsIndexRoute: SettingsIndexRoute,
@@ -1872,6 +1870,7 @@ interface authenticatedStoreIdRouteChildren {
ProductsMediaRoute: typeof ProductsMediaRoute
ProductsNewRoute: typeof ProductsNewRoute
ProductsOptionsRoute: typeof ProductsOptionsRoute
+ ProductsSuppliersRoute: typeof ProductsSuppliersRoute
ProductsTranslationsRoute: typeof ProductsTranslationsRoute
PromotionsPromotionIdRoute: typeof PromotionsPromotionIdRoute
PromotionsGiftCardsRoute: typeof PromotionsGiftCardsRoute
@@ -1928,6 +1927,7 @@ const authenticatedStoreIdRouteChildren: authenticatedStoreIdRouteChildren = {
ProductsMediaRoute: ProductsMediaRoute,
ProductsNewRoute: ProductsNewRoute,
ProductsOptionsRoute: ProductsOptionsRoute,
+ ProductsSuppliersRoute: ProductsSuppliersRoute,
ProductsTranslationsRoute: ProductsTranslationsRoute,
PromotionsPromotionIdRoute: PromotionsPromotionIdRoute,
PromotionsGiftCardsRoute: PromotionsGiftCardsRoute,
diff --git a/packages/dashboard/src/routes/_authenticated/$storeId/settings/suppliers.tsx b/packages/dashboard/src/components/spree/supplier-sheet.tsx
similarity index 66%
rename from packages/dashboard/src/routes/_authenticated/$storeId/settings/suppliers.tsx
rename to packages/dashboard/src/components/spree/supplier-sheet.tsx
index 423800ee1d..942ad96ae9 100644
--- a/packages/dashboard/src/routes/_authenticated/$storeId/settings/suppliers.tsx
+++ b/packages/dashboard/src/components/spree/supplier-sheet.tsx
@@ -1,15 +1,5 @@
import type { Supplier } from '@spree/admin-sdk'
-import {
- adminClient,
- Can,
- CountryCombobox,
- ResourceTable,
- resourceSearchSchema,
- StateCombobox,
- Subject,
- useCountryStates,
- usePermissions,
-} from '@spree/dashboard-core'
+import { CountryCombobox, StateCombobox, useCountryStates } from '@spree/dashboard-core'
import {
Button,
Field,
@@ -17,7 +7,6 @@ import {
FieldGroup,
FieldLabel,
Input,
- RowActions,
Sheet,
SheetContent,
SheetDescription,
@@ -25,115 +14,10 @@ import {
SheetHeader,
SheetTitle,
Textarea,
- useConfirm,
- useRowClickBridge,
} from '@spree/dashboard-ui'
-import { PencilIcon, PlusIcon } from '@spree/dashboard-ui/icons'
-import { createFileRoute, useNavigate } from '@tanstack/react-router'
import { useState } from 'react'
import { useTranslation } from 'react-i18next'
-import { z } from 'zod/v4'
-import {
- useCreateSupplier,
- useDeleteSupplier,
- useSupplier,
- useUpdateSupplier,
-} from '../../../../hooks/use-suppliers'
-import '../../../../tables/suppliers'
-
-const suppliersSearchSchema = resourceSearchSchema.extend({
- edit: z.string().optional(),
- new: z.coerce.boolean().optional(),
-})
-
-export const Route = createFileRoute('/_authenticated/$storeId/settings/suppliers')({
- validateSearch: suppliersSearchSchema,
- component: SuppliersPage,
-})
-
-function SuppliersPage() {
- const { t } = useTranslation()
- const search = Route.useSearch() as z.infer<typeof suppliersSearchSchema>
- const navigate = useNavigate()
- const confirm = useConfirm()
- const deleteMutation = useDeleteSupplier()
- const { permissions } = usePermissions()
-
- const editId = search.edit
- const isCreating = !!search.new
-
- const closeSheet = () =>
- navigate({
- search: (prev: Record<string, unknown>) => {
- const { edit: _e, new: _n, ...rest } = prev
- return rest as never
- },
- })
-
- const openCreate = () =>
- navigate({ search: (prev: Record<string, unknown>) => ({ ...prev, new: true }) as never })
-
- const openEdit = (id: string) =>
- navigate({ search: (prev: Record<string, unknown>) => ({ ...prev, edit: id }) as never })
-
- useRowClickBridge('data-supplier-id', openEdit)
-
- async function handleDelete(supplier: Supplier) {
- const ok = await confirm({
- title: t('admin.suppliers.delete_confirm.title'),
- message: t('admin.suppliers.delete_confirm.message', { name: supplier.name }),
- variant: 'destructive',
- confirmLabel: t('admin.actions.delete'),
- })
- if (!ok) return
- await deleteMutation.mutateAsync(supplier.id).catch(() => undefined)
- }
-
- return (
- <>
- <ResourceTable<Supplier>
- tableKey="suppliers"
- queryKey="suppliers"
- queryFn={(params) => adminClient.suppliers.list(params)}
- searchParams={search}
- rowActions={(supplier) => (
- <RowActions
- actions={[
- {
- key: 'edit',
- label: t('admin.actions.edit'),
- icon: <PencilIcon className="size-4" />,
- onSelect: () => openEdit(supplier.id),
- },
- {
- key: 'delete',
- destructive: true,
- // A supplier with a purchasing history is kept: the orders
- // naming it have to keep meaning something, which is what the
- // model's `restrict_with_error` enforces. The Orders column
- // shows why the option is absent.
- visible: permissions.can('destroy', Subject.Supplier) && supplier.can_be_deleted,
- disabled: deleteMutation.isPending,
- onSelect: () => handleDelete(supplier),
- },
- ]}
- />
- )}
- actions={
- <Can I="create" a={Subject.Supplier}>
- <Button size="sm" className="h-[2.125rem]" onClick={openCreate}>
- <PlusIcon className="size-4" />
- {t('admin.suppliers.new_cta')}
- </Button>
- </Can>
- }
- />
-
- {isCreating && <SupplierSheet open onOpenChange={(open) => !open && closeSheet()} />}
- {editId && <SupplierSheet id={editId} open onOpenChange={(open) => !open && closeSheet()} />}
- </>
- )
-}
+import { useCreateSupplier, useSupplier, useUpdateSupplier } from '../../hooks/use-suppliers'
interface SupplierFormState {
name: string
@@ -165,14 +49,23 @@ const EMPTY_FORM: SupplierFormState = {
postal_code: '',
}
-function SupplierSheet({
+/**
+ * Create or correct a supplier, wherever the merchant needs one.
+ *
+ * The purchase order screen opens it too: buying from someone new is part of
+ * raising the order, not a detour through another screen.
+ */
+export function SupplierSheet({
id,
open,
onOpenChange,
+ onCreated,
}: {
id?: string
open: boolean
onOpenChange: (open: boolean) => void
+ /** Handed the new record, so a caller can select what it just created. */
+ onCreated?: (supplier: Supplier) => void
}) {
const { t } = useTranslation()
const { data: supplier } = useSupplier(id)
@@ -182,6 +75,9 @@ function SupplierSheet({
const [form, setForm] = useState<SupplierFormState>(EMPTY_FORM)
const [hydratedFor, setHydratedFor] = useState<string | undefined>(undefined)
+ // A blank name is only wrong once the merchant has tried to save; showing it
+ // on a sheet they just opened reads as an error they caused.
+ const [submitAttempted, setSubmitAttempted] = useState(false)
const { states } = useCountryStates(form.country_code)
// The record arrives after the sheet opens, so seed the fields the first
@@ -209,6 +105,7 @@ function SupplierSheet({
}
async function handleSubmit() {
+ setSubmitAttempted(true)
if (!form.name.trim()) return
// Emptied fields are sent as null, not dropped: the API reads a missing
@@ -223,6 +120,7 @@ function SupplierSheet({
.catch(() => undefined)
if (!saved) return
+ if (!id) onCreated?.(saved)
onOpenChange(false)
}
@@ -244,9 +142,9 @@ function SupplierSheet({
id="supplier-name"
value={form.name}
onChange={(event) => set('name', event.target.value)}
- aria-invalid={!form.name.trim() || undefined}
+ aria-invalid={(submitAttempted && !form.name.trim()) || undefined}
/>
- {!form.name.trim() && (
+ {submitAttempted && !form.name.trim() && (
<FieldError>{t('admin.suppliers.errors.name_blank')}</FieldError>
)}
</Field>
@@ -370,11 +268,10 @@ function SupplierSheet({
>
{t('admin.actions.cancel')}
</Button>
- <Button
- type="button"
- onClick={handleSubmit}
- disabled={!form.name.trim() || mutation.isPending}
- >
+ {/* Clickable with the name still blank: pressing Save is how the
+ merchant asks what is missing, and a button that only greys out
+ never says. */}
+ <Button type="button" onClick={handleSubmit} disabled={mutation.isPending}>
{mutation.isPending ? t('admin.actions.saving') : t('admin.actions.save')}
</Button>
</SheetFooter>
diff --git a/packages/dashboard/src/locales/ar.json b/packages/dashboard/src/locales/ar.json
index 7a780c78ea..fff0f1d0ba 100644
--- a/packages/dashboard/src/locales/ar.json
+++ b/packages/dashboard/src/locales/ar.json
@@ -2602,7 +2602,9 @@
"settings": "الإعدادات",
"transfers": "التحويلات",
"translations": "الترجمات",
- "purchase_orders": "أوامر الشراء"
+ "purchase_orders": "أوامر الشراء",
+ "inventory": "المخزون",
+ "suppliers": "الموردون"
},
"option_types": {
"columns": {
@@ -5459,7 +5461,8 @@
"variant": "المنتج",
"sku": "رمز SKU",
"unit_cost": "تكلفة الوحدة"
- }
+ },
+ "picker_title": "إضافة منتجات"
},
"stock_history": {
"title": "سجل المخزون",
diff --git a/packages/dashboard/src/locales/de.json b/packages/dashboard/src/locales/de.json
index 85fa29b819..3b50fb6cd6 100644
--- a/packages/dashboard/src/locales/de.json
+++ b/packages/dashboard/src/locales/de.json
@@ -2584,7 +2584,9 @@
"settings": "Einstellungen",
"transfers": "Umlagerungen",
"translations": "Übersetzungen",
- "purchase_orders": "Bestellungen"
+ "purchase_orders": "Bestellungen",
+ "inventory": "Lagerbestand",
+ "suppliers": "Lieferanten"
},
"option_types": {
"columns": {
@@ -5430,7 +5432,8 @@
"variant": "Produkt",
"sku": "SKU",
"unit_cost": "Stückkosten"
- }
+ },
+ "picker_title": "Produkte hinzufügen"
},
"stock_history": {
"title": "Bestandsverlauf",
diff --git a/packages/dashboard/src/locales/en.json b/packages/dashboard/src/locales/en.json
index 0a832ebe25..e5ddedd5db 100644
--- a/packages/dashboard/src/locales/en.json
+++ b/packages/dashboard/src/locales/en.json
@@ -2584,7 +2584,9 @@
"settings": "Settings",
"transfers": "Transfers",
"translations": "Translations",
- "purchase_orders": "Purchase orders"
+ "purchase_orders": "Purchase orders",
+ "inventory": "Inventory",
+ "suppliers": "Suppliers"
},
"option_types": {
"columns": {
@@ -5430,7 +5432,8 @@
"variant": "Product",
"sku": "SKU",
"unit_cost": "Unit cost"
- }
+ },
+ "picker_title": "Add products"
},
"stock_history": {
"title": "Stock history",
diff --git a/packages/dashboard/src/locales/fr.json b/packages/dashboard/src/locales/fr.json
index 6e81a03a3a..e9542e9115 100644
--- a/packages/dashboard/src/locales/fr.json
+++ b/packages/dashboard/src/locales/fr.json
@@ -2584,7 +2584,9 @@
"settings": "Paramètres",
"transfers": "Transferts",
"translations": "Traductions",
- "purchase_orders": "Bons de commande"
+ "purchase_orders": "Bons de commande",
+ "inventory": "Inventaire",
+ "suppliers": "Fournisseurs"
},
"option_types": {
"columns": {
@@ -5430,7 +5432,8 @@
"variant": "Produit",
"sku": "UGS",
"unit_cost": "Coût unitaire"
- }
+ },
+ "picker_title": "Ajouter des produits"
},
"stock_history": {
"title": "Historique du stock",
diff --git a/packages/dashboard/src/locales/pl.json b/packages/dashboard/src/locales/pl.json
index b62447e021..9c826d76d3 100644
--- a/packages/dashboard/src/locales/pl.json
+++ b/packages/dashboard/src/locales/pl.json
@@ -2606,7 +2606,9 @@
"settings": "Ustawienia",
"transfers": "Transfery",
"translations": "Tłumaczenia",
- "purchase_orders": "Zamówienia zakupu"
+ "purchase_orders": "Zamówienia zakupu",
+ "inventory": "Magazyn",
+ "suppliers": "Dostawcy"
},
"option_types": {
"columns": {
@@ -5492,7 +5494,8 @@
"variant": "Produkt",
"sku": "SKU",
"unit_cost": "Koszt jednostkowy"
- }
+ },
+ "picker_title": "Dodaj produkty"
},
"stock_history": {
"title": "Historia stanu",
diff --git a/packages/dashboard/src/locales/zh-CN.json b/packages/dashboard/src/locales/zh-CN.json
index 752be326c8..93757c1933 100644
--- a/packages/dashboard/src/locales/zh-CN.json
+++ b/packages/dashboard/src/locales/zh-CN.json
@@ -2577,7 +2577,9 @@
"settings": "设置",
"transfers": "调拨",
"translations": "翻译",
- "purchase_orders": "采购订单"
+ "purchase_orders": "采购订单",
+ "inventory": "库存",
+ "suppliers": "供应商"
},
"option_types": {
"columns": {
@@ -5419,7 +5421,8 @@
"variant": "商品",
"sku": "SKU",
"unit_cost": "单位成本"
- }
+ },
+ "picker_title": "添加商品"
},
"stock_history": {
"title": "库存记录",
diff --git a/packages/dashboard/src/nav/default.ts b/packages/dashboard/src/nav/default.ts
index 562104c3f3..1bd088a82c 100644
--- a/packages/dashboard/src/nav/default.ts
+++ b/packages/dashboard/src/nav/default.ts
@@ -12,6 +12,7 @@ import {
StoreIcon,
TagIcon,
UsersIcon,
+ WarehouseIcon,
} from '@spree/dashboard-ui/icons'
import { GettingStartedNavBadge } from '../components/spree/getting-started-nav-badge'
import {
@@ -147,19 +148,40 @@ nav.add({
subject: Subject.Product,
position: 475,
},
+ ],
+})
+
+// Moving stock in and around is its own job, done by different people than the
+// ones who write the catalog — so it gets its own section rather than crowding
+// the end of Products.
+nav.add({
+ key: 'inventory',
+ labelKey: 'admin.nav.inventory',
+ path: '/products/transfers',
+ icon: WarehouseIcon,
+ subject: Subject.StockTransfer,
+ position: 350,
+ children: [
{
- key: 'products.transfers',
+ key: 'inventory.transfers',
labelKey: 'admin.nav.transfers',
path: '/products/transfers',
subject: Subject.StockTransfer,
- position: 500,
+ position: 100,
},
{
- key: 'products.purchase-orders',
+ key: 'inventory.purchase-orders',
labelKey: 'admin.nav.purchase_orders',
path: '/products/purchase-orders',
subject: Subject.PurchaseOrder,
- position: 550,
+ position: 200,
+ },
+ {
+ key: 'inventory.suppliers',
+ labelKey: 'admin.nav.suppliers',
+ path: '/products/suppliers',
+ subject: Subject.Supplier,
+ position: 300,
},
],
})
diff --git a/packages/dashboard/src/nav/settings.ts b/packages/dashboard/src/nav/settings.ts
index 2b2d751253..0c59517725 100644
--- a/packages/dashboard/src/nav/settings.ts
+++ b/packages/dashboard/src/nav/settings.ts
@@ -1,7 +1,6 @@
import { Subject, settingsNav } from '@spree/dashboard-core'
import {
BanknoteIcon,
- Building2Icon,
ClipboardCheckIcon,
CreditCardIcon,
GlobeIcon,
@@ -224,18 +223,6 @@ settingsNav.add({
subject: Subject.PackageType,
})
-settingsNav.add({
- key: 'settings.suppliers',
- labelKey: 'admin.settings_nav.items.suppliers',
- descriptionKey: 'admin.settings_nav.descriptions.suppliers',
- keywords: ['vendor', 'purchasing', 'procurement', 'purchase orders'],
- path: '/suppliers',
- icon: Building2Icon,
- group: 'shipping',
- position: 250,
- subject: Subject.Supplier,
-})
-
settingsNav.add({
key: 'settings.product-types',
labelKey: 'admin.settings_nav.items.product_types',
diff --git a/packages/dashboard/src/routeTree.gen.ts b/packages/dashboard/src/routeTree.gen.ts
index c440afef99..9506955321 100644
--- a/packages/dashboard/src/routeTree.gen.ts
+++ b/packages/dashboard/src/routeTree.gen.ts
@@ -33,7 +33,6 @@ import { Route as CustomersIndexRouteImport } from './routes/_authenticated/$sto
import { Route as CompaniesIndexRouteImport } from './routes/_authenticated/$storeId/companies/index'
import { Route as SettingsTaxRatesRouteImport } from './routes/_authenticated/$storeId/settings/tax-rates'
import { Route as SettingsTaxCategoriesRouteImport } from './routes/_authenticated/$storeId/settings/tax-categories'
-import { Route as SettingsSuppliersRouteImport } from './routes/_authenticated/$storeId/settings/suppliers'
import { Route as SettingsStoreRouteImport } from './routes/_authenticated/$storeId/settings/store'
import { Route as SettingsStockLocationsRouteImport } from './routes/_authenticated/$storeId/settings/stock-locations'
import { Route as SettingsStaffRouteImport } from './routes/_authenticated/$storeId/settings/staff'
@@ -59,6 +58,7 @@ import { Route as PromotionsNewRouteImport } from './routes/_authenticated/$stor
import { Route as PromotionsGiftCardsRouteImport } from './routes/_authenticated/$storeId/promotions/gift-cards'
import { Route as PromotionsPromotionIdRouteImport } from './routes/_authenticated/$storeId/promotions/$promotionId'
import { Route as ProductsTranslationsRouteImport } from './routes/_authenticated/$storeId/products/translations'
+import { Route as ProductsSuppliersRouteImport } from './routes/_authenticated/$storeId/products/suppliers'
import { Route as ProductsOptionsRouteImport } from './routes/_authenticated/$storeId/products/options'
import { Route as ProductsNewRouteImport } from './routes/_authenticated/$storeId/products/new'
import { Route as ProductsMediaRouteImport } from './routes/_authenticated/$storeId/products/media'
@@ -219,11 +219,6 @@ const SettingsTaxCategoriesRoute = SettingsTaxCategoriesRouteImport.update({
path: '/tax-categories',
getParentRoute: () => SettingsRoute,
} as any)
-const SettingsSuppliersRoute = SettingsSuppliersRouteImport.update({
- id: '/suppliers',
- path: '/suppliers',
- getParentRoute: () => SettingsRoute,
-} as any)
const SettingsStoreRoute = SettingsStoreRouteImport.update({
id: '/store',
path: '/store',
@@ -351,6 +346,11 @@ const ProductsTranslationsRoute = ProductsTranslationsRouteImport.update({
path: '/products/translations',
getParentRoute: () => authenticatedStoreIdRoute,
} as any)
+const ProductsSuppliersRoute = ProductsSuppliersRouteImport.update({
+ id: '/products/suppliers',
+ path: '/products/suppliers',
+ getParentRoute: () => authenticatedStoreIdRoute,
+} as any)
const ProductsOptionsRoute = ProductsOptionsRouteImport.update({
id: '/products/options',
path: '/products/options',
@@ -587,6 +587,7 @@ export interface FileRoutesByFullPath {
'/$storeId/products/media': typeof ProductsMediaRoute
'/$storeId/products/new': typeof ProductsNewRoute
'/$storeId/products/options': typeof ProductsOptionsRoute
+ '/$storeId/products/suppliers': typeof ProductsSuppliersRoute
'/$storeId/products/translations': typeof ProductsTranslationsRoute
'/$storeId/promotions/$promotionId': typeof PromotionsPromotionIdRoute
'/$storeId/promotions/gift-cards': typeof PromotionsGiftCardsRoute
@@ -612,7 +613,6 @@ export interface FileRoutesByFullPath {
'/$storeId/settings/staff': typeof SettingsStaffRoute
'/$storeId/settings/stock-locations': typeof SettingsStockLocationsRoute
'/$storeId/settings/store': typeof SettingsStoreRoute
- '/$storeId/settings/suppliers': typeof SettingsSuppliersRoute
'/$storeId/settings/tax-categories': typeof SettingsTaxCategoriesRoute
'/$storeId/settings/tax-rates': typeof SettingsTaxRatesRoute
'/$storeId/companies/': typeof CompaniesIndexRoute
@@ -675,6 +675,7 @@ export interface FileRoutesByTo {
'/$storeId/products/media': typeof ProductsMediaRoute
'/$storeId/products/new': typeof ProductsNewRoute
'/$storeId/products/options': typeof ProductsOptionsRoute
+ '/$storeId/products/suppliers': typeof ProductsSuppliersRoute
'/$storeId/products/translations': typeof ProductsTranslationsRoute
'/$storeId/promotions/$promotionId': typeof PromotionsPromotionIdRoute
'/$storeId/promotions/gift-cards': typeof PromotionsGiftCardsRoute
@@ -700,7 +701,6 @@ export interface FileRoutesByTo {
'/$storeId/settings/staff': typeof SettingsStaffRoute
'/$storeId/settings/stock-locations': typeof SettingsStockLocationsRoute
'/$storeId/settings/store': typeof SettingsStoreRoute
- '/$storeId/settings/suppliers': typeof SettingsSuppliersRoute
'/$storeId/settings/tax-categories': typeof SettingsTaxCategoriesRoute
'/$storeId/settings/tax-rates': typeof SettingsTaxRatesRoute
'/$storeId/companies': typeof CompaniesIndexRoute
@@ -767,6 +767,7 @@ export interface FileRoutesById {
'/_authenticated/$storeId/products/media': typeof ProductsMediaRoute
'/_authenticated/$storeId/products/new': typeof ProductsNewRoute
'/_authenticated/$storeId/products/options': typeof ProductsOptionsRoute
+ '/_authenticated/$storeId/products/suppliers': typeof ProductsSuppliersRoute
'/_authenticated/$storeId/products/translations': typeof ProductsTranslationsRoute
'/_authenticated/$storeId/promotions/$promotionId': typeof PromotionsPromotionIdRoute
'/_authenticated/$storeId/promotions/gift-cards': typeof PromotionsGiftCardsRoute
@@ -792,7 +793,6 @@ export interface FileRoutesById {
'/_authenticated/$storeId/settings/staff': typeof SettingsStaffRoute
'/_authenticated/$storeId/settings/stock-locations': typeof SettingsStockLocationsRoute
'/_authenticated/$storeId/settings/store': typeof SettingsStoreRoute
- '/_authenticated/$storeId/settings/suppliers': typeof SettingsSuppliersRoute
'/_authenticated/$storeId/settings/tax-categories': typeof SettingsTaxCategoriesRoute
'/_authenticated/$storeId/settings/tax-rates': typeof SettingsTaxRatesRoute
'/_authenticated/$storeId/companies/': typeof CompaniesIndexRoute
@@ -859,6 +859,7 @@ export interface FileRouteTypes {
| '/$storeId/products/media'
| '/$storeId/products/new'
| '/$storeId/products/options'
+ | '/$storeId/products/suppliers'
| '/$storeId/products/translations'
| '/$storeId/promotions/$promotionId'
| '/$storeId/promotions/gift-cards'
@@ -884,7 +885,6 @@ export interface FileRouteTypes {
| '/$storeId/settings/staff'
| '/$storeId/settings/stock-locations'
| '/$storeId/settings/store'
- | '/$storeId/settings/suppliers'
| '/$storeId/settings/tax-categories'
| '/$storeId/settings/tax-rates'
| '/$storeId/companies/'
@@ -947,6 +947,7 @@ export interface FileRouteTypes {
| '/$storeId/products/media'
| '/$storeId/products/new'
| '/$storeId/products/options'
+ | '/$storeId/products/suppliers'
| '/$storeId/products/translations'
| '/$storeId/promotions/$promotionId'
| '/$storeId/promotions/gift-cards'
@@ -972,7 +973,6 @@ export interface FileRouteTypes {
| '/$storeId/settings/staff'
| '/$storeId/settings/stock-locations'
| '/$storeId/settings/store'
- | '/$storeId/settings/suppliers'
| '/$storeId/settings/tax-categories'
| '/$storeId/settings/tax-rates'
| '/$storeId/companies'
@@ -1038,6 +1038,7 @@ export interface FileRouteTypes {
| '/_authenticated/$storeId/products/media'
| '/_authenticated/$storeId/products/new'
| '/_authenticated/$storeId/products/options'
+ | '/_authenticated/$storeId/products/suppliers'
| '/_authenticated/$storeId/products/translations'
| '/_authenticated/$storeId/promotions/$promotionId'
| '/_authenticated/$storeId/promotions/gift-cards'
@@ -1063,7 +1064,6 @@ export interface FileRouteTypes {
| '/_authenticated/$storeId/settings/staff'
| '/_authenticated/$storeId/settings/stock-locations'
| '/_authenticated/$storeId/settings/store'
- | '/_authenticated/$storeId/settings/suppliers'
| '/_authenticated/$storeId/settings/tax-categories'
| '/_authenticated/$storeId/settings/tax-rates'
| '/_authenticated/$storeId/companies/'
@@ -1284,13 +1284,6 @@ declare module '@tanstack/react-router' {
preLoaderRoute: typeof SettingsTaxCategoriesRouteImport
parentRoute: typeof SettingsRoute
}
- '/_authenticated/$storeId/settings/suppliers': {
- id: '/_authenticated/$storeId/settings/suppliers'
- path: '/suppliers'
- fullPath: '/$storeId/settings/suppliers'
- preLoaderRoute: typeof SettingsSuppliersRouteImport
- parentRoute: typeof SettingsRoute
- }
'/_authenticated/$storeId/settings/store': {
id: '/_authenticated/$storeId/settings/store'
path: '/store'
@@ -1466,6 +1459,13 @@ declare module '@tanstack/react-router' {
preLoaderRoute: typeof ProductsTranslationsRouteImport
parentRoute: typeof authenticatedStoreIdRoute
}
+ '/_authenticated/$storeId/products/suppliers': {
+ id: '/_authenticated/$storeId/products/suppliers'
+ path: '/products/suppliers'
+ fullPath: '/$storeId/products/suppliers'
+ preLoaderRoute: typeof ProductsSuppliersRouteImport
+ parentRoute: typeof authenticatedStoreIdRoute
+ }
'/_authenticated/$storeId/products/options': {
id: '/_authenticated/$storeId/products/options'
path: '/products/options'
@@ -1762,7 +1762,6 @@ interface SettingsRouteChildren {
SettingsStaffRoute: typeof SettingsStaffRoute
SettingsStockLocationsRoute: typeof SettingsStockLocationsRoute
SettingsStoreRoute: typeof SettingsStoreRoute
- SettingsSuppliersRoute: typeof SettingsSuppliersRoute
SettingsTaxCategoriesRoute: typeof SettingsTaxCategoriesRoute
SettingsTaxRatesRoute: typeof SettingsTaxRatesRoute
SettingsIndexRoute: typeof SettingsIndexRoute
@@ -1795,7 +1794,6 @@ const SettingsRouteChildren: SettingsRouteChildren = {
SettingsStaffRoute: SettingsStaffRoute,
SettingsStockLocationsRoute: SettingsStockLocationsRoute,
SettingsStoreRoute: SettingsStoreRoute,
- SettingsSuppliersRoute: SettingsSuppliersRoute,
SettingsTaxCategoriesRoute: SettingsTaxCategoriesRoute,
SettingsTaxRatesRoute: SettingsTaxRatesRoute,
SettingsIndexRoute: SettingsIndexRoute,
@@ -1833,6 +1831,7 @@ interface authenticatedStoreIdRouteChildren {
ProductsMediaRoute: typeof ProductsMediaRoute
ProductsNewRoute: typeof ProductsNewRoute
ProductsOptionsRoute: typeof ProductsOptionsRoute
+ ProductsSuppliersRoute: typeof ProductsSuppliersRoute
ProductsTranslationsRoute: typeof ProductsTranslationsRoute
PromotionsPromotionIdRoute: typeof PromotionsPromotionIdRoute
PromotionsGiftCardsRoute: typeof PromotionsGiftCardsRoute
@@ -1887,6 +1886,7 @@ const authenticatedStoreIdRouteChildren: authenticatedStoreIdRouteChildren = {
ProductsMediaRoute: ProductsMediaRoute,
ProductsNewRoute: ProductsNewRoute,
ProductsOptionsRoute: ProductsOptionsRoute,
+ ProductsSuppliersRoute: ProductsSuppliersRoute,
ProductsTranslationsRoute: ProductsTranslationsRoute,
PromotionsPromotionIdRoute: PromotionsPromotionIdRoute,
PromotionsGiftCardsRoute: PromotionsGiftCardsRoute,
diff --git a/packages/dashboard/src/routes/_authenticated/$storeId/products/suppliers.tsx b/packages/dashboard/src/routes/_authenticated/$storeId/products/suppliers.tsx
new file mode 100644
index 0000000000..5ca0d06413
--- /dev/null
+++ b/packages/dashboard/src/routes/_authenticated/$storeId/products/suppliers.tsx
@@ -0,0 +1,111 @@
+import type { Supplier } from '@spree/admin-sdk'
+import {
+ adminClient,
+ Can,
+ ResourceTable,
+ resourceSearchSchema,
+ Subject,
+ usePermissions,
+} from '@spree/dashboard-core'
+import { Button, RowActions, useConfirm, useRowClickBridge } from '@spree/dashboard-ui'
+import { PencilIcon, PlusIcon } from '@spree/dashboard-ui/icons'
+import { createFileRoute, useNavigate } from '@tanstack/react-router'
+import { useTranslation } from 'react-i18next'
+import { z } from 'zod/v4'
+import { SupplierSheet } from '../../../../components/spree/supplier-sheet'
+import { useDeleteSupplier } from '../../../../hooks/use-suppliers'
+import '../../../../tables/suppliers'
+
+const suppliersSearchSchema = resourceSearchSchema.extend({
+ edit: z.string().optional(),
+ new: z.coerce.boolean().optional(),
+})
+
+export const Route = createFileRoute('/_authenticated/$storeId/products/suppliers')({
+ validateSearch: suppliersSearchSchema,
+ component: SuppliersPage,
+})
+
+function SuppliersPage() {
+ const { t } = useTranslation()
+ const search = Route.useSearch() as z.infer<typeof suppliersSearchSchema>
+ const navigate = useNavigate()
+ const confirm = useConfirm()
+ const deleteMutation = useDeleteSupplier()
+ const { permissions } = usePermissions()
+
+ const editId = search.edit
+ const isCreating = !!search.new
+
+ const closeSheet = () =>
+ navigate({
+ search: (prev: Record<string, unknown>) => {
+ const { edit: _e, new: _n, ...rest } = prev
+ return rest as never
+ },
+ })
+
+ const openCreate = () =>
+ navigate({ search: (prev: Record<string, unknown>) => ({ ...prev, new: true }) as never })
+
+ const openEdit = (id: string) =>
+ navigate({ search: (prev: Record<string, unknown>) => ({ ...prev, edit: id }) as never })
+
+ useRowClickBridge('data-supplier-id', openEdit)
+
+ async function handleDelete(supplier: Supplier) {
+ const ok = await confirm({
+ title: t('admin.suppliers.delete_confirm.title'),
+ message: t('admin.suppliers.delete_confirm.message', { name: supplier.name }),
+ variant: 'destructive',
+ confirmLabel: t('admin.actions.delete'),
+ })
+ if (!ok) return
+ await deleteMutation.mutateAsync(supplier.id).catch(() => undefined)
+ }
+
+ return (
+ <>
+ <ResourceTable<Supplier>
+ tableKey="suppliers"
+ queryKey="suppliers"
+ queryFn={(params) => adminClient.suppliers.list(params)}
+ searchParams={search}
+ rowActions={(supplier) => (
+ <RowActions
+ actions={[
+ {
+ key: 'edit',
+ label: t('admin.actions.edit'),
+ icon: <PencilIcon className="size-4" />,
+ onSelect: () => openEdit(supplier.id),
+ },
+ {
+ key: 'delete',
+ destructive: true,
+ // A supplier with a purchasing history is kept: the orders
+ // naming it have to keep meaning something, which is what the
+ // model's `restrict_with_error` enforces. The Orders column
+ // shows why the option is absent.
+ visible: permissions.can('destroy', Subject.Supplier) && supplier.can_be_deleted,
+ disabled: deleteMutation.isPending,
+ onSelect: () => handleDelete(supplier),
+ },
+ ]}
+ />
+ )}
+ actions={
+ <Can I="create" a={Subject.Supplier}>
+ <Button size="sm" className="h-[2.125rem]" onClick={openCreate}>
+ <PlusIcon className="size-4" />
+ {t('admin.suppliers.new_cta')}
+ </Button>
+ </Can>
+ }
+ />
+
+ {isCreating && <SupplierSheet open onOpenChange={(open) => !open && closeSheet()} />}
+ {editId && <SupplierSheet id={editId} open onOpenChange={(open) => !open && closeSheet()} />}
+ </>
+ )
+}