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 ask what is on order from one supplier

Łukasz Adamczyk1df4d7a9f58a
diff --git a/packages/dashboard/src/hooks/use-suppliers.ts b/packages/dashboard/src/hooks/use-suppliers.ts
index 53071e8704..ed10b0de3e 100644
--- a/packages/dashboard/src/hooks/use-suppliers.ts
+++ b/packages/dashboard/src/hooks/use-suppliers.ts
@@ -15,6 +15,31 @@ export function useSuppliers(params?: { limit?: number; search?: string }) {
})
}
+/**
+ * A supplier picker, for the create form and the purchase orders filter.
+ *
+ * Searches on the same predicate the suppliers table searches on, so "how you
+ * look for a supplier" is defined once. `search:` — which the customer and
+ * order pickers use — is a Ransack *scope* those models declare and this one
+ * does not, so sent here it is quietly ignored and every supplier comes back.
+ */
+export function supplierAutocompleteProps(queryKey: string) {
+ return {
+ queryKey,
+ search: (query: string) =>
+ adminClient.suppliers.list({
+ name_or_contact_name_or_email_cont: query,
+ limit: 100,
+ sort: 'name',
+ fields: ['name'],
+ }),
+ hydrate: (ids: string[]) => adminClient.suppliers.list({ id_in: ids, limit: ids.length }),
+ getOptionLabel: (supplier: Supplier) => supplier.name ?? supplier.id,
+ placeholder: i18n.t('admin.suppliers.autocomplete.placeholder'),
+ emptyText: i18n.t('admin.suppliers.autocomplete.empty'),
+ }
+}
+
export function useSupplier(id: string | undefined) {
return useQuery({
queryKey: useResourceKey('suppliers', id ?? 'noop'),
diff --git a/packages/dashboard/src/locales/ar.json b/packages/dashboard/src/locales/ar.json
index a8d27060f1..e1dca3b1b8 100644
--- a/packages/dashboard/src/locales/ar.json
+++ b/packages/dashboard/src/locales/ar.json
@@ -5573,6 +5573,10 @@
"empty": "لا يوجد موردون بعد",
"search_placeholder": "ابحث بالاسم أو جهة الاتصال أو البريد…"
},
+ "autocomplete": {
+ "placeholder": "ابحث بالاسم أو جهة الاتصال أو البريد…",
+ "empty": "لا يوجد موردون مطابقون"
+ },
"columns": {
"contact": "جهة الاتصال",
"orders": "أوامر الشراء"
diff --git a/packages/dashboard/src/locales/de.json b/packages/dashboard/src/locales/de.json
index 57742686d7..e562ac551a 100644
--- a/packages/dashboard/src/locales/de.json
+++ b/packages/dashboard/src/locales/de.json
@@ -5544,6 +5544,10 @@
"empty": "Noch keine Lieferanten",
"search_placeholder": "Nach Name, Kontakt oder E-Mail suchen…"
},
+ "autocomplete": {
+ "placeholder": "Nach Name, Kontakt oder E-Mail suchen…",
+ "empty": "Keine passenden Lieferanten"
+ },
"columns": {
"contact": "Kontakt",
"orders": "Bestellungen"
diff --git a/packages/dashboard/src/locales/en.json b/packages/dashboard/src/locales/en.json
index 3057f38507..fc5a30b9c4 100644
--- a/packages/dashboard/src/locales/en.json
+++ b/packages/dashboard/src/locales/en.json
@@ -5544,6 +5544,10 @@
"empty": "No suppliers yet",
"search_placeholder": "Search by name, contact or email…"
},
+ "autocomplete": {
+ "placeholder": "Search by name, contact or email…",
+ "empty": "No suppliers match"
+ },
"columns": {
"contact": "Contact",
"orders": "Purchase orders"
diff --git a/packages/dashboard/src/locales/fr.json b/packages/dashboard/src/locales/fr.json
index 123157ed8e..3db4a63cab 100644
--- a/packages/dashboard/src/locales/fr.json
+++ b/packages/dashboard/src/locales/fr.json
@@ -5544,6 +5544,10 @@
"empty": "Aucun fournisseur",
"search_placeholder": "Rechercher par nom, contact ou e-mail…"
},
+ "autocomplete": {
+ "placeholder": "Rechercher par nom, contact ou e-mail…",
+ "empty": "Aucun fournisseur correspondant"
+ },
"columns": {
"contact": "Contact",
"orders": "Bons de commande"
diff --git a/packages/dashboard/src/locales/pl.json b/packages/dashboard/src/locales/pl.json
index 4823e188bd..7c5b898d10 100644
--- a/packages/dashboard/src/locales/pl.json
+++ b/packages/dashboard/src/locales/pl.json
@@ -5606,6 +5606,10 @@
"empty": "Brak dostawców",
"search_placeholder": "Szukaj po nazwie, kontakcie lub e-mailu…"
},
+ "autocomplete": {
+ "placeholder": "Szukaj po nazwie, kontakcie lub e-mailu…",
+ "empty": "Brak pasujących dostawców"
+ },
"columns": {
"contact": "Kontakt",
"orders": "Zamówienia zakupu"
diff --git a/packages/dashboard/src/locales/zh-CN.json b/packages/dashboard/src/locales/zh-CN.json
index c9fc6de296..37552dd317 100644
--- a/packages/dashboard/src/locales/zh-CN.json
+++ b/packages/dashboard/src/locales/zh-CN.json
@@ -5533,6 +5533,10 @@
"empty": "暂无供应商",
"search_placeholder": "按名称、联系人或邮箱搜索…"
},
+ "autocomplete": {
+ "placeholder": "按名称、联系人或邮箱搜索…",
+ "empty": "没有匹配的供应商"
+ },
"columns": {
"contact": "联系人",
"orders": "采购订单"
diff --git a/packages/dashboard/src/routes/_authenticated/$storeId/products/purchase-orders/new.tsx b/packages/dashboard/src/routes/_authenticated/$storeId/products/purchase-orders/new.tsx
index 40342ee1ef..e767905a50 100644
--- a/packages/dashboard/src/routes/_authenticated/$storeId/products/purchase-orders/new.tsx
+++ b/packages/dashboard/src/routes/_authenticated/$storeId/products/purchase-orders/new.tsx
@@ -1,6 +1,5 @@
import type { Supplier } from '@spree/admin-sdk'
import {
- adminClient,
CurrencySelect,
PageHeader,
ResourceCombobox,
@@ -32,6 +31,7 @@ import {
VariantLineEditor,
} from '../../../../../components/spree/variant-line-editor'
import { useCreatePurchaseOrder } from '../../../../../hooks/use-purchase-orders'
+import { supplierAutocompleteProps } from '../../../../../hooks/use-suppliers'
export const Route = createFileRoute('/_authenticated/$storeId/products/purchase-orders/new')({
component: NewPurchaseOrderPage,
@@ -105,15 +105,10 @@ function NewPurchaseOrderPage() {
more suppliers than one page of a Select would show, and a
Select says nothing about the ones it left out. */}
<ResourceCombobox<Supplier>
+ {...supplierAutocompleteProps('purchase-order-supplier-picker')}
id="supplier"
- queryKey="purchase-order-supplier-picker"
value={supplierId}
onChange={(id) => setSupplierId(id ?? '')}
- search={(query) => adminClient.suppliers.list({ search: query, limit: 20 })}
- hydrate={(ids) =>
- adminClient.suppliers.list({ q: { id_in: ids }, limit: ids.length || 1 })
- }
- getOptionLabel={(supplier) => supplier.name}
placeholder={t('admin.purchase_orders.fields.supplier_placeholder')}
/>
</Field>
diff --git a/packages/dashboard/src/tables/purchase-orders.tsx b/packages/dashboard/src/tables/purchase-orders.tsx
index 88fb50f70a..ec54f05da9 100644
--- a/packages/dashboard/src/tables/purchase-orders.tsx
+++ b/packages/dashboard/src/tables/purchase-orders.tsx
@@ -3,6 +3,7 @@ import { defineTable } from '@spree/dashboard-core'
import { RelativeTime, ResourceNameCell, StatusBadge } from '@spree/dashboard-ui'
import { TruckIcon } from '@spree/dashboard-ui/icons'
import i18n from 'i18next'
+import { supplierAutocompleteProps } from '../hooks/use-suppliers'
import { PURCHASE_ORDER_STATUSES } from '../schemas/inventory-operations'
function statusLabel(value: string): string {
@@ -54,6 +55,14 @@ defineTable<PurchaseOrder>('purchase-orders', {
{
key: 'supplier',
label: i18n.t('admin.purchase_orders.columns.supplier'),
+ filterable: true,
+ // Picked from a list rather than typed, the way an order filters by its
+ // customer: a merchant asking what is on order from Acme knows who they
+ // mean. Matched through the association's id, so a supplier renamed
+ // since the order was placed still answers.
+ filterType: 'resource',
+ filterResource: supplierAutocompleteProps('purchase-orders-table-supplier-filter'),
+ ransackAttribute: 'supplier_id',
default: true,
render: (po) => po.supplier?.name ?? '—',
},