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.
Ruby b2b-commercee-commerceecommerceecommerce-apiecommerce-frameworkecommerce-platformheadlessheadless-commerceheadless-ecommercemarketplacemulti-tenantmulti-vendormulti-vendor-ecommerceopen-sourcespree-commerce
Move the role editor into a settings sheet
Damian Legawiec8e864ecdff4d
diff --git a/docs/plans/6.0-admin-rbac.md b/docs/plans/6.0-admin-rbac.mdindex 53cd7680c9..968fa62b34 100644--- a/docs/plans/6.0-admin-rbac.md+++ b/docs/plans/6.0-admin-rbac.md@@ -172,9 +172,13 @@ pages.`read_x`/`write_x` scopes in one step. **Accepted trade-off:** the scope listis boot-dynamic — auditing "what can keys do" means consulting the runningcatalog (`/permissions`), not a frozen constant.-- **The role editor is a full page** — `/settings/roles/$roleId` +- `/settings/roles/new`, not a sheet. The grouped matrix, presets, and a members- panel need the room; Shopify/Vendure set the pattern.+- **The role editor is a settings sheet** (revised 2026-08-08). The original+ call was a full page for the matrix and a members sidebar; in review the+ consistency argument won — every other settings resource (tax categories,+ payment methods, API keys) edits in a `?edit=<id>` / `?new=1` sheet, and a+ roles page that navigated away was the odd one out. The members sidebar is+ dropped with it: the row already shows a member count and Staff owns+ assignment. One sheet serves create, duplicate and edit.- **No seeded roles; the create flow offers client-side templates.** "Ordermanager" / "Merchandiser" / "Support" presets pre-fill the matrix; nothinglands in the DB until saved. **Accepted trade-off:** templates are@@ -344,16 +348,14 @@ DELETE /api/v3/admin/roles/:id # newmembers count, lock icon on immutable roles. Row actions: edit,duplicate (opens the new-role page pre-filled), delete (confirm; disabled withtooltip while `can_be_deleted?` is false).-- **Role editor** (`/settings/roles/$roleId`, full page; `/settings/roles/new`):- name, description, then the permission matrix grouped by catalog group — one- row per resource with a **None / View / Full** segmented control (View =- `read_x`, Full = `write_x`; read-only resources render View/None). Group-level- select-all plus "Read only" / "Full access" presets. A summary sidebar shows- the effective permission count and the role's members on this store.- Immutable roles (`mutable: false`) render the whole editor read-only. Keys- outside the caller's own grant render disabled (the API would reject them —- don't offer them). The create- page opens with a template picker — Blank / Order manager / Merchandiser /+- **Role editor** (a sheet on the same page, driven by `?edit=<id>` / `?new=1`,+ with `?from=<id>` for duplicate): name, description, then the permission+ matrix grouped by catalog group — read/write checkboxes per resource+ (read-only resources render read alone). "Read only" / "Full access" /+ "Clear" presets. Immutable roles (`mutable: false`) and callers without+ update authority get a read-only sheet with no Save. Keys outside the+ caller's own grant render disabled (the API would reject them — don't offer+ them). Creating opens with template buttons — Order manager / Merchandiser /Support — pre-filling the matrix client-side; templates are dashboardconstants, never DB rows.- **Shared picker:** the matrix extracts asdiff --git a/packages/dashboard-starter/src/routeTree.gen.ts b/packages/dashboard-starter/src/routeTree.gen.tsindex faacd4a033..e619c8a509 100644--- a/packages/dashboard-starter/src/routeTree.gen.ts+++ b/packages/dashboard-starter/src/routeTree.gen.ts@@ -33,6 +33,7 @@ import { Route as SettingsTaxCategoriesRouteImport } from './../../dashboard/srcimport { 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'+import { Route as SettingsRolesRouteImport } from './../../dashboard/src/routes/_authenticated/$storeId/settings/roles'import { Route as SettingsReasonsRouteImport } from './../../dashboard/src/routes/_authenticated/$storeId/settings/reasons'import { Route as SettingsProductTypesRouteImport } from './../../dashboard/src/routes/_authenticated/$storeId/settings/product-types'import { Route as SettingsPaymentMethodsRouteImport } from './../../dashboard/src/routes/_authenticated/$storeId/settings/payment-methods'@@ -58,14 +59,11 @@ import { Route as CustomersGroupsRouteImport } from './../../dashboard/src/routeimport { Route as CustomersCustomerIdRouteImport } from './../../dashboard/src/routes/_authenticated/$storeId/customers/$customerId'import { Route as BrandsDotbrandIdRouteImport } from './../../dashboard-plugin-example/src/routes/brands.$brandId'import { Route as SettingsWebhooksIndexRouteImport } from './../../dashboard/src/routes/_authenticated/$storeId/settings/webhooks/index'-import { Route as SettingsRolesIndexRouteImport } from './../../dashboard/src/routes/_authenticated/$storeId/settings/roles/index'import { Route as SettingsImportsIndexRouteImport } from './../../dashboard/src/routes/_authenticated/$storeId/settings/imports/index'import { Route as ProductsPriceListsIndexRouteImport } from './../../dashboard/src/routes/_authenticated/$storeId/products/price-lists/index'import { Route as ProductsCollectionsIndexRouteImport } from './../../dashboard/src/routes/_authenticated/$storeId/products/collections/index'import { Route as ProductsCategoriesIndexRouteImport } from './../../dashboard/src/routes/_authenticated/$storeId/products/categories/index'import { Route as SettingsWebhooksWebhookEndpointIdRouteImport } from './../../dashboard/src/routes/_authenticated/$storeId/settings/webhooks/$webhookEndpointId'-import { Route as SettingsRolesNewRouteImport } from './../../dashboard/src/routes/_authenticated/$storeId/settings/roles/new'-import { Route as SettingsRolesRoleIdRouteImport } from './../../dashboard/src/routes/_authenticated/$storeId/settings/roles/$roleId'import { Route as ProductsPriceListsNewRouteImport } from './../../dashboard/src/routes/_authenticated/$storeId/products/price-lists/new'import { Route as ProductsCollectionsNewRouteImport } from './../../dashboard/src/routes/_authenticated/$storeId/products/collections/new'import { Route as ProductsCollectionsCollectionIdRouteImport } from './../../dashboard/src/routes/_authenticated/$storeId/products/collections/$collectionId'@@ -193,6 +191,11 @@ const SettingsStaffRoute = SettingsStaffRouteImport.update({path: '/staff',getParentRoute: () => SettingsRoute,} as any)+const SettingsRolesRoute = SettingsRolesRouteImport.update({+ id: '/roles',+ path: '/roles',+ getParentRoute: () => SettingsRoute,+} as any)const SettingsReasonsRoute = SettingsReasonsRouteImport.update({id: '/reasons',path: '/reasons',@@ -319,11 +322,6 @@ const SettingsWebhooksIndexRoute = SettingsWebhooksIndexRouteImport.update({path: '/webhooks/',getParentRoute: () => SettingsRoute,} as any)-const SettingsRolesIndexRoute = SettingsRolesIndexRouteImport.update({- id: '/roles/',- path: '/roles/',- getParentRoute: () => SettingsRoute,-} as any)const SettingsImportsIndexRoute = SettingsImportsIndexRouteImport.update({id: '/imports/',path: '/imports/',@@ -351,16 +349,6 @@ const SettingsWebhooksWebhookEndpointIdRoute =path: '/webhooks/$webhookEndpointId',getParentRoute: () => SettingsRoute,} as any)-const SettingsRolesNewRoute = SettingsRolesNewRouteImport.update({- id: '/roles/new',- path: '/roles/new',- getParentRoute: () => SettingsRoute,-} as any)-const SettingsRolesRoleIdRoute = SettingsRolesRoleIdRouteImport.update({- id: '/roles/$roleId',- path: '/roles/$roleId',- getParentRoute: () => SettingsRoute,-} as any)const ProductsPriceListsNewRoute = ProductsPriceListsNewRouteImport.update({id: '/products/price-lists/new',path: '/products/price-lists/new',@@ -433,6 +421,7 @@ export interface FileRoutesByFullPath {'/$storeId/settings/payment-methods': typeof SettingsPaymentMethodsRoute'/$storeId/settings/product-types': typeof SettingsProductTypesRoute'/$storeId/settings/reasons': typeof SettingsReasonsRoute+ '/$storeId/settings/roles': typeof SettingsRolesRoute'/$storeId/settings/staff': typeof SettingsStaffRoute'/$storeId/settings/stock-locations': typeof SettingsStockLocationsRoute'/$storeId/settings/store': typeof SettingsStoreRoute@@ -448,14 +437,11 @@ export interface FileRoutesByFullPath {'/$storeId/products/collections/$collectionId': typeof ProductsCollectionsCollectionIdRoute'/$storeId/products/collections/new': typeof ProductsCollectionsNewRoute'/$storeId/products/price-lists/new': typeof ProductsPriceListsNewRoute- '/$storeId/settings/roles/$roleId': typeof SettingsRolesRoleIdRoute- '/$storeId/settings/roles/new': typeof SettingsRolesNewRoute'/$storeId/settings/webhooks/$webhookEndpointId': typeof SettingsWebhooksWebhookEndpointIdRoute'/$storeId/products/categories/': typeof ProductsCategoriesIndexRoute'/$storeId/products/collections/': typeof ProductsCollectionsIndexRoute'/$storeId/products/price-lists/': typeof ProductsPriceListsIndexRoute'/$storeId/settings/imports/': typeof SettingsImportsIndexRoute- '/$storeId/settings/roles/': typeof SettingsRolesIndexRoute'/$storeId/settings/webhooks/': typeof SettingsWebhooksIndexRoute'/$storeId/products/price-lists/$priceListId/': typeof ProductsPriceListsPriceListIdIndexRoute}@@ -495,6 +481,7 @@ export interface FileRoutesByTo {'/$storeId/settings/payment-methods': typeof SettingsPaymentMethodsRoute'/$storeId/settings/product-types': typeof SettingsProductTypesRoute'/$storeId/settings/reasons': typeof SettingsReasonsRoute+ '/$storeId/settings/roles': typeof SettingsRolesRoute'/$storeId/settings/staff': typeof SettingsStaffRoute'/$storeId/settings/stock-locations': typeof SettingsStockLocationsRoute'/$storeId/settings/store': typeof SettingsStoreRoute@@ -510,14 +497,11 @@ export interface FileRoutesByTo {'/$storeId/products/collections/$collectionId': typeof ProductsCollectionsCollectionIdRoute'/$storeId/products/collections/new': typeof ProductsCollectionsNewRoute'/$storeId/products/price-lists/new': typeof ProductsPriceListsNewRoute- '/$storeId/settings/roles/$roleId': typeof SettingsRolesRoleIdRoute- '/$storeId/settings/roles/new': typeof SettingsRolesNewRoute'/$storeId/settings/webhooks/$webhookEndpointId': typeof SettingsWebhooksWebhookEndpointIdRoute'/$storeId/products/categories': typeof ProductsCategoriesIndexRoute'/$storeId/products/collections': typeof ProductsCollectionsIndexRoute'/$storeId/products/price-lists': typeof ProductsPriceListsIndexRoute'/$storeId/settings/imports': typeof SettingsImportsIndexRoute- '/$storeId/settings/roles': typeof SettingsRolesIndexRoute'/$storeId/settings/webhooks': typeof SettingsWebhooksIndexRoute'/$storeId/products/price-lists/$priceListId': typeof ProductsPriceListsPriceListIdIndexRoute}@@ -561,6 +545,7 @@ export interface FileRoutesById {'/_authenticated/$storeId/settings/payment-methods': typeof SettingsPaymentMethodsRoute'/_authenticated/$storeId/settings/product-types': typeof SettingsProductTypesRoute'/_authenticated/$storeId/settings/reasons': typeof SettingsReasonsRoute+ '/_authenticated/$storeId/settings/roles': typeof SettingsRolesRoute'/_authenticated/$storeId/settings/staff': typeof SettingsStaffRoute'/_authenticated/$storeId/settings/stock-locations': typeof SettingsStockLocationsRoute'/_authenticated/$storeId/settings/store': typeof SettingsStoreRoute@@ -576,14 +561,11 @@ export interface FileRoutesById {'/_authenticated/$storeId/products/collections/$collectionId': typeof ProductsCollectionsCollectionIdRoute'/_authenticated/$storeId/products/collections/new': typeof ProductsCollectionsNewRoute'/_authenticated/$storeId/products/price-lists/new': typeof ProductsPriceListsNewRoute- '/_authenticated/$storeId/settings/roles/$roleId': typeof SettingsRolesRoleIdRoute- '/_authenticated/$storeId/settings/roles/new': typeof SettingsRolesNewRoute'/_authenticated/$storeId/settings/webhooks/$webhookEndpointId': typeof SettingsWebhooksWebhookEndpointIdRoute'/_authenticated/$storeId/products/categories/': typeof ProductsCategoriesIndexRoute'/_authenticated/$storeId/products/collections/': typeof ProductsCollectionsIndexRoute'/_authenticated/$storeId/products/price-lists/': typeof ProductsPriceListsIndexRoute'/_authenticated/$storeId/settings/imports/': typeof SettingsImportsIndexRoute- '/_authenticated/$storeId/settings/roles/': typeof SettingsRolesIndexRoute'/_authenticated/$storeId/settings/webhooks/': typeof SettingsWebhooksIndexRoute'/_authenticated/$storeId/products/price-lists/$priceListId/': typeof ProductsPriceListsPriceListIdIndexRoute}@@ -627,6 +609,7 @@ export interface FileRouteTypes {| '/$storeId/settings/payment-methods'| '/$storeId/settings/product-types'| '/$storeId/settings/reasons'+ | '/$storeId/settings/roles'| '/$storeId/settings/staff'| '/$storeId/settings/stock-locations'| '/$storeId/settings/store'@@ -642,14 +625,11 @@ export interface FileRouteTypes {| '/$storeId/products/collections/$collectionId'| '/$storeId/products/collections/new'| '/$storeId/products/price-lists/new'- | '/$storeId/settings/roles/$roleId'- | '/$storeId/settings/roles/new'| '/$storeId/settings/webhooks/$webhookEndpointId'| '/$storeId/products/categories/'| '/$storeId/products/collections/'| '/$storeId/products/price-lists/'| '/$storeId/settings/imports/'- | '/$storeId/settings/roles/'| '/$storeId/settings/webhooks/'| '/$storeId/products/price-lists/$priceListId/'fileRoutesByTo: FileRoutesByTo@@ -689,6 +669,7 @@ export interface FileRouteTypes {| '/$storeId/settings/payment-methods'| '/$storeId/settings/product-types'| '/$storeId/settings/reasons'+ | '/$storeId/settings/roles'| '/$storeId/settings/staff'| '/$storeId/settings/stock-locations'| '/$storeId/settings/store'@@ -704,14 +685,11 @@ export interface FileRouteTypes {| '/$storeId/products/collections/$collectionId'| '/$storeId/products/collections/new'| '/$storeId/products/price-lists/new'- | '/$storeId/settings/roles/$roleId'- | '/$storeId/settings/roles/new'| '/$storeId/settings/webhooks/$webhookEndpointId'| '/$storeId/products/categories'| '/$storeId/products/collections'| '/$storeId/products/price-lists'| '/$storeId/settings/imports'- | '/$storeId/settings/roles'| '/$storeId/settings/webhooks'| '/$storeId/products/price-lists/$priceListId'id:@@ -754,6 +732,7 @@ export interface FileRouteTypes {| '/_authenticated/$storeId/settings/payment-methods'| '/_authenticated/$storeId/settings/product-types'| '/_authenticated/$storeId/settings/reasons'+ | '/_authenticated/$storeId/settings/roles'| '/_authenticated/$storeId/settings/staff'| '/_authenticated/$storeId/settings/stock-locations'| '/_authenticated/$storeId/settings/store'@@ -769,14 +748,11 @@ export interface FileRouteTypes {| '/_authenticated/$storeId/products/collections/$collectionId'| '/_authenticated/$storeId/products/collections/new'| '/_authenticated/$storeId/products/price-lists/new'- | '/_authenticated/$storeId/settings/roles/$roleId'- | '/_authenticated/$storeId/settings/roles/new'| '/_authenticated/$storeId/settings/webhooks/$webhookEndpointId'| '/_authenticated/$storeId/products/categories/'| '/_authenticated/$storeId/products/collections/'| '/_authenticated/$storeId/products/price-lists/'| '/_authenticated/$storeId/settings/imports/'- | '/_authenticated/$storeId/settings/roles/'| '/_authenticated/$storeId/settings/webhooks/'| '/_authenticated/$storeId/products/price-lists/$priceListId/'fileRoutesById: FileRoutesById@@ -959,6 +935,13 @@ declare module '@tanstack/react-router' {preLoaderRoute: typeof SettingsStaffRouteImportparentRoute: typeof SettingsRoute}+ '/_authenticated/$storeId/settings/roles': {+ id: '/_authenticated/$storeId/settings/roles'+ path: '/roles'+ fullPath: '/$storeId/settings/roles'+ preLoaderRoute: typeof SettingsRolesRouteImport+ parentRoute: typeof SettingsRoute+ }'/_authenticated/$storeId/settings/reasons': {id: '/_authenticated/$storeId/settings/reasons'path: '/reasons'@@ -1134,13 +1117,6 @@ declare module '@tanstack/react-router' {preLoaderRoute: typeof SettingsWebhooksIndexRouteImportparentRoute: typeof SettingsRoute}- '/_authenticated/$storeId/settings/roles/': {- id: '/_authenticated/$storeId/settings/roles/'- path: '/roles'- fullPath: '/$storeId/settings/roles/'- preLoaderRoute: typeof SettingsRolesIndexRouteImport- parentRoute: typeof SettingsRoute- }'/_authenticated/$storeId/settings/imports/': {id: '/_authenticated/$storeId/settings/imports/'path: '/imports'@@ -1176,20 +1152,6 @@ declare module '@tanstack/react-router' {preLoaderRoute: typeof SettingsWebhooksWebhookEndpointIdRouteImportparentRoute: typeof SettingsRoute}- '/_authenticated/$storeId/settings/roles/new': {- id: '/_authenticated/$storeId/settings/roles/new'- path: '/roles/new'- fullPath: '/$storeId/settings/roles/new'- preLoaderRoute: typeof SettingsRolesNewRouteImport- parentRoute: typeof SettingsRoute- }- '/_authenticated/$storeId/settings/roles/$roleId': {- id: '/_authenticated/$storeId/settings/roles/$roleId'- path: '/roles/$roleId'- fullPath: '/$storeId/settings/roles/$roleId'- preLoaderRoute: typeof SettingsRolesRoleIdRouteImport- parentRoute: typeof SettingsRoute- }'/_authenticated/$storeId/products/price-lists/new': {id: '/_authenticated/$storeId/products/price-lists/new'path: '/products/price-lists/new'@@ -1247,16 +1209,14 @@ interface SettingsRouteChildren {SettingsPaymentMethodsRoute: typeof SettingsPaymentMethodsRouteSettingsProductTypesRoute: typeof SettingsProductTypesRouteSettingsReasonsRoute: typeof SettingsReasonsRoute+ SettingsRolesRoute: typeof SettingsRolesRouteSettingsStaffRoute: typeof SettingsStaffRouteSettingsStockLocationsRoute: typeof SettingsStockLocationsRouteSettingsStoreRoute: typeof SettingsStoreRouteSettingsTaxCategoriesRoute: typeof SettingsTaxCategoriesRouteSettingsIndexRoute: typeof SettingsIndexRoute- SettingsRolesRoleIdRoute: typeof SettingsRolesRoleIdRoute- SettingsRolesNewRoute: typeof SettingsRolesNewRouteSettingsWebhooksWebhookEndpointIdRoute: typeof SettingsWebhooksWebhookEndpointIdRouteSettingsImportsIndexRoute: typeof SettingsImportsIndexRoute- SettingsRolesIndexRoute: typeof SettingsRolesIndexRouteSettingsWebhooksIndexRoute: typeof SettingsWebhooksIndexRoute}@@ -1272,17 +1232,15 @@ const SettingsRouteChildren: SettingsRouteChildren = {SettingsPaymentMethodsRoute: SettingsPaymentMethodsRoute,SettingsProductTypesRoute: SettingsProductTypesRoute,SettingsReasonsRoute: SettingsReasonsRoute,+ SettingsRolesRoute: SettingsRolesRoute,SettingsStaffRoute: SettingsStaffRoute,SettingsStockLocationsRoute: SettingsStockLocationsRoute,SettingsStoreRoute: SettingsStoreRoute,SettingsTaxCategoriesRoute: SettingsTaxCategoriesRoute,SettingsIndexRoute: SettingsIndexRoute,- SettingsRolesRoleIdRoute: SettingsRolesRoleIdRoute,- SettingsRolesNewRoute: SettingsRolesNewRoute,SettingsWebhooksWebhookEndpointIdRoute:SettingsWebhooksWebhookEndpointIdRoute,SettingsImportsIndexRoute: SettingsImportsIndexRoute,- SettingsRolesIndexRoute: SettingsRolesIndexRoute,SettingsWebhooksIndexRoute: SettingsWebhooksIndexRoute,}diff --git a/packages/dashboard/e2e/roles.spec.ts b/packages/dashboard/e2e/roles.spec.tsindex f579343ab6..7eea2fb88f 100644--- a/packages/dashboard/e2e/roles.spec.ts+++ b/packages/dashboard/e2e/roles.spec.ts@@ -8,6 +8,10 @@ async function gotoRoles(page: Page, storeId: string) {await expect(page.getByRole('button', { name: /add role/i })).toBeVisible({ timeout: 15_000 })}+function sheet(page: Page) {+ return page.getByRole('dialog')+}+test.describe('roles', () => {test('lists roles with the protected admin role', async ({ page }) => {const creds = await login(page)@@ -24,43 +28,57 @@ test.describe('roles', () => {const name = `e2e-support-${Date.now()}`await page.getByRole('button', { name: /add role/i }).click()- await expect(page.getByRole('heading', { name: /new role/i })).toBeVisible()+ await expect(sheet(page)).toBeVisible()await page.locator('#role-name').fill(name)await page.locator('#role-description').fill('Read-only support role')- await page.getByRole('checkbox', { name: /view orders/i }).check()- await page.getByRole('checkbox', { name: /view customers/i }).check()- await page.getByRole('button', { name: /^save$/i }).click()+ await sheet(page)+ .getByRole('checkbox', { name: /view orders/i })+ .check()+ await sheet(page)+ .getByRole('checkbox', { name: /view customers/i })+ .check()+ await sheet(page)+ .getByRole('button', { name: /^save$/i })+ .click()- // Back on the list with the new role and its human-readable permission badges.- await expect(page.getByRole('cell', { name: new RegExp(name, 'i') })).toBeVisible({- timeout: 15_000,- })+ // Sheet closes; the new role and its human-readable badges show in the list.+ await expect(sheet(page)).toHaveCount(0, { timeout: 15_000 })+ await expect(page.getByRole('cell', { name: new RegExp(name, 'i') })).toBeVisible()await expect(page.getByText('View Orders').first()).toBeVisible()- // Round-trip: open the editor, grant manage on orders, save.+ // Round-trip: reopen the row, grant manage on orders, save.await page.getByRole('cell', { name: new RegExp(name, 'i') }).click()- await expect(page.getByRole('heading', { name: new RegExp(name, 'i') })).toBeVisible()+ await expect(sheet(page).locator('#role-name')).toHaveValue(name, { timeout: 15_000 })++ await sheet(page)+ .getByRole('checkbox', { name: /manage orders/i })+ .check()+ await sheet(page)+ .getByRole('button', { name: /^save$/i })+ .click()- const manageOrders = page.getByRole('checkbox', { name: /manage orders/i })- await manageOrders.check()- await page.getByRole('button', { name: /^save$/i }).click()await expect(page.getByText(/role updated/i)).toBeVisible({ timeout: 15_000 })+ await expect(sheet(page)).toHaveCount(0)})- test('starts from a template on the create page', async ({ page }) => {+ test('starts from a template', async ({ page }) => {const creds = await login(page)await gotoRoles(page, creds.store_id)await page.getByRole('button', { name: /add role/i }).click()- await page.getByRole('button', { name: /^support$/i }).click()+ await sheet(page)+ .getByRole('button', { name: /^support$/i })+ .click()// The template pre-fills the grid; "view orders" is part of Support.- await expect(page.getByRole('checkbox', { name: /view orders/i })).toBeChecked()+ await expect(sheet(page).getByRole('checkbox', { name: /view orders/i })).toBeChecked()const name = `e2e-template-${Date.now()}`await page.locator('#role-name').fill(name)- await page.getByRole('button', { name: /^save$/i }).click()+ await sheet(page)+ .getByRole('button', { name: /^save$/i })+ .click()await expect(page.getByRole('cell', { name: new RegExp(name, 'i') })).toBeVisible({timeout: 15_000,@@ -75,9 +93,44 @@ test.describe('roles', () => {.getByRole('cell', { name: /^admin/i }).first().click()- await expect(page.getByText(/protected/i).first()).toBeVisible()- await expect(page.getByRole('button', { name: /^save$/i })).toHaveCount(0)- await expect(page.locator('#role-name')).toBeDisabled()+ await expect(+ sheet(page)+ .getByText(/protected/i)+ .first(),+ ).toBeVisible({ timeout: 15_000 })+ await expect(sheet(page).getByRole('button', { name: /^save$/i })).toHaveCount(0)+ await expect(sheet(page).locator('#role-name')).toBeDisabled()+ })++ test('duplicates a role', async ({ page }) => {+ const creds = await login(page)+ await gotoRoles(page, creds.store_id)++ const name = `e2e-dup-src-${Date.now()}`+ await page.getByRole('button', { name: /add role/i }).click()+ await page.locator('#role-name').fill(name)+ await sheet(page)+ .getByRole('checkbox', { name: /view orders/i })+ .check()+ await sheet(page)+ .getByRole('button', { name: /^save$/i })+ .click()+ await expect(page.getByRole('cell', { name: new RegExp(name, 'i') })).toBeVisible({+ timeout: 15_000,+ })++ await page+ .getByRole('row', { name: new RegExp(name, 'i') })+ .getByRole('button')+ .last()+ .click()+ await page.getByRole('menuitem', { name: /duplicate/i }).click()++ // The copy carries the source's permissions and a distinct name.+ await expect(sheet(page).getByRole('checkbox', { name: /view orders/i })).toBeChecked({+ timeout: 15_000,+ })+ await expect(sheet(page).locator('#role-name')).toHaveValue(new RegExp(name, 'i'))})test('blocks deleting a role while staff hold it, allows after unassign', async ({ page }) => {@@ -88,8 +141,12 @@ test.describe('roles', () => {await gotoRoles(page, creds.store_id)await page.getByRole('button', { name: /add role/i }).click()await page.locator('#role-name').fill(name)- await page.getByRole('checkbox', { name: /view orders/i }).check()- await page.getByRole('button', { name: /^save$/i }).click()+ await sheet(page)+ .getByRole('checkbox', { name: /view orders/i })+ .check()+ await sheet(page)+ .getByRole('button', { name: /^save$/i })+ .click()await expect(page.getByRole('cell', { name: new RegExp(name, 'i') })).toBeVisible({timeout: 15_000,})@@ -123,7 +180,6 @@ test.describe('roles', () => {await page.getByRole('menuitem', { name: /edit/i }).click()await page.getByRole('checkbox', { name: new RegExp(name, 'i') }).uncheck()await page.getByRole('button', { name: /^save$/i }).click()- // The sheet closes on success and the badge leaves the staff row.await expect(page.getByRole('row', { name: /spree@example\.com/i }).getByText(new RegExp(name, 'i')),).toHaveCount(0, { timeout: 15_000 })diff --git a/packages/dashboard/src/components/spree/role-form.tsx b/packages/dashboard/src/components/spree/role-form.tsxdeleted file mode 100644index 6fa41f39e9..0000000000--- a/packages/dashboard/src/components/spree/role-form.tsx+++ /dev/null@@ -1,290 +0,0 @@-import { zodResolver } from '@hookform/resolvers/zod'-import type { Role } from '@spree/admin-sdk'-import { SpreeError } from '@spree/admin-sdk'-import { mapSpreeErrorsToForm, usePermissions } from '@spree/dashboard-core'-import {- Badge,- Button,- Card,- CardContent,- CardHeader,- CardTitle,- Field,- FieldError,- FieldLabel,- Input,- Skeleton,- Textarea,-} from '@spree/dashboard-ui'-import i18n from 'i18next'-import { LockIcon } from 'lucide-react'-import { useMemo } from 'react'-import { Controller, useForm } from 'react-hook-form'-import { useTranslation } from 'react-i18next'-import { toast } from 'sonner'-import { z } from 'zod/v4'-import { usePermissionCatalog } from '../../hooks/use-roles'-import { useStaff } from '../../hooks/use-staff'-import { allReadKeys, allWriteKeys, PermissionGrid } from './permission-picker'--const roleSchema = z.object({- name: z.string().min(1, { error: () => i18n.t('admin.roles.validation.name_required') }),- description: z.string(),- permissions: z.array(z.string()),-})--export type RoleFormValues = z.infer<typeof roleSchema>--/**- * Quick-start permission sets offered on the create page. Dashboard constants- * only — nothing is seeded; a template just pre-fills the grid before saving.- */-export const ROLE_TEMPLATES: Array<{ key: string; permissions: string[] }> = [- {- key: 'order_manager',- permissions: [- 'write_orders',- 'write_payments',- 'write_fulfillments',- 'write_refunds',- 'write_gift_cards',- 'write_store_credits',- 'read_customers',- ],- },- {- key: 'merchandiser',- permissions: ['write_products', 'write_categories', 'write_collections', 'write_stock'],- },- {- key: 'support',- permissions: ['read_orders', 'read_customers', 'read_dashboard'],- },-]--export function useRoleForm(initial?: Partial<RoleFormValues>) {- return useForm<RoleFormValues>({- resolver: zodResolver(roleSchema),- defaultValues: {- name: initial?.name ?? '',- description: initial?.description ?? '',- permissions: initial?.permissions ?? [],- },- })-}--/** Wraps a submit handler with the standard 422 → form-error mapping. */-export function submitRole(- form: ReturnType<typeof useRoleForm>,- action: (values: RoleFormValues) => Promise<void>,-) {- return form.handleSubmit(async (values) => {- try {- await action(values)- } catch (err) {- if (mapSpreeErrorsToForm(err, form.setError)) return- if (err instanceof SpreeError) {- toast.error(err.message)- return- }- // Network and other unexpected failures still deserve feedback —- // rethrowing from a submit handler would surface nothing.- toast.error(i18n.t('admin.roles.errors.failed_to_save'))- }- })-}--/**- * The role editor body — name/description, the permission grid with presets,- * and the summary sidebar. Shared by the create and edit pages; the pages own- * the header, submit wiring, and navigation.- */-export function RoleFormFields({- form,- role,- readOnly = false,-}: {- form: ReturnType<typeof useRoleForm>- /** Present on the edit page — drives the members panel and immutable state. */- role?: Role- readOnly?: boolean-}) {- const { t } = useTranslation()- const { data: catalog } = usePermissionCatalog()- const { permissionKeys } = usePermissions()- const permissions = form.watch('permissions')-- // Keys the current admin cannot grant (the API rejects them) render- // disabled. An admin holding the full catalog is never restricted.- const blockedKeys = useMemo(() => {- if (!catalog) return undefined- const blocked = new Set(- catalog.data.filter((entry) => !permissionKeys.includes(entry.key)).map((entry) => entry.key),- )- return blocked.size > 0 ? blocked : undefined- }, [catalog, permissionKeys])-- function applyPreset(keys: string[]) {- form.setValue(- 'permissions',- keys.filter((key) => permissionKeys.includes(key)),- { shouldDirty: true },- )- }-- return (- <div className="flex flex-col gap-6 lg:flex-row">- <div className="flex min-w-0 flex-1 flex-col gap-6">- <Card>- <CardHeader>- <CardTitle>{t('admin.roles.form.details_section')}</CardTitle>- </CardHeader>- <CardContent className="flex flex-col gap-4">- {form.formState.errors.root?.message && (- <p className="text-sm text-destructive" role="alert">- {form.formState.errors.root.message}- </p>- )}- <Field>- <FieldLabel htmlFor="role-name">{t('admin.fields.role.name.label')}</FieldLabel>- <Input- id="role-name"- placeholder={t('admin.fields.role.name.placeholder')}- disabled={readOnly}- aria-invalid={!!form.formState.errors.name || undefined}- {...form.register('name')}- />- <FieldError errors={[form.formState.errors.name]} />- </Field>- <Field>- <FieldLabel htmlFor="role-description">- {t('admin.fields.role.description.label')}- </FieldLabel>- <Textarea- id="role-description"- rows={2}- placeholder={t('admin.fields.role.description.placeholder')}- disabled={readOnly}- {...form.register('description')}- />- </Field>- </CardContent>- </Card>-- <Card>- <CardHeader className="flex flex-row items-center justify-between">- <CardTitle>{t('admin.roles.form.permissions_section')}</CardTitle>- {!readOnly && catalog && (- <div className="flex gap-2">- <Button- type="button"- variant="outline"- size="sm"- onClick={() => applyPreset(allReadKeys(catalog.data))}- >- {t('admin.roles.presets.read_only')}- </Button>- <Button- type="button"- variant="outline"- size="sm"- onClick={() => applyPreset(allWriteKeys(catalog.data))}- >- {t('admin.roles.presets.full_access')}- </Button>- <Button type="button" variant="ghost" size="sm" onClick={() => applyPreset([])}>- {t('admin.roles.presets.clear')}- </Button>- </div>- )}- </CardHeader>- <CardContent>- {catalog ? (- <Controller- name="permissions"- control={form.control}- render={({ field }) => (- <PermissionGrid- entries={catalog.data}- value={field.value}- onChange={field.onChange}- disabled={readOnly}- disabledKeys={blockedKeys}- />- )}- />- ) : (- <div className="flex flex-col gap-2">- <Skeleton className="h-8 w-full" />- <Skeleton className="h-8 w-full" />- <Skeleton className="h-8 w-full" />- </div>- )}- {form.formState.errors.permissions && (- <p className="mt-2 text-sm text-destructive">- {form.formState.errors.permissions.message}- </p>- )}- </CardContent>- </Card>- </div>-- <div className="flex w-full flex-col gap-6 lg:w-72">- <Card>- <CardHeader>- <CardTitle>{t('admin.roles.form.summary_section')}</CardTitle>- </CardHeader>- <CardContent className="flex flex-col gap-3 text-sm">- {readOnly && (- <p className="flex items-start gap-2 text-muted-foreground">- <LockIcon className="mt-0.5 size-4 shrink-0" />- {t('admin.roles.form.locked_hint')}- </p>- )}- <div className="flex items-center justify-between">- <span className="text-muted-foreground">- {t('admin.roles.form.permissions_count')}- </span>- <Badge>- {role?.name === 'admin' ? t('admin.roles.badges.full_access') : permissions.length}- </Badge>- </div>- {role && <RoleMembers role={role} />}- </CardContent>- </Card>- </div>- </div>- )-}--function RoleMembers({ role }: { role: Role }) {- const { t } = useTranslation()- const { data: staff } = useStaff()-- const members = (staff?.data ?? []).filter((member) =>- member.roles.some((memberRole) => memberRole.id === role.id),- )-- return (- <div className="flex flex-col gap-2">- <div className="flex items-center justify-between">- <span className="text-muted-foreground">{t('admin.roles.form.members')}</span>- <Badge variant="secondary">{role.users_count}</Badge>- </div>- {members.length > 0 && (- <ul className="flex flex-col gap-1">- {members.slice(0, 8).map((member) => (- <li key={member.id} className="truncate text-muted-foreground">- {member.full_name || member.email}- </li>- ))}- {members.length > 8 && (- <li className="text-xs text-muted-foreground">- {t('admin.roles.form.more_members', { count: members.length - 8 })}- </li>- )}- </ul>- )}- </div>- )-}diff --git a/packages/dashboard/src/components/spree/role-sheet.tsx b/packages/dashboard/src/components/spree/role-sheet.tsxnew file mode 100644index 0000000000..5785068d33--- /dev/null+++ b/packages/dashboard/src/components/spree/role-sheet.tsx@@ -0,0 +1,331 @@+import { zodResolver } from '@hookform/resolvers/zod'+import { SpreeError } from '@spree/admin-sdk'+import { mapSpreeErrorsToForm, usePermissions } from '@spree/dashboard-core'+import {+ Badge,+ Button,+ Field,+ FieldError,+ FieldLabel,+ Input,+ Sheet,+ SheetContent,+ SheetDescription,+ SheetFooter,+ SheetHeader,+ SheetTitle,+ Skeleton,+ Textarea,+} from '@spree/dashboard-ui'+import i18n from 'i18next'+import { useEffect, useMemo } from 'react'+import { Controller, useForm } from 'react-hook-form'+import { useTranslation } from 'react-i18next'+import { toast } from 'sonner'+import { z } from 'zod/v4'+import { useCreateRole, usePermissionCatalog, useRole, useUpdateRole } from '../../hooks/use-roles'+import { allReadKeys, allWriteKeys, PermissionGrid } from './permission-picker'++const roleSchema = z.object({+ name: z.string().min(1, { error: () => i18n.t('admin.roles.validation.name_required') }),+ description: z.string(),+ permissions: z.array(z.string()),+})++type RoleFormValues = z.infer<typeof roleSchema>++const ROLE_DEFAULTS: RoleFormValues = { name: '', description: '', permissions: [] }++/**+ * Quick-start permission sets offered when creating a role. Dashboard+ * constants only — nothing is seeded; a template just pre-fills the grid+ * before saving.+ */+const ROLE_TEMPLATES: Array<{ key: string; permissions: string[] }> = [+ {+ key: 'order_manager',+ permissions: [+ 'write_orders',+ 'write_payments',+ 'write_fulfillments',+ 'write_refunds',+ 'write_gift_cards',+ 'write_store_credits',+ 'read_customers',+ ],+ },+ {+ key: 'merchandiser',+ permissions: ['write_products', 'write_categories', 'write_collections', 'write_stock'],+ },+ {+ key: 'support',+ permissions: ['read_orders', 'read_customers', 'read_dashboard'],+ },+]++/**+ * Create / duplicate / edit a staff role. One sheet drives all three: pass+ * `roleId` to edit, `duplicateFromId` to pre-fill a new role from an existing+ * one, or neither for a blank role.+ */+export function RoleSheet({+ open,+ roleId,+ duplicateFromId,+ onOpenChange,+}: {+ open: boolean+ roleId?: string+ duplicateFromId?: string+ onOpenChange: (open: boolean) => void+}) {+ const { t } = useTranslation()+ const { data: catalog } = usePermissionCatalog()+ const { permissions, permissionKeys } = usePermissions()+ const { data: role, isLoading } = useRole(roleId ?? '')+ const { data: source } = useRole(duplicateFromId ?? '')+ const createMutation = useCreateRole()+ const updateMutation = useUpdateRole()++ const form = useForm<RoleFormValues>({+ resolver: zodResolver(roleSchema),+ defaultValues: ROLE_DEFAULTS,+ })++ const isEditing = !!roleId+ // Protected roles (admin, host-locked) and callers without update authority+ // get a read-only sheet — the server enforces both independently.+ const readOnly = isEditing+ ? !role?.mutable || permissions.cannot('update', 'Spree::Role')+ : permissions.cannot('create', 'Spree::Role')++ // Populate from the edited role, or from the duplicate source.+ useEffect(() => {+ if (role) {+ form.reset({+ name: role.name,+ description: role.description ?? '',+ permissions: role.name === 'admin' ? [] : role.permissions,+ })+ return+ }+ if (source) {+ form.reset({+ name: t('admin.roles.duplicate_name', { name: source.name }),+ description: source.description ?? '',+ permissions: source.permissions,+ })+ }+ }, [role, source, form, t])++ // Keys the current admin cannot grant (the API would reject them) render+ // disabled. An admin holding the full catalog is never restricted.+ const blockedKeys = useMemo(() => {+ if (!catalog) return undefined+ const blocked = new Set(+ catalog.data.filter((entry) => !permissionKeys.includes(entry.key)).map((entry) => entry.key),+ )+ return blocked.size > 0 ? blocked : undefined+ }, [catalog, permissionKeys])++ function applyPreset(keys: string[]) {+ form.setValue(+ 'permissions',+ keys.filter((key) => permissionKeys.includes(key)),+ { shouldDirty: true },+ )+ }++ async function onSubmit(values: RoleFormValues) {+ const params = {+ name: values.name,+ description: values.description || null,+ permissions: values.permissions,+ }++ try {+ if (roleId) {+ await updateMutation.mutateAsync({ id: roleId, params })+ toast.success(t('admin.roles.messages.updated'))+ } else {+ await createMutation.mutateAsync(params)+ toast.success(t('admin.roles.messages.created'))+ }+ form.reset(ROLE_DEFAULTS)+ onOpenChange(false)+ } catch (err) {+ if (mapSpreeErrorsToForm(err, form.setError)) return+ if (err instanceof SpreeError) {+ toast.error(err.message)+ return+ }+ toast.error(t('admin.roles.errors.failed_to_save'))+ }+ }++ return (+ <Sheet+ open={open}+ onOpenChange={(next) => {+ if (!next) form.reset(ROLE_DEFAULTS)+ onOpenChange(next)+ }}+ >+ <SheetContent>+ <SheetHeader>+ <SheetTitle className="flex items-center gap-2">+ <span className="capitalize">+ {isEditing+ ? (role?.name ?? t('admin.pages.roles.edit_sheet_title'))+ : t('admin.pages.roles.new_title')}+ </span>+ {readOnly && <Badge variant="secondary">{t('admin.roles.badges.protected')}</Badge>}+ </SheetTitle>+ <SheetDescription>+ {readOnly ? t('admin.roles.form.locked_hint') : t('admin.roles.form.description')}+ </SheetDescription>+ </SheetHeader>++ {isEditing && isLoading ? (+ <div className="flex flex-col gap-3 p-4">+ <Skeleton className="h-9 w-full" />+ <Skeleton className="h-32 w-full" />+ </div>+ ) : (+ <form onSubmit={form.handleSubmit(onSubmit)} className="flex min-h-0 flex-1 flex-col">+ <div className="flex flex-1 flex-col gap-4 overflow-y-auto p-4">+ {form.formState.errors.root?.message && (+ <p className="text-sm text-destructive" role="alert">+ {form.formState.errors.root.message}+ </p>+ )}++ {!isEditing && (+ <Field>+ <FieldLabel>{t('admin.roles.templates.start_from')}</FieldLabel>+ <div className="flex flex-wrap gap-2">+ {ROLE_TEMPLATES.map((template) => (+ <Button+ key={template.key}+ type="button"+ variant="outline"+ size="sm"+ onClick={() => {+ applyPreset(template.permissions)+ if (!form.getValues('name')) {+ form.setValue('name', t(`admin.roles.templates.${template.key}`))+ }+ }}+ >+ {t(`admin.roles.templates.${template.key}`)}+ </Button>+ ))}+ </div>+ </Field>+ )}++ <Field>+ <FieldLabel htmlFor="role-name">{t('admin.fields.role.name.label')}</FieldLabel>+ <Input+ id="role-name"+ placeholder={t('admin.fields.role.name.placeholder')}+ disabled={readOnly}+ aria-invalid={!!form.formState.errors.name || undefined}+ {...form.register('name')}+ />+ <FieldError errors={[form.formState.errors.name]} />+ </Field>++ <Field>+ <FieldLabel htmlFor="role-description">+ {t('admin.fields.role.description.label')}+ </FieldLabel>+ <Textarea+ id="role-description"+ rows={2}+ placeholder={t('admin.fields.role.description.placeholder')}+ disabled={readOnly}+ {...form.register('description')}+ />+ </Field>++ <Field>+ <div className="flex items-center justify-between">+ <FieldLabel>{t('admin.roles.form.permissions_section')}</FieldLabel>+ {!readOnly && catalog && (+ <div className="flex gap-1">+ <Button+ type="button"+ variant="ghost"+ size="sm"+ onClick={() => applyPreset(allReadKeys(catalog.data))}+ >+ {t('admin.roles.presets.read_only')}+ </Button>+ <Button+ type="button"+ variant="ghost"+ size="sm"+ onClick={() => applyPreset(allWriteKeys(catalog.data))}+ >+ {t('admin.roles.presets.full_access')}+ </Button>+ <Button+ type="button"+ variant="ghost"+ size="sm"+ onClick={() => applyPreset([])}+ >+ {t('admin.roles.presets.clear')}+ </Button>+ </div>+ )}+ </div>+ {catalog ? (+ <Controller+ name="permissions"+ control={form.control}+ render={({ field }) => (+ <PermissionGrid+ entries={catalog.data}+ value={field.value}+ onChange={field.onChange}+ disabled={readOnly}+ disabledKeys={blockedKeys}+ />+ )}+ />+ ) : (+ <div className="flex flex-col gap-2">+ <Skeleton className="h-8 w-full" />+ <Skeleton className="h-8 w-full" />+ </div>+ )}+ </Field>+ </div>++ <SheetFooter>+ <Button+ type="button"+ variant="outline"+ size="sm"+ onClick={() => onOpenChange(false)}+ disabled={form.formState.isSubmitting}+ >+ {t('admin.actions.cancel')}+ </Button>+ {!readOnly && (+ <Button type="submit" size="sm" disabled={form.formState.isSubmitting}>+ {form.formState.isSubmitting+ ? t('admin.actions.saving')+ : t('admin.actions.save')}+ </Button>+ )}+ </SheetFooter>+ </form>+ )}+ </SheetContent>+ </Sheet>+ )+}diff --git a/packages/dashboard/src/locales/ar.json b/packages/dashboard/src/locales/ar.jsonindex 61a6fc019f..298bb52ba6 100644--- a/packages/dashboard/src/locales/ar.json+++ b/packages/dashboard/src/locales/ar.json@@ -2239,6 +2239,7 @@},"roles": {"add_cta": "إضافة دور",+ "edit_sheet_title": "تعديل الدور","empty": "لا توجد أدوار بعد","empty_description": "أنشئ دورًا لمنح أعضاء الفريق وصولًا محددًا.","new_title": "دور جديد",@@ -3112,13 +3113,9 @@"failed_to_save": "فشل حفظ الدور"},"form": {- "details_section": "التفاصيل",+ "description": "اختر ما يمكن لهذا الدور عرضه وإدارته.","locked_hint": "هذا الدور محمي ولا يمكن تعديله.",- "members": "الأعضاء",- "more_members": "+{{count}} أخرى",- "permissions_count": "الأذونات",- "permissions_section": "الأذونات",- "summary_section": "الملخص"+ "permissions_section": "الأذونات"},"manage_roles_link": "إدارة الأدوار","messages": {diff --git a/packages/dashboard/src/locales/de.json b/packages/dashboard/src/locales/de.jsonindex 2399b3859d..bc74e0b296 100644--- a/packages/dashboard/src/locales/de.json+++ b/packages/dashboard/src/locales/de.json@@ -2239,6 +2239,7 @@},"roles": {"add_cta": "Rolle hinzufügen",+ "edit_sheet_title": "Rolle bearbeiten","empty": "Noch keine Rollen","empty_description": "Erstelle eine Rolle, um Teammitgliedern gezielten Zugriff zu geben.","new_title": "Neue Rolle",@@ -3106,13 +3107,9 @@"failed_to_save": "Rolle konnte nicht gespeichert werden"},"form": {- "details_section": "Details",+ "description": "Lege fest, was diese Rolle ansehen und verwalten darf.","locked_hint": "Diese Rolle ist geschützt und kann nicht bearbeitet werden.",- "members": "Mitglieder",- "more_members": "+{{count}} weitere",- "permissions_count": "Berechtigungen",- "permissions_section": "Berechtigungen",- "summary_section": "Zusammenfassung"+ "permissions_section": "Berechtigungen"},"manage_roles_link": "Rollen verwalten","messages": {diff --git a/packages/dashboard/src/locales/en.json b/packages/dashboard/src/locales/en.jsonindex 757385fd29..a0a34e804d 100644--- a/packages/dashboard/src/locales/en.json+++ b/packages/dashboard/src/locales/en.json@@ -2239,6 +2239,7 @@},"roles": {"add_cta": "Add role",+ "edit_sheet_title": "Edit role","empty": "No roles yet","empty_description": "Create a role to give staff members scoped access.","new_title": "New role",@@ -3106,13 +3107,9 @@"failed_to_save": "Failed to save role"},"form": {- "details_section": "Details",+ "description": "Choose what this role can view and manage.","locked_hint": "This role is protected and cannot be edited.",- "members": "Members",- "more_members": "+{{count}} more",- "permissions_count": "Permissions",- "permissions_section": "Permissions",- "summary_section": "Summary"+ "permissions_section": "Permissions"},"manage_roles_link": "Manage roles","messages": {diff --git a/packages/dashboard/src/locales/fr.json b/packages/dashboard/src/locales/fr.jsonindex ed0d0b0807..766d348656 100644--- a/packages/dashboard/src/locales/fr.json+++ b/packages/dashboard/src/locales/fr.json@@ -2239,6 +2239,7 @@},"roles": {"add_cta": "Ajouter un rôle",+ "edit_sheet_title": "Modifier le rôle","empty": "Aucun rôle pour le moment","empty_description": "Créez un rôle pour donner un accès ciblé aux membres de l’équipe.","new_title": "Nouveau rôle",@@ -3106,13 +3107,9 @@"failed_to_save": "Échec de l'enregistrement du rôle"},"form": {- "details_section": "Détails",+ "description": "Choisissez ce que ce rôle peut voir et gérer.","locked_hint": "Ce rôle est protégé et ne peut pas être modifié.",- "members": "Membres",- "more_members": "+{{count}} de plus",- "permissions_count": "Permissions",- "permissions_section": "Permissions",- "summary_section": "Résumé"+ "permissions_section": "Permissions"},"manage_roles_link": "Gérer les rôles","messages": {diff --git a/packages/dashboard/src/locales/pl.json b/packages/dashboard/src/locales/pl.jsonindex 7f0c96ef6b..81214897dc 100644--- a/packages/dashboard/src/locales/pl.json+++ b/packages/dashboard/src/locales/pl.json@@ -2265,6 +2265,7 @@},"roles": {"add_cta": "Dodaj rolę",+ "edit_sheet_title": "Edytuj rolę","empty": "Brak ról","empty_description": "Utwórz rolę, aby nadać członkom zespołu ograniczony dostęp.","new_title": "Nowa rola",@@ -3148,13 +3149,9 @@"failed_to_save": "Nie udało się zapisać roli"},"form": {- "details_section": "Szczegóły",+ "description": "Wybierz, co ta rola może przeglądać i którymi obszarami zarządzać.","locked_hint": "Ta rola jest chroniona i nie można jej edytować.",- "members": "Członkowie",- "more_members": "+{{count}} więcej",- "permissions_count": "Uprawnienia",- "permissions_section": "Uprawnienia",- "summary_section": "Podsumowanie"+ "permissions_section": "Uprawnienia"},"manage_roles_link": "Zarządzaj rolami","messages": {diff --git a/packages/dashboard/src/locales/zh-CN.json b/packages/dashboard/src/locales/zh-CN.jsonindex e779b0f6ae..9115acd534 100644--- a/packages/dashboard/src/locales/zh-CN.json+++ b/packages/dashboard/src/locales/zh-CN.json@@ -2239,6 +2239,7 @@},"roles": {"add_cta": "添加角色",+ "edit_sheet_title": "编辑角色","empty": "暂无角色","empty_description": "创建角色,为团队成员授予相应的访问权限。","new_title": "新建角色",@@ -3106,13 +3107,9 @@"failed_to_save": "保存角色失败"},"form": {- "details_section": "详情",+ "description": "选择该角色可以查看和管理的内容。","locked_hint": "该角色受保护,无法编辑。",- "members": "成员",- "more_members": "+{{count}} 位",- "permissions_count": "权限",- "permissions_section": "权限",- "summary_section": "摘要"+ "permissions_section": "权限"},"manage_roles_link": "管理角色","messages": {diff --git a/packages/dashboard/src/routeTree.gen.ts b/packages/dashboard/src/routeTree.gen.tsindex 5f3462a890..ae8227065e 100644--- a/packages/dashboard/src/routeTree.gen.ts+++ b/packages/dashboard/src/routeTree.gen.ts@@ -32,6 +32,7 @@ import { Route as SettingsTaxCategoriesRouteImport } from './routes/_authenticatimport { 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'+import { Route as SettingsRolesRouteImport } from './routes/_authenticated/$storeId/settings/roles'import { Route as SettingsReasonsRouteImport } from './routes/_authenticated/$storeId/settings/reasons'import { Route as SettingsProductTypesRouteImport } from './routes/_authenticated/$storeId/settings/product-types'import { Route as SettingsPaymentMethodsRouteImport } from './routes/_authenticated/$storeId/settings/payment-methods'@@ -56,14 +57,11 @@ import { Route as OrdersOrderIdRouteImport } from './routes/_authenticated/$storimport { Route as CustomersGroupsRouteImport } from './routes/_authenticated/$storeId/customers/groups'import { Route as CustomersCustomerIdRouteImport } from './routes/_authenticated/$storeId/customers/$customerId'import { Route as SettingsWebhooksIndexRouteImport } from './routes/_authenticated/$storeId/settings/webhooks/index'-import { Route as SettingsRolesIndexRouteImport } from './routes/_authenticated/$storeId/settings/roles/index'import { Route as SettingsImportsIndexRouteImport } from './routes/_authenticated/$storeId/settings/imports/index'import { Route as ProductsPriceListsIndexRouteImport } from './routes/_authenticated/$storeId/products/price-lists/index'import { Route as ProductsCollectionsIndexRouteImport } from './routes/_authenticated/$storeId/products/collections/index'import { Route as ProductsCategoriesIndexRouteImport } from './routes/_authenticated/$storeId/products/categories/index'import { Route as SettingsWebhooksWebhookEndpointIdRouteImport } from './routes/_authenticated/$storeId/settings/webhooks/$webhookEndpointId'-import { Route as SettingsRolesNewRouteImport } from './routes/_authenticated/$storeId/settings/roles/new'-import { Route as SettingsRolesRoleIdRouteImport } from './routes/_authenticated/$storeId/settings/roles/$roleId'import { Route as ProductsPriceListsNewRouteImport } from './routes/_authenticated/$storeId/products/price-lists/new'import { Route as ProductsCollectionsNewRouteImport } from './routes/_authenticated/$storeId/products/collections/new'import { Route as ProductsCollectionsCollectionIdRouteImport } from './routes/_authenticated/$storeId/products/collections/$collectionId'@@ -186,6 +184,11 @@ const SettingsStaffRoute = SettingsStaffRouteImport.update({path: '/staff',getParentRoute: () => SettingsRoute,} as any)+const SettingsRolesRoute = SettingsRolesRouteImport.update({+ id: '/roles',+ path: '/roles',+ getParentRoute: () => SettingsRoute,+} as any)const SettingsReasonsRoute = SettingsReasonsRouteImport.update({id: '/reasons',path: '/reasons',@@ -307,11 +310,6 @@ const SettingsWebhooksIndexRoute = SettingsWebhooksIndexRouteImport.update({path: '/webhooks/',getParentRoute: () => SettingsRoute,} as any)-const SettingsRolesIndexRoute = SettingsRolesIndexRouteImport.update({- id: '/roles/',- path: '/roles/',- getParentRoute: () => SettingsRoute,-} as any)const SettingsImportsIndexRoute = SettingsImportsIndexRouteImport.update({id: '/imports/',path: '/imports/',@@ -339,16 +337,6 @@ const SettingsWebhooksWebhookEndpointIdRoute =path: '/webhooks/$webhookEndpointId',getParentRoute: () => SettingsRoute,} as any)-const SettingsRolesNewRoute = SettingsRolesNewRouteImport.update({- id: '/roles/new',- path: '/roles/new',- getParentRoute: () => SettingsRoute,-} as any)-const SettingsRolesRoleIdRoute = SettingsRolesRoleIdRouteImport.update({- id: '/roles/$roleId',- path: '/roles/$roleId',- getParentRoute: () => SettingsRoute,-} as any)const ProductsPriceListsNewRoute = ProductsPriceListsNewRouteImport.update({id: '/products/price-lists/new',path: '/products/price-lists/new',@@ -420,6 +408,7 @@ export interface FileRoutesByFullPath {'/$storeId/settings/payment-methods': typeof SettingsPaymentMethodsRoute'/$storeId/settings/product-types': typeof SettingsProductTypesRoute'/$storeId/settings/reasons': typeof SettingsReasonsRoute+ '/$storeId/settings/roles': typeof SettingsRolesRoute'/$storeId/settings/staff': typeof SettingsStaffRoute'/$storeId/settings/stock-locations': typeof SettingsStockLocationsRoute'/$storeId/settings/store': typeof SettingsStoreRoute@@ -434,14 +423,11 @@ export interface FileRoutesByFullPath {'/$storeId/products/collections/$collectionId': typeof ProductsCollectionsCollectionIdRoute'/$storeId/products/collections/new': typeof ProductsCollectionsNewRoute'/$storeId/products/price-lists/new': typeof ProductsPriceListsNewRoute- '/$storeId/settings/roles/$roleId': typeof SettingsRolesRoleIdRoute- '/$storeId/settings/roles/new': typeof SettingsRolesNewRoute'/$storeId/settings/webhooks/$webhookEndpointId': typeof SettingsWebhooksWebhookEndpointIdRoute'/$storeId/products/categories/': typeof ProductsCategoriesIndexRoute'/$storeId/products/collections/': typeof ProductsCollectionsIndexRoute'/$storeId/products/price-lists/': typeof ProductsPriceListsIndexRoute'/$storeId/settings/imports/': typeof SettingsImportsIndexRoute- '/$storeId/settings/roles/': typeof SettingsRolesIndexRoute'/$storeId/settings/webhooks/': typeof SettingsWebhooksIndexRoute'/$storeId/products/price-lists/$priceListId/': typeof ProductsPriceListsPriceListIdIndexRoute}@@ -480,6 +466,7 @@ export interface FileRoutesByTo {'/$storeId/settings/payment-methods': typeof SettingsPaymentMethodsRoute'/$storeId/settings/product-types': typeof SettingsProductTypesRoute'/$storeId/settings/reasons': typeof SettingsReasonsRoute+ '/$storeId/settings/roles': typeof SettingsRolesRoute'/$storeId/settings/staff': typeof SettingsStaffRoute'/$storeId/settings/stock-locations': typeof SettingsStockLocationsRoute'/$storeId/settings/store': typeof SettingsStoreRoute@@ -494,14 +481,11 @@ export interface FileRoutesByTo {'/$storeId/products/collections/$collectionId': typeof ProductsCollectionsCollectionIdRoute'/$storeId/products/collections/new': typeof ProductsCollectionsNewRoute'/$storeId/products/price-lists/new': typeof ProductsPriceListsNewRoute- '/$storeId/settings/roles/$roleId': typeof SettingsRolesRoleIdRoute- '/$storeId/settings/roles/new': typeof SettingsRolesNewRoute'/$storeId/settings/webhooks/$webhookEndpointId': typeof SettingsWebhooksWebhookEndpointIdRoute'/$storeId/products/categories': typeof ProductsCategoriesIndexRoute'/$storeId/products/collections': typeof ProductsCollectionsIndexRoute'/$storeId/products/price-lists': typeof ProductsPriceListsIndexRoute'/$storeId/settings/imports': typeof SettingsImportsIndexRoute- '/$storeId/settings/roles': typeof SettingsRolesIndexRoute'/$storeId/settings/webhooks': typeof SettingsWebhooksIndexRoute'/$storeId/products/price-lists/$priceListId': typeof ProductsPriceListsPriceListIdIndexRoute}@@ -544,6 +528,7 @@ export interface FileRoutesById {'/_authenticated/$storeId/settings/payment-methods': typeof SettingsPaymentMethodsRoute'/_authenticated/$storeId/settings/product-types': typeof SettingsProductTypesRoute'/_authenticated/$storeId/settings/reasons': typeof SettingsReasonsRoute+ '/_authenticated/$storeId/settings/roles': typeof SettingsRolesRoute'/_authenticated/$storeId/settings/staff': typeof SettingsStaffRoute'/_authenticated/$storeId/settings/stock-locations': typeof SettingsStockLocationsRoute'/_authenticated/$storeId/settings/store': typeof SettingsStoreRoute@@ -558,14 +543,11 @@ export interface FileRoutesById {'/_authenticated/$storeId/products/collections/$collectionId': typeof ProductsCollectionsCollectionIdRoute'/_authenticated/$storeId/products/collections/new': typeof ProductsCollectionsNewRoute'/_authenticated/$storeId/products/price-lists/new': typeof ProductsPriceListsNewRoute- '/_authenticated/$storeId/settings/roles/$roleId': typeof SettingsRolesRoleIdRoute- '/_authenticated/$storeId/settings/roles/new': typeof SettingsRolesNewRoute'/_authenticated/$storeId/settings/webhooks/$webhookEndpointId': typeof SettingsWebhooksWebhookEndpointIdRoute'/_authenticated/$storeId/products/categories/': typeof ProductsCategoriesIndexRoute'/_authenticated/$storeId/products/collections/': typeof ProductsCollectionsIndexRoute'/_authenticated/$storeId/products/price-lists/': typeof ProductsPriceListsIndexRoute'/_authenticated/$storeId/settings/imports/': typeof SettingsImportsIndexRoute- '/_authenticated/$storeId/settings/roles/': typeof SettingsRolesIndexRoute'/_authenticated/$storeId/settings/webhooks/': typeof SettingsWebhooksIndexRoute'/_authenticated/$storeId/products/price-lists/$priceListId/': typeof ProductsPriceListsPriceListIdIndexRoute}@@ -608,6 +590,7 @@ export interface FileRouteTypes {| '/$storeId/settings/payment-methods'| '/$storeId/settings/product-types'| '/$storeId/settings/reasons'+ | '/$storeId/settings/roles'| '/$storeId/settings/staff'| '/$storeId/settings/stock-locations'| '/$storeId/settings/store'@@ -622,14 +605,11 @@ export interface FileRouteTypes {| '/$storeId/products/collections/$collectionId'| '/$storeId/products/collections/new'| '/$storeId/products/price-lists/new'- | '/$storeId/settings/roles/$roleId'- | '/$storeId/settings/roles/new'| '/$storeId/settings/webhooks/$webhookEndpointId'| '/$storeId/products/categories/'| '/$storeId/products/collections/'| '/$storeId/products/price-lists/'| '/$storeId/settings/imports/'- | '/$storeId/settings/roles/'| '/$storeId/settings/webhooks/'| '/$storeId/products/price-lists/$priceListId/'fileRoutesByTo: FileRoutesByTo@@ -668,6 +648,7 @@ export interface FileRouteTypes {| '/$storeId/settings/payment-methods'| '/$storeId/settings/product-types'| '/$storeId/settings/reasons'+ | '/$storeId/settings/roles'| '/$storeId/settings/staff'| '/$storeId/settings/stock-locations'| '/$storeId/settings/store'@@ -682,14 +663,11 @@ export interface FileRouteTypes {| '/$storeId/products/collections/$collectionId'| '/$storeId/products/collections/new'| '/$storeId/products/price-lists/new'- | '/$storeId/settings/roles/$roleId'- | '/$storeId/settings/roles/new'| '/$storeId/settings/webhooks/$webhookEndpointId'| '/$storeId/products/categories'| '/$storeId/products/collections'| '/$storeId/products/price-lists'| '/$storeId/settings/imports'- | '/$storeId/settings/roles'| '/$storeId/settings/webhooks'| '/$storeId/products/price-lists/$priceListId'id:@@ -731,6 +709,7 @@ export interface FileRouteTypes {| '/_authenticated/$storeId/settings/payment-methods'| '/_authenticated/$storeId/settings/product-types'| '/_authenticated/$storeId/settings/reasons'+ | '/_authenticated/$storeId/settings/roles'| '/_authenticated/$storeId/settings/staff'| '/_authenticated/$storeId/settings/stock-locations'| '/_authenticated/$storeId/settings/store'@@ -745,14 +724,11 @@ export interface FileRouteTypes {| '/_authenticated/$storeId/products/collections/$collectionId'| '/_authenticated/$storeId/products/collections/new'| '/_authenticated/$storeId/products/price-lists/new'- | '/_authenticated/$storeId/settings/roles/$roleId'- | '/_authenticated/$storeId/settings/roles/new'| '/_authenticated/$storeId/settings/webhooks/$webhookEndpointId'| '/_authenticated/$storeId/products/categories/'| '/_authenticated/$storeId/products/collections/'| '/_authenticated/$storeId/products/price-lists/'| '/_authenticated/$storeId/settings/imports/'- | '/_authenticated/$storeId/settings/roles/'| '/_authenticated/$storeId/settings/webhooks/'| '/_authenticated/$storeId/products/price-lists/$priceListId/'fileRoutesById: FileRoutesById@@ -928,6 +904,13 @@ declare module '@tanstack/react-router' {preLoaderRoute: typeof SettingsStaffRouteImportparentRoute: typeof SettingsRoute}+ '/_authenticated/$storeId/settings/roles': {+ id: '/_authenticated/$storeId/settings/roles'+ path: '/roles'+ fullPath: '/$storeId/settings/roles'+ preLoaderRoute: typeof SettingsRolesRouteImport+ parentRoute: typeof SettingsRoute+ }'/_authenticated/$storeId/settings/reasons': {id: '/_authenticated/$storeId/settings/reasons'path: '/reasons'@@ -1096,13 +1079,6 @@ declare module '@tanstack/react-router' {preLoaderRoute: typeof SettingsWebhooksIndexRouteImportparentRoute: typeof SettingsRoute}- '/_authenticated/$storeId/settings/roles/': {- id: '/_authenticated/$storeId/settings/roles/'- path: '/roles'- fullPath: '/$storeId/settings/roles/'- preLoaderRoute: typeof SettingsRolesIndexRouteImport- parentRoute: typeof SettingsRoute- }'/_authenticated/$storeId/settings/imports/': {id: '/_authenticated/$storeId/settings/imports/'path: '/imports'@@ -1138,20 +1114,6 @@ declare module '@tanstack/react-router' {preLoaderRoute: typeof SettingsWebhooksWebhookEndpointIdRouteImportparentRoute: typeof SettingsRoute}- '/_authenticated/$storeId/settings/roles/new': {- id: '/_authenticated/$storeId/settings/roles/new'- path: '/roles/new'- fullPath: '/$storeId/settings/roles/new'- preLoaderRoute: typeof SettingsRolesNewRouteImport- parentRoute: typeof SettingsRoute- }- '/_authenticated/$storeId/settings/roles/$roleId': {- id: '/_authenticated/$storeId/settings/roles/$roleId'- path: '/roles/$roleId'- fullPath: '/$storeId/settings/roles/$roleId'- preLoaderRoute: typeof SettingsRolesRoleIdRouteImport- parentRoute: typeof SettingsRoute- }'/_authenticated/$storeId/products/price-lists/new': {id: '/_authenticated/$storeId/products/price-lists/new'path: '/products/price-lists/new'@@ -1209,16 +1171,14 @@ interface SettingsRouteChildren {SettingsPaymentMethodsRoute: typeof SettingsPaymentMethodsRouteSettingsProductTypesRoute: typeof SettingsProductTypesRouteSettingsReasonsRoute: typeof SettingsReasonsRoute+ SettingsRolesRoute: typeof SettingsRolesRouteSettingsStaffRoute: typeof SettingsStaffRouteSettingsStockLocationsRoute: typeof SettingsStockLocationsRouteSettingsStoreRoute: typeof SettingsStoreRouteSettingsTaxCategoriesRoute: typeof SettingsTaxCategoriesRouteSettingsIndexRoute: typeof SettingsIndexRoute- SettingsRolesRoleIdRoute: typeof SettingsRolesRoleIdRoute- SettingsRolesNewRoute: typeof SettingsRolesNewRouteSettingsWebhooksWebhookEndpointIdRoute: typeof SettingsWebhooksWebhookEndpointIdRouteSettingsImportsIndexRoute: typeof SettingsImportsIndexRoute- SettingsRolesIndexRoute: typeof SettingsRolesIndexRouteSettingsWebhooksIndexRoute: typeof SettingsWebhooksIndexRoute}@@ -1234,17 +1194,15 @@ const SettingsRouteChildren: SettingsRouteChildren = {SettingsPaymentMethodsRoute: SettingsPaymentMethodsRoute,SettingsProductTypesRoute: SettingsProductTypesRoute,SettingsReasonsRoute: SettingsReasonsRoute,+ SettingsRolesRoute: SettingsRolesRoute,SettingsStaffRoute: SettingsStaffRoute,SettingsStockLocationsRoute: SettingsStockLocationsRoute,SettingsStoreRoute: SettingsStoreRoute,SettingsTaxCategoriesRoute: SettingsTaxCategoriesRoute,SettingsIndexRoute: SettingsIndexRoute,- SettingsRolesRoleIdRoute: SettingsRolesRoleIdRoute,- SettingsRolesNewRoute: SettingsRolesNewRoute,SettingsWebhooksWebhookEndpointIdRoute:SettingsWebhooksWebhookEndpointIdRoute,SettingsImportsIndexRoute: SettingsImportsIndexRoute,- SettingsRolesIndexRoute: SettingsRolesIndexRoute,SettingsWebhooksIndexRoute: SettingsWebhooksIndexRoute,}diff --git a/packages/dashboard/src/routes/_authenticated/$storeId/settings/roles/index.tsx b/packages/dashboard/src/routes/_authenticated/$storeId/settings/roles.tsxsimilarity index 75%rename from packages/dashboard/src/routes/_authenticated/$storeId/settings/roles/index.tsxrename to packages/dashboard/src/routes/_authenticated/$storeId/settings/roles.tsxindex 21f7b56db8..74192eb7e0 100644--- a/packages/dashboard/src/routes/_authenticated/$storeId/settings/roles/index.tsx+++ b/packages/dashboard/src/routes/_authenticated/$storeId/settings/roles.tsx@@ -24,21 +24,48 @@ import { createFileRoute, useNavigate } from '@tanstack/react-router'import { CopyIcon, LockIcon, PlusIcon, ShieldIcon } from 'lucide-react'import { useTranslation } from 'react-i18next'import { toast } from 'sonner'-import { permissionKeyLabel } from '../../../../../components/spree/permission-picker'-import { useDeleteRole, usePermissionCatalog, useRoles } from '../../../../../hooks/use-roles'+import { z } from 'zod/v4'+import { permissionKeyLabel } from '../../../../components/spree/permission-picker'+import { RoleSheet } from '../../../../components/spree/role-sheet'+import { useDeleteRole, usePermissionCatalog, useRoles } from '../../../../hooks/use-roles'-export const Route = createFileRoute('/_authenticated/$storeId/settings/roles/')({+// `edit` carries the role being edited, `new` opens an empty sheet, and+// `from` pre-fills a new role from an existing one (duplicate).+const rolesSearchSchema = z.object({+ edit: z.string().optional(),+ new: z.coerce.boolean().optional(),+ from: z.string().optional(),+})++export const Route = createFileRoute('/_authenticated/$storeId/settings/roles')({+ validateSearch: rolesSearchSchema,component: RolesSettingsPage,})function RolesSettingsPage() {const { t } = useTranslation()const navigate = useNavigate()- const { storeId } = Route.useParams()+ const search = Route.useSearch()const { permissions } = usePermissions()const { data, isLoading } = useRoles()const roles = data?.data ?? []+ const closeSheet = () =>+ navigate({+ search: (prev: Record<string, unknown>) => {+ const { edit: _edit, new: _new, from: _from, ...rest } = prev+ return rest as never+ },+ })++ const openCreate = (from?: string) =>+ navigate({+ search: (prev: Record<string, unknown>) => ({ ...prev, new: true, from }) as never,+ })++ const openEdit = (id: string) =>+ navigate({ search: (prev: Record<string, unknown>) => ({ ...prev, edit: id }) as never })+return (<div className="flex flex-col gap-6"><PageHeader@@ -46,10 +73,7 @@ function RolesSettingsPage() {subtitle={t('admin.pages.roles.subtitle')}actions={permissions.can('create', 'Spree::Role') && (- <Button- size="sm"- onClick={() => navigate({ to: '/$storeId/settings/roles/new', params: { storeId } })}- >+ <Button size="sm" onClick={() => openCreate()}><PlusIcon className="size-4" />{t('admin.pages.roles.add_cta')}</Button>@@ -86,32 +110,45 @@ function RolesSettingsPage() {</TableHeader><TableBody>{roles.map((role) => (- <RoleRow key={role.id} role={role} />+ <RoleRow+ key={role.id}+ role={role}+ onEdit={() => openEdit(role.id)}+ onDuplicate={() => openCreate(role.id)}+ />))}</TableBody></Table>)}</CardContent></Card>++ {(search.new || search.edit) && (+ <RoleSheet+ open+ roleId={search.edit}+ duplicateFromId={search.new ? search.from : undefined}+ onOpenChange={(next) => !next && closeSheet()}+ />+ )}</div>)}-function RoleRow({ role }: { role: Role }) {+function RoleRow({+ role,+ onEdit,+ onDuplicate,+}: {+ role: Role+ onEdit: () => void+ onDuplicate: () => void+}) {const { t } = useTranslation()- const navigate = useNavigate()- const { storeId } = Route.useParams()const { permissions } = usePermissions()const deleteMutation = useDeleteRole()const confirm = useConfirm()- function openEditor() {- navigate({- to: '/$storeId/settings/roles/$roleId',- params: { storeId, roleId: role.id },- })- }-async function handleDelete() {const ok = await confirm({title: t('admin.roles.confirm.delete_title'),@@ -130,7 +167,7 @@ function RoleRow({ role }: { role: Role }) {}return (- <TableRow className="cursor-pointer" onClick={openEditor}>+ <TableRow className="cursor-pointer" onClick={onEdit}><TableCell><div className="flex flex-col"><span className="flex items-center gap-1.5 font-medium capitalize">@@ -151,18 +188,13 @@ function RoleRow({ role }: { role: Role }) {<TableCell className="text-right" onClick={(event) => event.stopPropagation()}><RowActionsactions={[- { key: 'edit', onSelect: openEditor },+ { key: 'edit', onSelect: onEdit },{key: 'duplicate',label: t('admin.actions.duplicate'),icon: <CopyIcon className="size-4" />,visible: permissions.can('create', 'Spree::Role'),- onSelect: () =>- navigate({- to: '/$storeId/settings/roles/new',- params: { storeId },- search: { from: role.id },- }),+ onSelect: onDuplicate,},{key: 'delete',diff --git a/packages/dashboard/src/routes/_authenticated/$storeId/settings/roles/$roleId.tsx b/packages/dashboard/src/routes/_authenticated/$storeId/settings/roles/$roleId.tsxdeleted file mode 100644index ca52c90a4d..0000000000--- a/packages/dashboard/src/routes/_authenticated/$storeId/settings/roles/$roleId.tsx+++ /dev/null@@ -1,104 +0,0 @@-import { PageHeader, usePermissions } from '@spree/dashboard-core'-import { Badge, Button, ErrorState, Skeleton } from '@spree/dashboard-ui'-import { createFileRoute, useNavigate } from '@tanstack/react-router'-import { useEffect } from 'react'-import { useTranslation } from 'react-i18next'-import { toast } from 'sonner'-import { RoleFormFields, submitRole, useRoleForm } from '../../../../../components/spree/role-form'-import { useDeleteRole, useRole, useUpdateRole } from '../../../../../hooks/use-roles'--export const Route = createFileRoute('/_authenticated/$storeId/settings/roles/$roleId')({- component: EditRolePage,-})--function EditRolePage() {- const { t } = useTranslation()- const navigate = useNavigate()- const { storeId, roleId } = Route.useParams()- const { permissions } = usePermissions()- const { data: role, isLoading, isError } = useRole(roleId)- const updateMutation = useUpdateRole()- const deleteMutation = useDeleteRole()-- const form = useRoleForm()-- // Populate once the role loads (and after refetches while pristine).- useEffect(() => {- if (!role || form.formState.isDirty) return- form.reset({- name: role.name,- description: role.description ?? '',- permissions: role.name === 'admin' ? [] : role.permissions,- })- }, [role, form])-- const handleSubmit = submitRole(form, async (values) => {- await updateMutation.mutateAsync({- id: roleId,- params: {- name: values.name,- description: values.description || null,- permissions: values.permissions,- },- })- toast.success(t('admin.roles.messages.updated'))- form.reset(values)- })-- async function handleDelete() {- try {- await deleteMutation.mutateAsync(roleId)- toast.success(t('admin.roles.messages.deleted'))- navigate({ to: '/$storeId/settings/roles', params: { storeId } })- } catch (err) {- toast.error(err instanceof Error ? err.message : t('admin.roles.errors.failed_to_delete'))- }- }-- if (isError) {- return <ErrorState />- }-- if (isLoading || !role) {- return (- <div className="flex flex-col gap-4">- <Skeleton className="h-10 w-64" />- <Skeleton className="h-64 w-full" />- </div>- )- }-- const readOnly = !role.mutable || permissions.cannot('update', 'Spree::Role')-- return (- <div className="flex flex-col gap-6">- <PageHeader- title={<span className="capitalize">{role.name}</span>}- subtitle={role.description ?? undefined}- backTo={`/${storeId}/settings/roles`}- badges={- readOnly ? <Badge variant="secondary">{t('admin.roles.badges.protected')}</Badge> : null- }- resource={role}- onDelete={- role.mutable && role.users_count === 0 && permissions.can('destroy', 'Spree::Role')- ? handleDelete- : undefined- }- actions={- !readOnly && (- <Button- size="sm"- onClick={handleSubmit}- disabled={form.formState.isSubmitting || !form.formState.isDirty}- >- {form.formState.isSubmitting ? t('admin.actions.saving') : t('admin.actions.save')}- </Button>- )- }- />-- <RoleFormFields form={form} role={role} readOnly={readOnly} />- </div>- )-}diff --git a/packages/dashboard/src/routes/_authenticated/$storeId/settings/roles/new.tsx b/packages/dashboard/src/routes/_authenticated/$storeId/settings/roles/new.tsxdeleted file mode 100644index c590dd5bb1..0000000000--- a/packages/dashboard/src/routes/_authenticated/$storeId/settings/roles/new.tsx+++ /dev/null@@ -1,97 +0,0 @@-import { PageHeader } from '@spree/dashboard-core'-import { Button } from '@spree/dashboard-ui'-import { createFileRoute, useNavigate } from '@tanstack/react-router'-import { useEffect } from 'react'-import { useTranslation } from 'react-i18next'-import { toast } from 'sonner'-import { z } from 'zod/v4'-import {- ROLE_TEMPLATES,- RoleFormFields,- submitRole,- useRoleForm,-} from '../../../../../components/spree/role-form'-import { useCreateRole, useRole } from '../../../../../hooks/use-roles'--// `from` carries the prefixed ID of a role being duplicated — the form-// prefills with its name and permissions once it loads.-const newRoleSearchSchema = z.object({- from: z.string().optional(),-})--export const Route = createFileRoute('/_authenticated/$storeId/settings/roles/new')({- validateSearch: newRoleSearchSchema,- component: NewRolePage,-})--function NewRolePage() {- const { t } = useTranslation()- const navigate = useNavigate()- const { storeId } = Route.useParams()- const { from } = Route.useSearch()- const { data: sourceRole } = useRole(from ?? '')- const createMutation = useCreateRole()-- const form = useRoleForm()-- // Duplicate flow: prefill once the source role arrives. Guarded on a- // pristine form so a user's in-progress edits are never clobbered.- useEffect(() => {- if (!sourceRole || form.formState.isDirty) return- form.reset({- name: t('admin.roles.duplicate_name', { name: sourceRole.name }),- description: sourceRole.description ?? '',- permissions: sourceRole.permissions,- })- }, [sourceRole, form, t])-- const handleSubmit = submitRole(form, async (values) => {- await createMutation.mutateAsync({- name: values.name,- description: values.description || null,- permissions: values.permissions,- })- toast.success(t('admin.roles.messages.created'))- navigate({ to: '/$storeId/settings/roles', params: { storeId } })- })-- return (- <div className="flex flex-col gap-6">- <PageHeader- title={t('admin.pages.roles.new_title')}- backTo={`/${storeId}/settings/roles`}- actions={- <Button size="sm" onClick={handleSubmit} disabled={form.formState.isSubmitting}>- {form.formState.isSubmitting ? t('admin.actions.saving') : t('admin.actions.save')}- </Button>- }- />-- {!from && (- <div className="flex flex-wrap items-center gap-2">- <span className="text-sm text-muted-foreground">- {t('admin.roles.templates.start_from')}- </span>- {ROLE_TEMPLATES.map((template) => (- <Button- key={template.key}- type="button"- variant="outline"- size="sm"- onClick={() => {- form.setValue('permissions', template.permissions, { shouldDirty: true })- if (!form.getValues('name')) {- form.setValue('name', t(`admin.roles.templates.${template.key}`))- }- }}- >- {t(`admin.roles.templates.${template.key}`)}- </Button>- ))}- </div>- )}-- <RoleFormFields form={form} />- </div>- )-}