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
Add a brand detail route to the example plugin
Damian Legawiec2cb35ef66fdc
diff --git a/packages/dashboard-plugin-example/README.md b/packages/dashboard-plugin-example/README.mdindex 3c6b292809..85a5fc24c2 100644--- a/packages/dashboard-plugin-example/README.md+++ b/packages/dashboard-plugin-example/README.md@@ -6,10 +6,10 @@ This package is the runnable companion to the [Dashboard section](../../docs/dev## What it demonstrates-Five extension points, all in one plugin:+Six extension points, all in one plugin:1. **Nav entry** — adds "Brands" to the main sidebar between Products and Customers-2. **Custom route** — `/$storeId/brands` renders a list page using `<ResourceTable>`+2. **Custom routes** — `/$storeId/brands` (list page using `<ResourceTable>`) and `/$storeId/brands/$brandId` (detail page reading the `$brandId` path param)3. **Table definition** — `defineTable('brands', ...)` declares columns, default sort, search params4. **Slot widget** — the product detail page's right sidebar shows a "Brand" card via the `product.form_sidebar` slot5. **Table column extension** — adds a "Brand" column to the existing core Products tablediff --git a/packages/dashboard-plugin-example/src/index.tsx b/packages/dashboard-plugin-example/src/index.tsxindex fa8f0fe14c..af2ab16eb8 100644--- a/packages/dashboard-plugin-example/src/index.tsx+++ b/packages/dashboard-plugin-example/src/index.tsx@@ -35,6 +35,7 @@ import { Link } from '@tanstack/react-router'import { PackageIcon } from 'lucide-react'import { brandsClient } from './client'import en from './locales/en.json'+import { BrandDetailPage } from './routes/brand-detail'import { BrandsListPage } from './routes/brands-list'import { ProductBrandCard } from './slots/product-brand-card'import type { Brand } from './types'@@ -127,6 +128,12 @@ defineDashboardPlugin({component: BrandsListPage,subject: 'Spree::Brand',},+ {+ key: 'brand-detail',+ path: '/brands/$brandId',+ component: BrandDetailPage,+ subject: 'Spree::Brand',+ },],slots: {'product.form_sidebar': [diff --git a/packages/dashboard-plugin-example/src/locales/en.json b/packages/dashboard-plugin-example/src/locales/en.jsonindex 26d8e85756..5512223fe5 100644--- a/packages/dashboard-plugin-example/src/locales/en.json+++ b/packages/dashboard-plugin-example/src/locales/en.json@@ -24,6 +24,10 @@"product_card": {"title": "Brand","empty": "No brand assigned."+ },+ "detail": {+ "about": "About this brand",+ "no_description": "No description yet."}}}diff --git a/packages/dashboard-plugin-example/src/routes/brand-detail.tsx b/packages/dashboard-plugin-example/src/routes/brand-detail.tsxnew file mode 100644index 0000000000..737a9c17f6--- /dev/null+++ b/packages/dashboard-plugin-example/src/routes/brand-detail.tsx@@ -0,0 +1,46 @@+/**+ * Brand detail page. Mounted at `/$storeId/brands/$brandId` via the plugin's+ * route registration in `index.tsx` — the canonical example of a plugin route+ * with a path param. The catch-all dispatcher extracts `$brandId` from the+ * URL and hands it to us via `params`.+ */+import { PageHeader } from '@spree/dashboard-core'+import { Card, CardContent, CardHeader, CardTitle, Skeleton } from '@spree/dashboard-ui'+import { useQuery } from '@tanstack/react-query'+import { useTranslation } from 'react-i18next'+import { brandsClient } from '../client'++interface BrandDetailPageProps {+ params: Record<string, string>+}++export function BrandDetailPage({ params }: BrandDetailPageProps) {+ const { t } = useTranslation()+ const brandId = params.brandId++ const { data: brand, isLoading } = useQuery({+ queryKey: ['plugin-brands', 'brand', brandId],+ queryFn: () => brandsClient.get(brandId),+ })++ if (isLoading || !brand) {+ return <Skeleton className="h-48 w-full rounded-xl" />+ }++ return (+ <div className="flex flex-col gap-6">+ <PageHeader title={brand.name} subtitle={brand.slug} />+ <Card>+ <CardHeader>+ <CardTitle>{t('admin.brands_plugin.detail.about')}</CardTitle>+ </CardHeader>+ <CardContent className="space-y-2 text-sm">+ <p>{brand.description ?? t('admin.brands_plugin.detail.no_description')}</p>+ <p className="text-muted-foreground">+ {t('admin.brands_plugin.fields.products_count')}: {brand.products_count}+ </p>+ </CardContent>+ </Card>+ </div>+ )+}