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.

Fix back navigation after create across dashboard and seller panel (#14551)

Damian Legawiec2f6c9a5a6d8a
diff --git a/packages/dashboard/e2e/categories.spec.ts b/packages/dashboard/e2e/categories.spec.ts
index 12870de6c1..ea14804310 100644
--- a/packages/dashboard/e2e/categories.spec.ts
+++ b/packages/dashboard/e2e/categories.spec.ts
@@ -20,18 +20,16 @@ async function createCategory(page: Page, name: string) {
await page.locator('#category-name').fill(name)
await page.getByRole('button', { name: /^save$/i }).click()
- // On success the create route navigates to the edit page; go back to the
- // tree and confirm the row landed.
- await page.goto(CATEGORIES_PATH((await currentStoreId(page)) ?? ''))
+ // Create replaces the new-form route in history; back lands on the tree.
+ await expect(page.locator('#category-name')).toHaveValue(name, { timeout: 15_000 })
+ await page.getByRole('button', { name: /^back$/i }).click()
+ await expect(page).toHaveURL(/\/products\/categories(?:\?|$)/, { timeout: 15_000 })
+ // List page title is a CardTitle (not a heading role); the CTA proves we're on the tree.
+ await expect(page.getByRole('button', { name: CTA })).toBeVisible({ timeout: 15_000 })
+ await expect(page.getByRole('heading', { name: CTA })).toHaveCount(0)
await expect(treeRow(page, name)).toBeVisible({ timeout: 15_000 })
}
-// The store id is in the URL; read it so we can navigate back to the index.
-async function currentStoreId(page: Page): Promise<string | null> {
- const match = page.url().match(/\/([^/]+)\/products\/categories/)
- return match?.[1] ?? null
-}
-
test.describe('categories management', () => {
test('creates a category', async ({ page }) => {
const creds = await login(page)
diff --git a/packages/dashboard/e2e/promotions.spec.ts b/packages/dashboard/e2e/promotions.spec.ts
index 2386e6cbfd..7f043b0a70 100644
--- a/packages/dashboard/e2e/promotions.spec.ts
+++ b/packages/dashboard/e2e/promotions.spec.ts
@@ -96,6 +96,15 @@ test.describe('promotions', () => {
await cancelEditor(page)
await submitCreate(page, name)
+
+ // Creating replaces the new-form route in history; back goes to the list,
+ // not the stale create form (which would duplicate on re-save).
+ await page.getByRole('button', { name: /^back$/i }).click()
+ await expect(page).toHaveURL(new RegExp(`/${creds.store_id}/promotions(?:\\?|$)`), {
+ timeout: 15_000,
+ })
+ await expect(page.getByRole('heading', { name: /^new promotion$/i })).toHaveCount(0)
+ await expect(rowButton(page, name)).toBeVisible({ timeout: 15_000 })
})
test('removes a rule and an action while editing', async ({ page }) => {
diff --git a/packages/dashboard/e2e/sellers.spec.ts b/packages/dashboard/e2e/sellers.spec.ts
index 0fec79bc93..c86c41cdbe 100644
--- a/packages/dashboard/e2e/sellers.spec.ts
+++ b/packages/dashboard/e2e/sellers.spec.ts
@@ -34,6 +34,24 @@ test.describe('sellers', () => {
await gotoIndex(page, SELLERS_PATH(creds.store_id), CTA)
})
+ test('back from a new seller lands on the list', async ({ page }) => {
+ const creds = await login(page)
+ await gotoIndex(page, SELLERS_PATH(creds.store_id), CTA)
+
+ const name = `E2E Back Seller ${Date.now()}`
+ await page.getByRole('button', { name: CTA }).click()
+ await page.locator('#name').fill(name)
+ await page.getByRole('button', { name: /create seller/i }).click()
+ await expect(page.getByRole('heading', { name })).toBeVisible({ timeout: 15_000 })
+
+ await page.getByRole('button', { name: /^back$/i }).click()
+ await expect(page).toHaveURL(new RegExp(`/${creds.store_id}/sellers(?:\\?|$)`), {
+ timeout: 15_000,
+ })
+ await expect(page.getByRole('heading', { name: /new seller/i })).toHaveCount(0)
+ await expect(rowLink(page, name)).toBeVisible({ timeout: 15_000 })
+ })
+
// The page is a profile you read, not a form you land in.
test('shows the profile without dropping into an edit form', async ({ page }) => {
const creds = await login(page)
diff --git a/packages/dashboard/src/routes/_authenticated/$storeId/companies/index.tsx b/packages/dashboard/src/routes/_authenticated/$storeId/companies/index.tsx
index b365a13ef2..264b4a2c14 100644
--- a/packages/dashboard/src/routes/_authenticated/$storeId/companies/index.tsx
+++ b/packages/dashboard/src/routes/_authenticated/$storeId/companies/index.tsx
@@ -66,6 +66,7 @@ function CompaniesPage() {
const closeSheet = () =>
navigate({
+ replace: true,
search: (prev: Record<string, unknown>) => {
const { new: _n, ...rest } = prev
return rest as never
@@ -152,6 +153,7 @@ function CreateCompanySheet({
navigate({
to: '/$storeId/companies/$companyId',
params: { storeId, companyId: company.id },
+ replace: true,
})
} catch (err) {
if (!mapSpreeErrorsToForm(err, form.setError)) throw err
diff --git a/packages/dashboard/src/routes/_authenticated/$storeId/customers/index.tsx b/packages/dashboard/src/routes/_authenticated/$storeId/customers/index.tsx
index 34ab6dbcd2..24eed13ab0 100644
--- a/packages/dashboard/src/routes/_authenticated/$storeId/customers/index.tsx
+++ b/packages/dashboard/src/routes/_authenticated/$storeId/customers/index.tsx
@@ -393,6 +393,7 @@ function NewCustomerSheet({
navigate({
to: '/$storeId/customers/$customerId',
params: { storeId, customerId: customer.id },
+ replace: true,
})
},
})
diff --git a/packages/dashboard/src/routes/_authenticated/$storeId/orders/new.tsx b/packages/dashboard/src/routes/_authenticated/$storeId/orders/new.tsx
index 5b8d5ab5a5..ef25326baf 100644
--- a/packages/dashboard/src/routes/_authenticated/$storeId/orders/new.tsx
+++ b/packages/dashboard/src/routes/_authenticated/$storeId/orders/new.tsx
@@ -115,7 +115,13 @@ function NewOrderPage() {
return adminClient.orders.create(payload)
},
onSuccess: (order) => {
- navigate({ to: '/$storeId/orders/$orderId', params: { storeId, orderId: order.id } })
+ // Replace history rather than pushing — otherwise back lands on the
+ // (now-stale) new order form.
+ navigate({
+ to: '/$storeId/orders/$orderId',
+ params: { storeId, orderId: order.id },
+ replace: true,
+ })
},
})
diff --git a/packages/dashboard/src/routes/_authenticated/$storeId/products/categories/new.tsx b/packages/dashboard/src/routes/_authenticated/$storeId/products/categories/new.tsx
index 3b7e482a9d..50eb5d2e5a 100644
--- a/packages/dashboard/src/routes/_authenticated/$storeId/products/categories/new.tsx
+++ b/packages/dashboard/src/routes/_authenticated/$storeId/products/categories/new.tsx
@@ -53,9 +53,12 @@ function NewCategoryPage() {
})
form.reset(values)
// Land on the edit page so images + products can be managed next.
+ // Replace history rather than pushing — otherwise back lands on the
+ // (now-stale) new category form.
await navigate({
to: '/$storeId/products/categories/$categoryId',
params: { storeId, categoryId: created.id },
+ replace: true,
})
} catch (err) {
if (mapSpreeErrorsToForm(err, form.setError)) return
diff --git a/packages/dashboard/src/routes/_authenticated/$storeId/products/collections/new.tsx b/packages/dashboard/src/routes/_authenticated/$storeId/products/collections/new.tsx
index 4f130270fc..25ec489f1a 100644
--- a/packages/dashboard/src/routes/_authenticated/$storeId/products/collections/new.tsx
+++ b/packages/dashboard/src/routes/_authenticated/$storeId/products/collections/new.tsx
@@ -53,9 +53,12 @@ function NewCollectionPage() {
})
form.reset(values)
// Land on the edit page so images + products can be managed next.
+ // Replace history rather than pushing — otherwise back lands on the
+ // (now-stale) new collection form.
await navigate({
to: '/$storeId/products/collections/$collectionId',
params: { storeId, collectionId: created.id },
+ replace: true,
})
} catch (err) {
if (mapSpreeErrorsToForm(err, form.setError)) return
diff --git a/packages/dashboard/src/routes/_authenticated/$storeId/products/price-lists/new.tsx b/packages/dashboard/src/routes/_authenticated/$storeId/products/price-lists/new.tsx
index 757b133e90..b36a7a823e 100644
--- a/packages/dashboard/src/routes/_authenticated/$storeId/products/price-lists/new.tsx
+++ b/packages/dashboard/src/routes/_authenticated/$storeId/products/price-lists/new.tsx
@@ -16,9 +16,12 @@ function NewPriceListPage() {
mode="create"
onSubmit={async (payload) => {
const list = await create.mutateAsync(payload)
+ // Replace history rather than pushing — otherwise the detail page's
+ // back button lands the merchant on the (now-stale) new form.
navigate({
to: '/$storeId/products/price-lists/$priceListId',
params: { storeId, priceListId: list.id },
+ replace: true,
})
}}
/>
diff --git a/packages/dashboard/src/routes/_authenticated/$storeId/promotions/new.tsx b/packages/dashboard/src/routes/_authenticated/$storeId/promotions/new.tsx
index 79d54a2e7b..264b8e8dc9 100644
--- a/packages/dashboard/src/routes/_authenticated/$storeId/promotions/new.tsx
+++ b/packages/dashboard/src/routes/_authenticated/$storeId/promotions/new.tsx
@@ -16,9 +16,12 @@ function NewPromotionPage() {
mode="create"
onSubmit={async (payload) => {
const promotion = await createMutation.mutateAsync(payload)
+ // Replace history rather than pushing — otherwise the detail page's
+ // back button lands the merchant on the (now-stale) new promotion form.
navigate({
to: '/$storeId/promotions/$promotionId',
params: { storeId, promotionId: promotion.id },
+ replace: true,
})
}}
/>
diff --git a/packages/dashboard/src/routes/_authenticated/$storeId/sellers/index.tsx b/packages/dashboard/src/routes/_authenticated/$storeId/sellers/index.tsx
index 92bbd42400..ba225a65d2 100644
--- a/packages/dashboard/src/routes/_authenticated/$storeId/sellers/index.tsx
+++ b/packages/dashboard/src/routes/_authenticated/$storeId/sellers/index.tsx
@@ -62,6 +62,7 @@ function SellersPage() {
const closeSheet = () =>
navigate({
+ replace: true,
search: (prev: Record<string, unknown>) => {
const { new: _n, ...rest } = prev
return rest as never
@@ -153,6 +154,7 @@ function CreateSellerSheet({
navigate({
to: '/$storeId/sellers/$sellerId',
params: { storeId, sellerId: seller.id },
+ replace: true,
})
} catch (err) {
if (!mapSpreeErrorsToForm(err, form.setError)) throw err
diff --git a/packages/dashboard/src/routes/_authenticated/$storeId/settings/delivery-profiles/index.tsx b/packages/dashboard/src/routes/_authenticated/$storeId/settings/delivery-profiles/index.tsx
index 04ccef151b..339a67fcb1 100644
--- a/packages/dashboard/src/routes/_authenticated/$storeId/settings/delivery-profiles/index.tsx
+++ b/packages/dashboard/src/routes/_authenticated/$storeId/settings/delivery-profiles/index.tsx
@@ -75,6 +75,7 @@ function ShippingPage() {
const closeDialog = () =>
navigate({
+ replace: true,
search: (prev: Record<string, unknown>) => {
const { new: _n, ...rest } = prev
return rest as never
@@ -176,6 +177,7 @@ function CreateProfileDialog({ onClose }: { onClose: () => void }) {
navigate({
to: '/$storeId/settings/delivery-profiles/$profileId',
params: { storeId, profileId: profile.id },
+ replace: true,
})
} catch (err) {
if (!mapSpreeErrorsToForm(err, form.setError)) throw err
diff --git a/packages/dashboard/src/routes/_authenticated/$storeId/settings/webhooks/index.tsx b/packages/dashboard/src/routes/_authenticated/$storeId/settings/webhooks/index.tsx
index 089897d387..a0ab39e424 100644
--- a/packages/dashboard/src/routes/_authenticated/$storeId/settings/webhooks/index.tsx
+++ b/packages/dashboard/src/routes/_authenticated/$storeId/settings/webhooks/index.tsx
@@ -85,6 +85,7 @@ function WebhooksPage() {
const closeCreate = () =>
navigate({
+ replace: true,
search: (prev: Record<string, unknown>) => {
const { new: _n, ...rest } = prev
return rest as never
@@ -217,6 +218,7 @@ function WebhooksPage() {
navigate({
to: '/$storeId/settings/webhooks/$webhookEndpointId',
params: { storeId, webhookEndpointId: id },
+ replace: true,
})
}
}}
diff --git a/packages/seller-dashboard/src/pages/product.tsx b/packages/seller-dashboard/src/pages/product.tsx
index ea89caf789..291aa45a52 100644
--- a/packages/seller-dashboard/src/pages/product.tsx
+++ b/packages/seller-dashboard/src/pages/product.tsx
@@ -141,9 +141,12 @@ export function ProductPage({ mode }: { mode: 'new' | 'edit' }) {
void queryClient.invalidateQueries({ queryKey: ['seller', sellerId, 'product', saved.id] })
toastManager.add({ type: 'success', title: t('products.saved') })
if (!productId) {
+ // Replace history rather than pushing — otherwise back lands on the
+ // (now-stale) new product form.
navigate({
to: '/$sellerId/products/$productId',
params: { sellerId, productId: saved.id },
+ replace: true,
})
}
},