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.

Export and import price-list prices from the dashboard

Damian Legawiec8e5dc20147ff
diff --git a/.changeset/price-list-csv-and-volume-pricing.md b/.changeset/price-list-csv-and-volume-pricing.md
new file mode 100644
index 0000000000..7ab2c13a80
--- /dev/null
+++ b/.changeset/price-list-csv-and-volume-pricing.md
@@ -0,0 +1,21 @@
+---
+"@spree/dashboard": minor
+"@spree/dashboard-core": minor
+"@spree/dashboard-ui": minor
+"@spree/admin-sdk": minor
+---
+
+Volume pricing: quantity breaks, percentage tiers and a price-list CSV.
+
+A price list can now carry a ladder per variant — a unit price from each
+quantity up — edited as tier rows in the price spreadsheet, and a catalog's
+percentage adjustment can step by quantity too. The catalog's price column
+shows how many tiers a variant carries, with the ladder on hover and a note
+that fixed tiers set the price regardless of the percentage.
+
+A price list's prices can be exported and imported as CSV, one rung per row
+keyed by SKU, from the list's own page and from the catalog that owns it.
+The import merges: rows in the file are written, a blank price removes that
+rung, and rungs the file does not mention are left alone. The admin SDK's
+price, price list and import types carry the new fields, and the import
+create call accepts the price list to merge into.
diff --git a/packages/dashboard-core/src/api-client.ts b/packages/dashboard-core/src/api-client.ts
index d40b11bd11..e111e49e1f 100644
--- a/packages/dashboard-core/src/api-client.ts
+++ b/packages/dashboard-core/src/api-client.ts
@@ -290,6 +290,8 @@ export interface PanelImport {
original_filename?: string | null
original_byte_size?: number | null
original_file_url?: string | null
+ /** The list a `price_list_prices` import merges into; null elsewhere. */
+ price_list_id?: string | null
created_at?: string
updated_at?: string
}
@@ -322,6 +324,8 @@ export interface PanelImportCreateParams {
attachment: string
/** CSV column separator — the four both APIs accept. */
preferred_delimiter?: PanelImportDelimiter
+ /** The price list a `price_list_prices` import merges into. */
+ price_list_id?: string
results_url?: string
}
diff --git a/packages/dashboard-core/src/components/export-button.tsx b/packages/dashboard-core/src/components/export-button.tsx
index 122c88d0d1..b6c22ad5e5 100644
--- a/packages/dashboard-core/src/components/export-button.tsx
+++ b/packages/dashboard-core/src/components/export-button.tsx
@@ -36,6 +36,49 @@ interface ExportButtonProps extends ResourceActionsContext {
type Selection = 'filtered' | 'all'
+interface ExportRecordButtonProps {
+ /** Which dataset to export; see `ExportButton`. */
+ type: string
+ /** Ransack filter naming the records, as `search_params` on the export. */
+ searchParams: Record<string, unknown>
+ /** Label shown on the button. Defaults to the translated "Export" action. */
+ label?: string
+ /** Optional size for the button. Defaults to "sm". */
+ size?: 'sm' | 'default' | 'lg'
+}
+
+/**
+ * Export from a record's own page — one price list's prices, one promotion's
+ * coupon codes. The page has already decided what the file holds, so one
+ * click queues it; the filtered-or-all dialog is the table's concern.
+ */
+export function ExportRecordButton({ type, searchParams, label, size }: ExportRecordButtonProps) {
+ const { t } = useTranslation()
+ const exportMutation = useExport()
+
+ return (
+ <Button
+ type="button"
+ size={size ?? 'sm'}
+ variant="outline"
+ onClick={() =>
+ exportMutation.mutate({
+ type,
+ record_selection: 'filtered',
+ search_params: searchParams,
+ results_url: window.location.href,
+ })
+ }
+ disabled={exportMutation.isPending}
+ >
+ <DownloadIcon className="size-4" />
+ {exportMutation.isPending
+ ? t('admin.actions.exporting')
+ : (label ?? t('admin.actions.export'))}
+ </Button>
+ )
+}
+
export function ExportButton({
type,
label,
@@ -79,6 +122,7 @@ export function ExportButton({
the file is desk work, and the button is one of the things that
pushed the toolbar onto a third row on a phone. */}
<Button
+ type="button"
size="sm"
variant="outline"
className="hidden h-[2.125rem] lg:inline-flex"
diff --git a/packages/dashboard-core/src/components/import-button.tsx b/packages/dashboard-core/src/components/import-button.tsx
index c22ae557d9..2e466b505d 100644
--- a/packages/dashboard-core/src/components/import-button.tsx
+++ b/packages/dashboard-core/src/components/import-button.tsx
@@ -20,6 +20,7 @@ import { useState } from 'react'
import { useTranslation } from 'react-i18next'
import type { PanelImport } from '../api-client'
import {
+ type ImportCreateExtras,
useCreateImport,
useDownloadImportExample,
useDownloadImportTemplate,
@@ -59,6 +60,11 @@ interface ImportButtonProps {
variant?: 'default' | 'outline' | 'ghost'
/** Optional size for the button. Defaults to "sm". */
size?: 'sm' | 'default' | 'lg'
+ /**
+ * Whatever else the type needs at create — a parent record's id, say. The
+ * button then belongs on that record's page, and the sheet asks nothing.
+ */
+ params?: ImportCreateExtras
/**
* Path the import-done email links back to, relative to this panel's origin.
* Defaults to the operator dashboard's imports view under the current
@@ -80,6 +86,7 @@ export function ImportButton({
label,
variant,
size,
+ params,
resultsPath,
}: ImportButtonProps) {
const { t } = useTranslation()
@@ -105,7 +112,7 @@ export function ImportButton({
if (!file.signedId || createImport.isPending) return
createImport.mutate(
- { type, signedId: file.signedId, preferredDelimiter: delimiter, resultsPath },
+ { type, signedId: file.signedId, preferredDelimiter: delimiter, params, resultsPath },
{
onSuccess: (imp) => {
handleOpenChange(false)
@@ -154,6 +161,7 @@ export function ImportButton({
{/* Desktop only: the wizard needs a file from disk and column
mapping across a wide grid, neither of which works on a phone. */}
<Button
+ type="button"
size={size ?? 'sm'}
variant={variant ?? 'outline'}
className="hidden h-[2.125rem] lg:inline-flex"
diff --git a/packages/dashboard-core/src/components/import-wizard-dialog.tsx b/packages/dashboard-core/src/components/import-wizard-dialog.tsx
index bc910b41ce..29a50843ba 100644
--- a/packages/dashboard-core/src/components/import-wizard-dialog.tsx
+++ b/packages/dashboard-core/src/components/import-wizard-dialog.tsx
@@ -64,7 +64,7 @@ interface ImportWizardDialogProps {
* in the one it was written for. Omit it and the button is not rendered —
* the import is still complete, there is simply nowhere named to go.
*/
- onViewRecords?: (type: string | null) => void
+ onViewRecords?: (type: string | null, imp: PanelImport) => void
}
/**
@@ -80,7 +80,6 @@ export function ImportWizardDialog({ importId, onClose, onViewRecords }: ImportW
// Only the mapping step holds anything unsaved. Once the import is running
// the work is server-side, so closing then is safe and asking would nag.
const [mappingUnsaved, setMappingUnsaved] = useState(false)
-
async function requestClose() {
if (mappingUnsaved) {
const discard = await confirm({
@@ -136,7 +135,7 @@ function ImportWizard({
}: {
importId: string
onClose: () => void
- onViewRecords?: (type: string | null) => void
+ onViewRecords?: (type: string | null, imp: PanelImport) => void
/** Reports whether the mapping has edits the dialog should protect. */
onMappingDirtyChange?: (dirty: boolean) => void
}) {
@@ -320,7 +319,7 @@ function ImportWizard({
<Button
onClick={() => {
onClose()
- onViewRecords(imp.type)
+ onViewRecords(imp.type, imp)
}}
>
{t('admin.imports.results.view_records', { type: importTypeLabel(imp.type) })}
diff --git a/packages/dashboard-core/src/hooks/use-import.ts b/packages/dashboard-core/src/hooks/use-import.ts
index 594c5788ab..955e64b119 100644
--- a/packages/dashboard-core/src/hooks/use-import.ts
+++ b/packages/dashboard-core/src/hooks/use-import.ts
@@ -1,10 +1,17 @@
import { toastManager } from '@spree/dashboard-ui'
-import { useMutation, useQuery, useQueryClient } from '@tanstack/react-query'
-import { useEffect } from 'react'
+import {
+ type QueryClient,
+ type QueryKey,
+ useMutation,
+ useQuery,
+ useQueryClient,
+} from '@tanstack/react-query'
+import { useEffect, useRef } from 'react'
import {
getApiClient,
type PanelImport,
type PanelImportCompleteMappingParams,
+ type PanelImportCreateParams,
type PanelImportDelimiter,
} from '../api-client'
import { downloadFromApi } from '../lib/download'
@@ -25,13 +32,40 @@ const ROWS_POLL_INTERVAL_MS = 5000
//
// These are the operator dashboard's key names; a panel that names its lists
// differently adds its own through the client's `invalidateKeys`.
-const IMPORT_TOUCHED_RESOURCES = ['products', 'option-types', 'categories', 'customers', 'imports']
+// Everything an import type can write. `price-lists` itself stays out: a
+// list's own record does not change when its prices do, and refetching it
+// would reset the form under a merchant's unsaved edits.
+const IMPORT_TOUCHED_RESOURCES = [
+ 'products',
+ 'option-types',
+ 'categories',
+ 'customers',
+ 'imports',
+ 'prices',
+ 'catalogs',
+]
/** Whether the import's pipeline is still running (the poll's continue predicate). */
export function isImportActive(status: string | undefined): boolean {
return !!status && ACTIVE_STATUSES.has(status)
}
+/**
+ * Marks every cache an import can have written as stale. The pipeline writes
+ * records server-side, outside any tracked mutation, so nothing else ever
+ * does; called when an import finishes, and when its wizard is closed while
+ * it is still running (after which nothing is left to see it finish).
+ */
+export function invalidateImportTouchedResources(
+ queryClient: QueryClient,
+ buildKey: (resource: string) => QueryKey,
+) {
+ const extraKeys = getApiClient().imports?.invalidateKeys
+ for (const resource of new Set([...IMPORT_TOUCHED_RESOURCES, ...(extraKeys ?? [])])) {
+ queryClient.invalidateQueries({ queryKey: buildKey(resource) })
+ }
+}
+
/**
* The panel's import resource.
*
@@ -51,11 +85,22 @@ function imports() {
return resource
}
+/** Create-time parameters beyond the ones every import shares. */
+export type ImportCreateExtras = Omit<
+ PanelImportCreateParams,
+ 'type' | 'attachment' | 'preferred_delimiter' | 'results_url'
+>
+
export interface CreateImportInput {
type: string
/** Signed blob id of the already direct-uploaded CSV (see `FileUploadField`). */
signedId: string
preferredDelimiter?: PanelImportDelimiter
+ /**
+ * Whatever else the import type needs at create — the price list a
+ * `price_list_prices` import merges into, say. Passed through untouched.
+ */
+ params?: ImportCreateExtras
/**
* Where the import-done email should link back to. Defaults to this panel's
* own imports view under the current tenant.
@@ -75,9 +120,11 @@ export function useCreateImport() {
type,
signedId,
preferredDelimiter,
+ params,
resultsPath,
}: CreateImportInput): Promise<PanelImport> =>
imports().create({
+ ...params,
type,
attachment: signedId,
preferred_delimiter: preferredDelimiter,
@@ -117,13 +164,22 @@ export function useImport(id: string) {
// already-finished import refires it; harmless, invalidation is idempotent.
const status = query.data?.status
const finished = status === 'completed' || status === 'failed'
- const extraKeys = getApiClient().imports?.invalidateKeys
useEffect(() => {
- if (!finished) return
- for (const resource of new Set([...IMPORT_TOUCHED_RESOURCES, ...(extraKeys ?? [])])) {
- queryClient.invalidateQueries({ queryKey: buildKey(resource) })
- }
- }, [finished, queryClient, buildKey, extraKeys])
+ if (finished) invalidateImportTouchedResources(queryClient, buildKey)
+ }, [finished, queryClient, buildKey])
+
+ // Unmounted while the import is still running — the wizard closed, or the
+ // merchant navigated away — nothing is left to see it finish, so the caches
+ // it will have written are marked stale now. An import the poll has not
+ // answered for yet counts as running: nothing says it is finished.
+ const unfinished = useRef(true)
+ unfinished.current = !finished
+ useEffect(
+ () => () => {
+ if (unfinished.current) invalidateImportTouchedResources(queryClient, buildKey)
+ },
+ [queryClient, buildKey],
+ )
return query
}
diff --git a/packages/dashboard-core/src/lib/sample-csv.ts b/packages/dashboard-core/src/lib/sample-csv.ts
index 470dfd5eef..1e9511c9a3 100644
--- a/packages/dashboard-core/src/lib/sample-csv.ts
+++ b/packages/dashboard-core/src/lib/sample-csv.ts
@@ -8,7 +8,12 @@
* the installed Spree version. A type missing from this list simply hides the link;
* the endpoint is the authority and 404s for anything it has no example for.
*/
-const TYPES_WITH_SAMPLE_CSV = new Set(['products', 'customers', 'product_translations'])
+const TYPES_WITH_SAMPLE_CSV = new Set([
+ 'products',
+ 'customers',
+ 'product_translations',
+ 'price_list_prices',
+])
/** Whether an import type has an example CSV to offer. */
export function hasSampleCsv(type: string): boolean {
diff --git a/packages/dashboard-core/src/locales/ar.json b/packages/dashboard-core/src/locales/ar.json
index e49f174b44..f3a96f79a7 100644
--- a/packages/dashboard-core/src/locales/ar.json
+++ b/packages/dashboard-core/src/locales/ar.json
@@ -922,6 +922,7 @@
"try_again": "حاول مرة أخرى",
"types": {
"customers": "العملاء",
+ "price_list_prices": "أسعار قائمة الأسعار",
"product_translations": "ترجمات المنتجات",
"products": "المنتجات"
},
diff --git a/packages/dashboard-core/src/locales/de.json b/packages/dashboard-core/src/locales/de.json
index 2a210edc66..4c8a737c40 100644
--- a/packages/dashboard-core/src/locales/de.json
+++ b/packages/dashboard-core/src/locales/de.json
@@ -922,6 +922,7 @@
"try_again": "Erneut versuchen",
"types": {
"customers": "Kunden",
+ "price_list_prices": "Preislistenpreise",
"product_translations": "Produktübersetzungen",
"products": "Produkte"
},
diff --git a/packages/dashboard-core/src/locales/en.json b/packages/dashboard-core/src/locales/en.json
index 2aaaf76c4c..48402988d7 100644
--- a/packages/dashboard-core/src/locales/en.json
+++ b/packages/dashboard-core/src/locales/en.json
@@ -924,6 +924,7 @@
"try_again": "Try again",
"types": {
"customers": "Customers",
+ "price_list_prices": "Price list prices",
"product_translations": "Product translations",
"products": "Products"
},
diff --git a/packages/dashboard-core/src/locales/fr.json b/packages/dashboard-core/src/locales/fr.json
index b8bde036ef..dc1b19ec66 100644
--- a/packages/dashboard-core/src/locales/fr.json
+++ b/packages/dashboard-core/src/locales/fr.json
@@ -922,6 +922,7 @@
"try_again": "Réessayer",
"types": {
"customers": "Clients",
+ "price_list_prices": "Prix des listes de prix",
"product_translations": "Traductions de produits",
"products": "Produits"
},
diff --git a/packages/dashboard-core/src/locales/pl.json b/packages/dashboard-core/src/locales/pl.json
index 9a92facda2..2dc31d3196 100644
--- a/packages/dashboard-core/src/locales/pl.json
+++ b/packages/dashboard-core/src/locales/pl.json
@@ -923,6 +923,7 @@
"try_again": "Spróbuj ponownie",
"types": {
"customers": "Klienci",
+ "price_list_prices": "Ceny cennika",
"product_translations": "Tłumaczenia produktów",
"products": "Produkty"
},
diff --git a/packages/dashboard-core/src/locales/zh-CN.json b/packages/dashboard-core/src/locales/zh-CN.json
index 914e876d2d..4f30f4eb1e 100644
--- a/packages/dashboard-core/src/locales/zh-CN.json
+++ b/packages/dashboard-core/src/locales/zh-CN.json
@@ -922,6 +922,7 @@
"try_again": "重试",
"types": {
"customers": "客户",
+ "price_list_prices": "价目表价格",
"product_translations": "产品翻译",
"products": "产品"
},
diff --git a/packages/dashboard/src/components/spree/catalog-price-columns.tsx b/packages/dashboard/src/components/spree/catalog-price-columns.tsx
index 526fe6aef6..81341331f8 100644
--- a/packages/dashboard/src/components/spree/catalog-price-columns.tsx
+++ b/packages/dashboard/src/components/spree/catalog-price-columns.tsx
@@ -145,6 +145,13 @@ function TierBadge({ price }: { price: CatalogPrice }) {
))}
</tbody>
</table>
+ {/* A ladder fixes the price: the catalog's percentage adjustment is
+ never applied on top of an explicit row, and this is where a
+ merchant who set both would otherwise expect to see it
+ (docs/plans/6.0-volume-pricing.md). */}
+ <p className="mt-1.5 max-w-56 text-muted-foreground text-xs">
+ {i18n.t('admin.catalogs.prices.tier_fixed_note')}
+ </p>
</TooltipContent>
</Tooltip>
)
diff --git a/packages/dashboard/src/components/spree/catalog-pricing-fields.tsx b/packages/dashboard/src/components/spree/catalog-pricing-fields.tsx
index afed0b82fa..564ad8a81e 100644
--- a/packages/dashboard/src/components/spree/catalog-pricing-fields.tsx
+++ b/packages/dashboard/src/components/spree/catalog-pricing-fields.tsx
@@ -1,4 +1,5 @@
import type { PriceList } from '@spree/admin-sdk'
+import type { PanelImport } from '@spree/dashboard-core'
import {
Alert,
AlertDescription,
@@ -32,6 +33,7 @@ import {
} from '../../schemas/catalog'
import { ADJUSTMENT_DIRECTIONS, MAXIMUM_QUANTITY_TIERS } from '../../schemas/price-list'
import { BulkPriceEditorDialog } from './bulk-price-editor/bulk-price-editor-dialog'
+import { PriceListCsvButtons } from './price-list-csv-buttons'
/**
* How the agreement prices, edited on the catalog itself: the catalog and the
@@ -51,6 +53,7 @@ export function CatalogPricingFields({
hasStagedProducts,
priceEditorOpen: controlledOpen,
onPriceEditorOpenChange,
+ onImportCreated,
}: {
form: UseFormReturn<CatalogFormValues>
canEdit: boolean
@@ -60,6 +63,12 @@ export function CatalogPricingFields({
* does not exist until Save.
*/
priceList?: PriceList | null
+ /**
+ * When supplied, the list's prices can be exported and imported as CSV
+ * from here; a created import is handed back so the page can open the
+ * wizard for it.
+ */
+ onImportCreated?: (imp: PanelImport) => void
/** The mode as last saved, so a switch can be warned about before Save. */
savedMode?: CatalogPricingMode
/**
@@ -269,15 +278,26 @@ export function CatalogPricingFields({
{mode === 'fixed' &&
(priceList ? (
<div>
- <Button
- type="button"
- size="sm"
- disabled={!canEdit}
- onClick={() => setPriceEditorOpen(true)}
- >
- <TableIcon className="size-4" />
- {t('admin.catalogs.edit_prices_cta')}
- </Button>
+ <div className="flex flex-wrap gap-2">
+ <Button
+ type="button"
+ size="sm"
+ disabled={!canEdit}
+ onClick={() => setPriceEditorOpen(true)}
+ >
+ <TableIcon className="size-4" />
+ {t('admin.catalogs.edit_prices_cta')}
+ </Button>
+ {/* Export needs only read access; the import button gates
+ itself on create. */}
+ {onImportCreated && (
+ <PriceListCsvButtons
+ priceList={priceList}
+ onImportCreated={onImportCreated}
+ size="sm"
+ />
+ )}
+ </div>
<FieldDescription className="mt-4">
{t(
hasStagedProducts
diff --git a/packages/dashboard/src/components/spree/imports/import-wizard-dialog.tsx b/packages/dashboard/src/components/spree/imports/import-wizard-dialog.tsx
index 7f36de924e..af70c48746 100644
--- a/packages/dashboard/src/components/spree/imports/import-wizard-dialog.tsx
+++ b/packages/dashboard/src/components/spree/imports/import-wizard-dialog.tsx
@@ -1,6 +1,6 @@
import { ImportWizardDialog as SharedImportWizardDialog } from '@spree/dashboard-core'
import { useNavigate } from '@tanstack/react-router'
-import { importTypeIndexPath } from '../../../lib/import-types'
+import { importTypeDestination } from '../../../lib/import-types'
interface ImportWizardDialogProps {
/** Prefixed id of the import to drive; `null` keeps the dialog closed. */
@@ -23,7 +23,13 @@ export function ImportWizardDialog({ importId, onClose }: ImportWizardDialogProp
<SharedImportWizardDialog
importId={importId}
onClose={onClose}
- onViewRecords={(type) => navigate({ to: importTypeIndexPath(type) })}
+ onViewRecords={(type, imp) => {
+ const { to, params } = importTypeDestination(type, imp)
+ navigate({
+ to,
+ params: (prev: Record<string, string>) => ({ ...prev, ...params }),
+ } as never)
+ }}
/>
)
}
diff --git a/packages/dashboard/src/components/spree/imports/import-wizard-search.ts b/packages/dashboard/src/components/spree/imports/import-wizard-search.ts
new file mode 100644
index 0000000000..8c349e6c64
--- /dev/null
+++ b/packages/dashboard/src/components/spree/imports/import-wizard-search.ts
@@ -0,0 +1,38 @@
+import { useNavigate } from '@tanstack/react-router'
+import { z } from 'zod'
+
+/**
+ * `?import=<prefixed id>` names the import whose wizard is open over a page —
+ * deep-linkable and refresh-safe. Add the schema to a route's `validateSearch`
+ * and drive the dialog from the hook.
+ */
+// Loose, so a route that uses the schema on its own keeps whatever other
+// search params it carries; `z.object()` would strip them before `open` and
+// `close` ever see `prev`.
+export const importWizardSearchSchema = z.looseObject({
+ import: z.string().optional(),
+})
+
+/**
+ * The wizard's open/closed state as the URL holds it: `importId` is the
+ * import to show (or null), `open` writes an id into the search params and
+ * `close` removes it, both preserving the page's other params.
+ *
+ * @param search the route's validated search params
+ */
+export function useImportWizardSearch(search: { import?: string }) {
+ const navigate = useNavigate()
+
+ return {
+ importId: search.import ?? null,
+ open: (id: string) =>
+ navigate({ search: (prev: Record<string, unknown>) => ({ ...prev, import: id }) as never }),
+ close: () =>
+ navigate({
+ search: (prev: Record<string, unknown>) => {
+ const { import: _i, ...rest } = prev
+ return rest as never
+ },
+ }),
+ }
+}
diff --git a/packages/dashboard/src/components/spree/price-list-csv-buttons.tsx b/packages/dashboard/src/components/spree/price-list-csv-buttons.tsx
new file mode 100644
index 0000000000..9ed34cadb7
--- /dev/null
+++ b/packages/dashboard/src/components/spree/price-list-csv-buttons.tsx
@@ -0,0 +1,39 @@
+import type { PriceList } from '@spree/admin-sdk'
+import { ExportRecordButton, ImportButton, type PanelImport, Subject } from '@spree/dashboard-core'
+
+/**
+ * Export and import of one price list's prices as CSV, one rung per row. Sits
+ * next to "Edit prices" wherever a list is edited — its own page and the
+ * catalog that owns it — so a merchant working an agreement never leaves it
+ * to move its figures in bulk (docs/plans/6.0-volume-pricing.md).
+ *
+ * The export is fixed to this list, and the import is bound to it before the
+ * sheet opens: the file never names a list, so neither does the merchant.
+ */
+export function PriceListCsvButtons({
+ priceList,
+ onImportCreated,
+ size,
+}: {
+ priceList: PriceList
+ /** Receives the created import so the page can open the wizard for it. */
+ onImportCreated: (imp: PanelImport) => void
+ size?: 'sm' | 'default'
+}) {
+ return (
+ <>
+ <ImportButton
+ type="price_list_prices"
+ subject={Subject.PriceList}
+ params={{ price_list_id: priceList.id }}
+ onCreated={onImportCreated}
+ size={size}
+ />
+ <ExportRecordButton
+ type="price_list_prices"
+ searchParams={{ price_list_id_eq: priceList.id }}
+ size={size}
+ />
+ </>
+ )
+}
diff --git a/packages/dashboard/src/components/spree/price-list-editors/price-list-form.tsx b/packages/dashboard/src/components/spree/price-list-editors/price-list-form.tsx
index 1d3c00e009..c4b5ff1020 100644
--- a/packages/dashboard/src/components/spree/price-list-editors/price-list-form.tsx
+++ b/packages/dashboard/src/components/spree/price-list-editors/price-list-form.tsx
@@ -5,6 +5,7 @@ import {
Can,
formatStoreDateTime,
PageHeader,
+ type PanelImport,
PreferencesForm,
typeDescription,
typeLabel,
@@ -28,6 +29,7 @@ import { useTranslation } from 'react-i18next'
import { spreeJsonLinkResolver } from '../../../lib/json-link-resolver'
import { BulkPriceEditorDialog } from '../bulk-price-editor/bulk-price-editor-dialog'
import { DeferredProductMembershipCard } from '../deferred-product-membership-card'
+import { PriceListCsvButtons } from '../price-list-csv-buttons'
import {
flushProductMembership,
ProductMembershipStagingProvider,
@@ -106,6 +108,12 @@ interface PriceListFormProps {
onSubmit: (payload: ReturnType<typeof priceListValuesToParams>) => Promise<void>
/** Edit-mode only: when supplied, the header gains a Delete button. */
onDelete?: () => void
+ /**
+ * Edit-mode only: when supplied, the header gains CSV export and import of
+ * the list's prices, and a created import is handed here so the page can
+ * open the wizard for it.
+ */
+ onImportCreated?: (imp: PanelImport) => void
deletePending?: boolean
}
@@ -119,6 +127,7 @@ export function PriceListForm({
initialRules,
onSubmit,
onDelete,
+ onImportCreated,
deletePending = false,
}: PriceListFormProps) {
const { t } = useTranslation()
@@ -234,6 +243,15 @@ export function PriceListForm({
{mode === 'edit' && priceList && canEdit && (
<EditPricesButton priceList={priceList} />
)}
+ {/* Export needs only read access; the import button gates
+ itself on create. */}
+ {mode === 'edit' && priceList && onImportCreated && (
+ <PriceListCsvButtons
+ priceList={priceList}
+ onImportCreated={onImportCreated}
+ size="default"
+ />
+ )}
{mode === 'edit' && priceList && <ActivationButtons priceList={priceList} />}
<Button
type="submit"
diff --git a/packages/dashboard/src/components/spree/promotion-editors/promotion-form.tsx b/packages/dashboard/src/components/spree/promotion-editors/promotion-form.tsx
index 0546f890b3..5bc8836a8e 100644
--- a/packages/dashboard/src/components/spree/promotion-editors/promotion-form.tsx
+++ b/packages/dashboard/src/components/spree/promotion-editors/promotion-form.tsx
@@ -10,7 +10,7 @@ import type {
} from '@spree/admin-sdk'
import { Can, PageHeader, PreferencesForm, StoreDatePicker } from '@spree/dashboard-core'
import { DropdownMenuItem, formatCalculatorSummary, useConfirm } from '@spree/dashboard-ui'
-import { DownloadIcon, PlusIcon, SparklesIcon, TrashIcon } from '@spree/dashboard-ui/icons'
+import { PlusIcon, SparklesIcon, TrashIcon } from '@spree/dashboard-ui/icons'
import i18n from 'i18next'
import { useEffect, useState } from 'react'
import { Controller, type UseFormReturn, useFieldArray, useForm } from 'react-hook-form'
@@ -20,12 +20,12 @@ import { EditorShell } from './editor-shell'
import './register'
import {
adminClient,
+ ExportRecordButton,
mapSpreeErrorsToForm,
Slot,
Subject,
typeDescription,
typeLabel,
- useExport,
usePermissions,
useStore,
} from '@spree/dashboard-core'
@@ -1390,15 +1390,6 @@ function CouponCodesSheet({
const totalCount = codesData?.meta?.count ?? codes.length
const totalPages = codesData?.meta?.pages ?? 1
- const exportMutation = useExport()
- function handleExport() {
- exportMutation.mutate({
- type: 'coupon_codes',
- record_selection: 'filtered',
- search_params: { promotion_id_eq: promotionId },
- })
- }
-
return (
<Sheet open={open} onOpenChange={onOpenChange}>
<SheetContent className="sm:max-w-xl">
@@ -1483,17 +1474,12 @@ function CouponCodesSheet({
<SheetFooter>
{totalCount > 0 && (
- <Button
- type="button"
- variant="outline"
- onClick={handleExport}
- disabled={exportMutation.isPending}
- >
- <DownloadIcon className="size-4" />
- {exportMutation.isPending
- ? t('admin.actions.exporting')
- : t('admin.promotions.coupon_codes.export_csv')}
- </Button>
+ <ExportRecordButton
+ type="coupon_codes"
+ searchParams={{ promotion_id_eq: promotionId }}
+ label={t('admin.promotions.coupon_codes.export_csv')}
+ size="default"
+ />
)}
<Button type="button" variant="outline" onClick={() => onOpenChange(false)}>
{t('admin.actions.close')}
diff --git a/packages/dashboard/src/lib/import-types.test.ts b/packages/dashboard/src/lib/import-types.test.ts
index 916efab2f5..2935364376 100644
--- a/packages/dashboard/src/lib/import-types.test.ts
+++ b/packages/dashboard/src/lib/import-types.test.ts
@@ -1,5 +1,5 @@
import { describe, expect, it } from 'vitest'
-import { importTypeIndexPath, importTypeKey, isImportActive } from './import-types'
+import { importTypeDestination, importTypeKey, isImportActive } from './import-types'
describe('importTypeKey', () => {
it('passes the API shorthand through unchanged', () => {
@@ -21,16 +21,30 @@ describe('importTypeKey', () => {
})
})
-describe('importTypeIndexPath', () => {
+describe('importTypeDestination', () => {
it('routes customers imports to the customers index', () => {
- expect(importTypeIndexPath('customers')).toBe('/$storeId/customers')
- expect(importTypeIndexPath('Spree::Imports::Customers')).toBe('/$storeId/customers')
+ expect(importTypeDestination('customers')).toEqual({ to: '/$storeId/customers' })
+ expect(importTypeDestination('Spree::Imports::Customers')).toEqual({
+ to: '/$storeId/customers',
+ })
})
it('routes product-ish imports to the products index', () => {
- expect(importTypeIndexPath('products')).toBe('/$storeId/products')
- expect(importTypeIndexPath('product_translations')).toBe('/$storeId/products')
- expect(importTypeIndexPath('Spree::Imports::Products')).toBe('/$storeId/products')
+ expect(importTypeDestination('products')).toEqual({ to: '/$storeId/products' })
+ expect(importTypeDestination('product_translations')).toEqual({ to: '/$storeId/products' })
+ expect(importTypeDestination('Spree::Imports::Products')).toEqual({ to: '/$storeId/products' })
+ })
+
+ // The rows a price-list import wrote live on one list, so that list's page
+ // is where "View records" goes; without the id, the lists index.
+ it('routes a price-list import to the list it wrote into', () => {
+ expect(importTypeDestination('price_list_prices', { price_list_id: 'pl_1' } as never)).toEqual({
+ to: '/$storeId/products/price-lists/$priceListId',
+ params: { priceListId: 'pl_1' },
+ })
+ expect(importTypeDestination('price_list_prices')).toEqual({
+ to: '/$storeId/products/price-lists',
+ })
})
})
diff --git a/packages/dashboard/src/lib/import-types.ts b/packages/dashboard/src/lib/import-types.ts
index 64395f7b45..903561272e 100644
--- a/packages/dashboard/src/lib/import-types.ts
+++ b/packages/dashboard/src/lib/import-types.ts
@@ -1,18 +1,30 @@
-import { importTypeKey } from '@spree/dashboard-core'
+import { importTypeKey, type PanelImport } from '@spree/dashboard-core'
export { importTypeKey, importTypeLabel, isImportActive } from '@spree/dashboard-core'
/**
- * Resource index the "Done" action points to after a finished import.
+ * Where "View records" goes after a finished import.
*
- * Stays in the app rather than the framework: the route it names belongs to
+ * Stays in the app rather than the framework: the routes it names belong to
* this dashboard's own tree, and the seller panel files its catalog elsewhere.
+ * A price-list import points at the list it wrote into rather than an index,
+ * since the rows it produced live nowhere else.
*/
-export function importTypeIndexPath(type: string | null): string {
+export function importTypeDestination(
+ type: string | null,
+ imp?: PanelImport,
+): { to: string; params?: Record<string, string> } {
switch (importTypeKey(type)) {
case 'customers':
- return '/$storeId/customers'
+ return { to: '/$storeId/customers' }
+ case 'price_list_prices':
+ return imp?.price_list_id
+ ? {
+ to: '/$storeId/products/price-lists/$priceListId',
+ params: { priceListId: imp.price_list_id },
+ }
+ : { to: '/$storeId/products/price-lists' }
default:
- return '/$storeId/products'
+ return { to: '/$storeId/products' }
}
}
diff --git a/packages/dashboard/src/locales/ar.json b/packages/dashboard/src/locales/ar.json
index 020f0c8f19..e1776fa6af 100644
--- a/packages/dashboard/src/locales/ar.json
+++ b/packages/dashboard/src/locales/ar.json
@@ -162,6 +162,7 @@
},
"tier_count_one": "+{{count}} مستوى",
"tier_count_other": "+{{count}} مستويات",
+ "tier_fixed_note": "لا تنطبق نسبة تعديل الكتالوج هنا. هذه المستويات تحدد السعر.",
"tier_from_one": "من {{count}}",
"tier_from_other": "من {{count}}",
"tier_preview": "ما تحتسبه هذه الاتفاقية",
diff --git a/packages/dashboard/src/locales/de.json b/packages/dashboard/src/locales/de.json
index 8ae97f0322..951fa9ef73 100644
--- a/packages/dashboard/src/locales/de.json
+++ b/packages/dashboard/src/locales/de.json
@@ -162,6 +162,7 @@
},
"tier_count_one": "+{{count}} Stufe",
"tier_count_other": "+{{count}} Stufen",
+ "tier_fixed_note": "Die prozentuale Anpassung des Katalogs gilt hier nicht. Diese Staffeln legen den Preis fest.",
"tier_from_one": "Ab {{count}}",
"tier_from_other": "Ab {{count}}",
"tier_preview": "Was diese Vereinbarung berechnet",
diff --git a/packages/dashboard/src/locales/en.json b/packages/dashboard/src/locales/en.json
index 338ed96b97..7aeb927a65 100644
--- a/packages/dashboard/src/locales/en.json
+++ b/packages/dashboard/src/locales/en.json
@@ -162,6 +162,7 @@
},
"tier_count_one": "+{{count}} tier",
"tier_count_other": "+{{count}} tiers",
+ "tier_fixed_note": "The catalog's percentage adjustment does not apply here. These tiers fix the price.",
"tier_from_one": "From {{count}}",
"tier_from_other": "From {{count}}",
"tier_preview": "What this agreement charges",
diff --git a/packages/dashboard/src/locales/fr.json b/packages/dashboard/src/locales/fr.json
index a4c32453cb..0025200cca 100644
--- a/packages/dashboard/src/locales/fr.json
+++ b/packages/dashboard/src/locales/fr.json
@@ -162,6 +162,7 @@
},
"tier_count_one": "+{{count}} palier",
"tier_count_other": "+{{count}} paliers",
+ "tier_fixed_note": "L'ajustement en pourcentage du catalogue ne s'applique pas ici. Ces paliers fixent le prix.",
"tier_from_one": "Dès {{count}}",
"tier_from_other": "Dès {{count}}",
"tier_preview": "Ce que facture cet accord",
diff --git a/packages/dashboard/src/locales/pl.json b/packages/dashboard/src/locales/pl.json
index d3a89660b9..3697147f68 100644
--- a/packages/dashboard/src/locales/pl.json
+++ b/packages/dashboard/src/locales/pl.json
@@ -166,6 +166,7 @@
"tier_count_many": "+{{count}} progów",
"tier_count_one": "+{{count}} próg",
"tier_count_other": "+{{count}} progów",
+ "tier_fixed_note": "Procentowa korekta katalogu nie ma tu zastosowania. Te progi ustalają cenę.",
"tier_from_few": "Od {{count}}",
"tier_from_many": "Od {{count}}",
"tier_from_one": "Od {{count}}",
diff --git a/packages/dashboard/src/locales/zh-CN.json b/packages/dashboard/src/locales/zh-CN.json
index d579595b2e..dc364f863a 100644
--- a/packages/dashboard/src/locales/zh-CN.json
+++ b/packages/dashboard/src/locales/zh-CN.json
@@ -162,6 +162,7 @@
},
"tier_count_one": "+{{count}} 档",
"tier_count_other": "+{{count}} 档",
+ "tier_fixed_note": "目录的百分比调整不适用于此处。这些阶梯固定了价格。",
"tier_from_one": "满 {{count}}",
"tier_from_other": "满 {{count}}",
"tier_preview": "此协议的计价",
diff --git a/packages/dashboard/src/routes/_authenticated/$storeId/customers/index.tsx b/packages/dashboard/src/routes/_authenticated/$storeId/customers/index.tsx
index 31899ff636..a7203e87c8 100644
--- a/packages/dashboard/src/routes/_authenticated/$storeId/customers/index.tsx
+++ b/packages/dashboard/src/routes/_authenticated/$storeId/customers/index.tsx
@@ -39,6 +39,10 @@ import { Controller, useForm } from 'react-hook-form'
import { useTranslation } from 'react-i18next'
import { z } from 'zod/v4'
import { ImportWizardDialog } from '../../../../components/spree/imports/import-wizard-dialog'
+import {
+ importWizardSearchSchema,
+ useImportWizardSearch,
+} from '../../../../components/spree/imports/import-wizard-search'
import {
customerGroupAutocompleteProps,
useCustomerGroups,
@@ -61,7 +65,7 @@ import '../../../../tables/customers'
// carries the prefixed id of the import wizard dialog open over the table.
const customersSearchSchema = resourceSearchSchema.extend({
new: z.coerce.boolean().optional(),
- import: z.string().optional(),
+ ...importWizardSearchSchema.shape,
})
export const Route = createFileRoute('/_authenticated/$storeId/customers/')({
@@ -189,18 +193,7 @@ function CustomersPage() {
})
}
- function openImportWizard(id: string) {
- navigate({ search: (prev: Record<string, unknown>) => ({ ...prev, import: id }) as never })
- }
-
- function closeImportWizard() {
- navigate({
- search: (prev: Record<string, unknown>) => {
- const { import: _i, ...rest } = prev
- return rest as never
- },
- })
- }
+ const wizard = useImportWizardSearch(search)
return (
<>
@@ -222,7 +215,7 @@ function CustomersPage() {
<ImportButton
type="customers"
subject={Subject.Customer}
- onCreated={(imp) => openImportWizard(imp.id)}
+ onCreated={(imp) => wizard.open(imp.id)}
/>
<ExportButton type="customers" {...ctx} />
<Button size="sm" className="h-[2.125rem]" onClick={openCreate}>
@@ -233,7 +226,7 @@ function CustomersPage() {
)}
/>
{isCreating && <NewCustomerSheet open onOpenChange={(o) => !o && closeSheet()} />}
- <ImportWizardDialog importId={search.import ?? null} onClose={closeImportWizard} />
+ <ImportWizardDialog importId={wizard.importId} onClose={wizard.close} />
</>
)
}
diff --git a/packages/dashboard/src/routes/_authenticated/$storeId/products/catalogs/$catalogId.tsx b/packages/dashboard/src/routes/_authenticated/$storeId/products/catalogs/$catalogId.tsx
index acd84907e3..d922081e01 100644
--- a/packages/dashboard/src/routes/_authenticated/$storeId/products/catalogs/$catalogId.tsx
+++ b/packages/dashboard/src/routes/_authenticated/$storeId/products/catalogs/$catalogId.tsx
@@ -1,5 +1,6 @@
import { zodResolver } from '@hookform/resolvers/zod'
import type { Catalog } from '@spree/admin-sdk'
+import type { PanelImport } from '@spree/dashboard-core'
import {
adminClient,
mapSpreeErrorsToForm,
@@ -45,6 +46,11 @@ import {
termsToFormValues,
} from '../../../../../components/spree/catalog-terms-card'
import { DeferredProductMembershipCard } from '../../../../../components/spree/deferred-product-membership-card'
+import { ImportWizardDialog } from '../../../../../components/spree/imports/import-wizard-dialog'
+import {
+ importWizardSearchSchema,
+ useImportWizardSearch,
+} from '../../../../../components/spree/imports/import-wizard-search'
import {
ProductMembershipStagingProvider,
useProductMembershipStaging,
@@ -72,6 +78,7 @@ import {
/** One catalog: its assortment, pricing and the audiences that see it. */
export const Route = createFileRoute('/_authenticated/$storeId/products/catalogs/$catalogId')({
+ validateSearch: importWizardSearchSchema,
component: CatalogDetailPage,
})
@@ -106,6 +113,7 @@ function CatalogBody({ catalog }: { catalog: Catalog }) {
const navigate = useNavigate()
const { permissions } = usePermissions()
const deleteMutation = useDeleteCatalog()
+ const wizard = useImportWizardSearch(Route.useSearch())
const saveMutation = useSaveCatalog(catalog.id)
const { data: productTermsData } = useCatalogProductTerms(catalog.id)
const productTerms = useMemo(() => productTermsData?.data ?? [], [productTermsData])
@@ -362,6 +370,7 @@ function CatalogBody({ catalog }: { catalog: Catalog }) {
canEdit={canEdit}
priceEditorOpen={priceEditorOpen}
onPriceEditorOpenChange={setPriceEditorOpen}
+ onImportCreated={(imp) => wizard.open(imp.id)}
/>
<CatalogTermsCard form={form} canEdit={canEdit} />
<CatalogAudienceCard form={form} canEdit={canEdit} />
@@ -369,6 +378,7 @@ function CatalogBody({ catalog }: { catalog: Catalog }) {
}
/>
</form>
+ <ImportWizardDialog importId={wizard.importId} onClose={wizard.close} />
</ProductMembershipStagingProvider>
)
}
@@ -384,12 +394,14 @@ function CatalogPricingCard({
canEdit,
priceEditorOpen,
onPriceEditorOpenChange,
+ onImportCreated,
}: {
catalog: Catalog
form: UseFormReturn<CatalogFormValues>
canEdit: boolean
priceEditorOpen: boolean
onPriceEditorOpenChange: (open: boolean) => void
+ onImportCreated: (imp: PanelImport) => void
}) {
const { t } = useTranslation()
// A product staged for removal still has its prices on the list until
@@ -412,6 +424,7 @@ function CatalogPricingCard({
hasStagedProducts={stagedProducts}
priceEditorOpen={priceEditorOpen}
onPriceEditorOpenChange={onPriceEditorOpenChange}
+ onImportCreated={onImportCreated}
/>
</FieldGroup>
</CardContent>
diff --git a/packages/dashboard/src/routes/_authenticated/$storeId/products/index.tsx b/packages/dashboard/src/routes/_authenticated/$storeId/products/index.tsx
index c07fef36bf..a9c324bcfb 100644
--- a/packages/dashboard/src/routes/_authenticated/$storeId/products/index.tsx
+++ b/packages/dashboard/src/routes/_authenticated/$storeId/products/index.tsx
@@ -38,8 +38,12 @@ import {
import { createFileRoute, useNavigate } from '@tanstack/react-router'
import { useCallback, useMemo, useState } from 'react'
import { useTranslation } from 'react-i18next'
-import { z } from 'zod/v4'
+import type { z } from 'zod/v4'
import { ImportWizardDialog } from '../../../../components/spree/imports/import-wizard-dialog'
+import {
+ importWizardSearchSchema,
+ useImportWizardSearch,
+} from '../../../../components/spree/imports/import-wizard-search'
import { categoryAutocompleteProps, useCategories } from '../../../../hooks/use-categories'
import { channelAutocompleteProps, useChannels } from '../../../../hooks/use-channels'
import { collectionAutocompleteProps, useCollections } from '../../../../hooks/use-collections'
@@ -62,9 +66,7 @@ import { toastManager } from '@spree/dashboard-ui'
// `import` carries the prefixed id of the import whose wizard dialog is open
// over the table — deep-linkable and refresh-safe.
-const productsSearchSchema = resourceSearchSchema.extend({
- import: z.string().optional(),
-})
+const productsSearchSchema = resourceSearchSchema.extend(importWizardSearchSchema.shape)
// Custom field type → filter operator set. Anything unmapped filters as text.
// Narrowed to the variants that need no companion field (`enum` needs
@@ -92,16 +94,7 @@ function ProductsPage() {
const searchParams = Route.useSearch() as z.infer<typeof productsSearchSchema>
const navigate = useNavigate()
- const openImportWizard = (id: string) =>
- navigate({ search: (prev: Record<string, unknown>) => ({ ...prev, import: id }) as never })
-
- const closeImportWizard = () =>
- navigate({
- search: (prev: Record<string, unknown>) => {
- const { import: _i, ...rest } = prev
- return rest as never
- },
- })
+ const wizard = useImportWizardSearch(searchParams)
const bulkStatus = useBulkProductStatusUpdate()
const bulkAddCategories = useBulkAddProductsToCategories()
@@ -376,7 +369,7 @@ function ProductsPage() {
<ImportButton
type="products"
subject={Subject.Product}
- onCreated={(imp) => openImportWizard(imp.id)}
+ onCreated={(imp) => wizard.open(imp.id)}
/>
<ExportButton type="products" {...ctx} />
<Button
@@ -390,7 +383,7 @@ function ProductsPage() {
</>
)}
/>
- <ImportWizardDialog importId={searchParams.import ?? null} onClose={closeImportWizard} />
+ <ImportWizardDialog importId={wizard.importId} onClose={wizard.close} />
</>
)
}
diff --git a/packages/dashboard/src/routes/_authenticated/$storeId/products/price-lists/$priceListId/index.tsx b/packages/dashboard/src/routes/_authenticated/$storeId/products/price-lists/$priceListId/index.tsx
index d98d49d3bd..cfd15c4e81 100644
--- a/packages/dashboard/src/routes/_authenticated/$storeId/products/price-lists/$priceListId/index.tsx
+++ b/packages/dashboard/src/routes/_authenticated/$storeId/products/price-lists/$priceListId/index.tsx
@@ -1,6 +1,13 @@
+import { useResourceKeyBuilder } from '@spree/dashboard-core'
import { toastManager, useConfirm } from '@spree/dashboard-ui'
+import { useQueryClient } from '@tanstack/react-query'
import { createFileRoute, useNavigate } from '@tanstack/react-router'
import { useTranslation } from 'react-i18next'
+import { ImportWizardDialog } from '../../../../../../components/spree/imports/import-wizard-dialog'
+import {
+ importWizardSearchSchema,
+ useImportWizardSearch,
+} from '../../../../../../components/spree/imports/import-wizard-search'
import { PriceListForm } from '../../../../../../components/spree/price-list-editors/price-list-form'
import {
useDeletePriceList,
@@ -10,6 +17,7 @@ import {
export const Route = createFileRoute('/_authenticated/$storeId/products/price-lists/$priceListId/')(
{
+ validateSearch: importWizardSearchSchema,
component: EditPriceListPage,
},
)
@@ -18,6 +26,17 @@ function EditPriceListPage() {
const { t } = useTranslation()
const { storeId, priceListId } = Route.useParams()
const navigate = useNavigate()
+ const queryClient = useQueryClient()
+ const buildKey = useResourceKeyBuilder()
+ const wizard = useImportWizardSearch(Route.useSearch())
+
+ // The products card reads prices too. It is the one key the wizard leaves
+ // alone on completion, since refetching the list itself would reset the
+ // form under whatever the merchant has typed but not saved.
+ const closeImportWizard = () => {
+ queryClient.invalidateQueries({ queryKey: buildKey('price-lists', priceListId, 'products') })
+ wizard.close()
+ }
// Pull rules inline via expand — there's no separate /price_rules
// endpoint anymore; rules ship as a nested array on the price list.
const { data: priceList } = usePriceList(priceListId, ['price_rules'])
@@ -50,15 +69,19 @@ function EditPriceListPage() {
}
return (
- <PriceListForm
- mode="edit"
- priceList={priceList}
- initialRules={priceList?.price_rules}
- onSubmit={async (payload) => {
- await updateMutation.mutateAsync(payload)
- }}
- onDelete={onDelete}
- deletePending={deleteMutation.isPending}
- />
+ <>
+ <PriceListForm
+ mode="edit"
+ priceList={priceList}
+ initialRules={priceList?.price_rules}
+ onSubmit={async (payload) => {
+ await updateMutation.mutateAsync(payload)
+ }}
+ onDelete={onDelete}
+ onImportCreated={(imp) => wizard.open(imp.id)}
+ deletePending={deleteMutation.isPending}
+ />
+ <ImportWizardDialog importId={wizard.importId} onClose={closeImportWizard} />
+ </>
)
}
diff --git a/packages/dashboard/src/routes/_authenticated/$storeId/settings/imports/index.tsx b/packages/dashboard/src/routes/_authenticated/$storeId/settings/imports/index.tsx
index de0d9d0d01..4a3b9c2cf4 100644
--- a/packages/dashboard/src/routes/_authenticated/$storeId/settings/imports/index.tsx
+++ b/packages/dashboard/src/routes/_authenticated/$storeId/settings/imports/index.tsx
@@ -7,19 +7,21 @@ import {
} from '@spree/dashboard-core'
import { RowActions, useConfirm, useRowClickBridge } from '@spree/dashboard-ui'
import { DownloadIcon } from '@spree/dashboard-ui/icons'
-import { createFileRoute, useNavigate } from '@tanstack/react-router'
+import { createFileRoute } from '@tanstack/react-router'
import { useTranslation } from 'react-i18next'
-import { z } from 'zod/v4'
+import type { z } from 'zod/v4'
import { ImportWizardDialog } from '../../../../../components/spree/imports/import-wizard-dialog'
+import {
+ importWizardSearchSchema,
+ useImportWizardSearch,
+} from '../../../../../components/spree/imports/import-wizard-search'
import { isImportActive, useDeleteImport } from '../../../../../hooks/use-imports'
import '../../../../../tables/imports'
// `import` carries the prefixed id of the import whose wizard dialog is open,
// so the flow is deep-linkable and survives refresh (same pattern as the
// webhooks `delivery` param).
-const importsSearchSchema = resourceSearchSchema.extend({
- import: z.string().optional(),
-})
+const importsSearchSchema = resourceSearchSchema.extend(importWizardSearchSchema.shape)
export const Route = createFileRoute('/_authenticated/$storeId/settings/imports/')({
validateSearch: importsSearchSchema,
@@ -29,23 +31,13 @@ export const Route = createFileRoute('/_authenticated/$storeId/settings/imports/
function ImportsPage() {
const { t } = useTranslation()
const search = Route.useSearch() as z.infer<typeof importsSearchSchema>
- const navigate = useNavigate()
const confirm = useConfirm()
const deleteMutation = useDeleteImport()
const downloadOriginal = useDownloadImportOriginal()
- const openWizard = (id: string) =>
- navigate({ search: (prev: Record<string, unknown>) => ({ ...prev, import: id }) as never })
-
- const closeWizard = () =>
- navigate({
- search: (prev: Record<string, unknown>) => {
- const { import: _i, ...rest } = prev
- return rest as never
- },
- })
+ const wizard = useImportWizardSearch(search)
- useRowClickBridge('data-import-id', openWizard)
+ useRowClickBridge('data-import-id', wizard.open)
async function handleDelete(imp: Import) {
const ok = await confirm({
@@ -71,7 +63,7 @@ function ImportsPage() {
{
key: 'view',
label: t('admin.actions.view'),
- onSelect: () => openWizard(imp.id),
+ onSelect: () => wizard.open(imp.id),
},
{
key: 'download_original',
@@ -93,7 +85,7 @@ function ImportsPage() {
)}
/>
- <ImportWizardDialog importId={search.import ?? null} onClose={closeWizard} />
+ <ImportWizardDialog importId={wizard.importId} onClose={wizard.close} />
</>
)
}