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.

Share the primary sidebar and fold it in the seller panel's settings

Damian Legawiece243418dea42
diff --git a/packages/dashboard-core/src/components/app-sidebar.tsx b/packages/dashboard-core/src/components/app-sidebar.tsx
index bb1885a817..99e7f26b57 100644
--- a/packages/dashboard-core/src/components/app-sidebar.tsx
+++ b/packages/dashboard-core/src/components/app-sidebar.tsx
@@ -1,7 +1,7 @@
import { Sidebar, SidebarContent, SidebarHeader } from '@spree/dashboard-ui'
import { useParams } from '@tanstack/react-router'
import { PackageIcon } from 'lucide-react'
-import type { ComponentProps } from 'react'
+import type { ComponentProps, ReactNode } from 'react'
import { useAuth } from '../hooks/use-auth'
import { primarySidebarSide, useTranslation } from '../lib/i18n'
import { type NavEntry, resolveNavLabel, useNavEntries } from '../lib/nav-registry'
@@ -76,16 +76,36 @@ export function useNavItems(tenantId: string): { navItems: NavItem[]; bottomItem
return { navItems, bottomItems }
}
-export function AppSidebar(props: ComponentProps<typeof Sidebar>) {
+/**
+ * The primary sidebar: registry-driven nav under a tenant switcher.
+ *
+ * Shared by every panel. The two things that genuinely differ are which
+ * tenant the links are built under and what sits in the header — a store
+ * switcher for the operator, a seller switcher for the marketplace panel — so
+ * both are props. Everything else (side-by-language, collapsible rail,
+ * permission filtering) is the same in either, and a panel that copied this to
+ * change the header would silently miss every later fix to the rest.
+ */
+export function AppSidebar({
+ tenantId,
+ header,
+ ...props
+}: ComponentProps<typeof Sidebar> & {
+ /**
+ * The id the nav links are prefixed with. Defaults to the route's `storeId`,
+ * so the operator's dashboard passes nothing.
+ */
+ tenantId?: string
+ /** Rendered in the header. Defaults to the store switcher. */
+ header?: ReactNode
+}) {
const { i18n } = useTranslation()
const { storeId } = useParams({ strict: false }) as { storeId?: string }
- const { navItems, bottomItems } = useNavItems(storeId || 'default')
+ const { navItems, bottomItems } = useNavItems(tenantId ?? storeId ?? 'default')
return (
<Sidebar collapsible="icon" side={primarySidebarSide(i18n.language)} {...props}>
- <SidebarHeader>
- <StoreSwitcher />
- </SidebarHeader>
+ <SidebarHeader>{header ?? <StoreSwitcher />}</SidebarHeader>
<SidebarContent>
<NavMain items={navItems} bottomItems={bottomItems} />
</SidebarContent>
diff --git a/packages/seller-dashboard/src/panel-chrome.tsx b/packages/seller-dashboard/src/panel-chrome.tsx
index 045b6dd60b..770c3b509a 100644
--- a/packages/seller-dashboard/src/panel-chrome.tsx
+++ b/packages/seller-dashboard/src/panel-chrome.tsx
@@ -1,19 +1,12 @@
import {
- NavMain,
+ AppSidebar,
SettingsSidebar,
StickyHeaderProvider,
TenantProvider,
TopBarUser,
- useNavItems,
+ useAutoCollapseSidebar,
} from '@spree/dashboard-core'
-import {
- Sidebar,
- SidebarContent,
- SidebarHeader,
- SidebarInset,
- SidebarProvider,
- SidebarTrigger,
-} from '@spree/dashboard-ui'
+import { SidebarInset, SidebarProvider, SidebarTrigger } from '@spree/dashboard-ui'
import { useParams, useRouterState } from '@tanstack/react-router'
import type { ReactNode } from 'react'
import { SellerSwitcher } from './components/seller-switcher'
@@ -21,13 +14,10 @@ import { SellerSwitcher } from './components/seller-switcher'
/**
* The panel's frame: the sidebar and a content column under a top bar.
*
- * Built on the same primitives, the same nav registry and the same account
- * menu as the operator's dashboard, so a seller who has used one recognises
- * the other and a fix to the shared pieces reaches both.
- *
- * The store switcher's counterpart is the seller switcher in the header, and
- * the settings rail is the same component reading the same registry — it just
- * slides in under `/settings` here as it does there.
+ * The pieces are the operator dashboard's, not copies of them — `AppSidebar`
+ * takes the tenant and its header as props precisely so a second panel can
+ * reuse it, and the settings rail reads the same registry. A seller who has
+ * used one recognises the other, and a fix to any of it reaches both.
*
* What the operator's chrome has that this does not is the command palette:
* it needs a search surface this panel does not have yet, and mounting the
@@ -35,9 +25,8 @@ import { SellerSwitcher } from './components/seller-switcher'
*/
export function PanelChrome({ children }: { children: ReactNode }) {
const { sellerId } = useParams({ from: '/_authenticated/$sellerId' })
- const { navItems, bottomItems } = useNavItems(sellerId)
const inSettings = useRouterState({
- select: (state) => state.location.pathname.includes('/settings'),
+ select: (state) => state.location.pathname.startsWith(`/${sellerId}/settings`),
})
return (
@@ -47,34 +36,57 @@ export function PanelChrome({ children }: { children: ReactNode }) {
<TenantProvider id={sellerId}>
<StickyHeaderProvider>
<SidebarProvider>
- <Sidebar collapsible="icon">
- <SidebarHeader>
- <SellerSwitcher />
- </SidebarHeader>
- <SidebarContent>
- <NavMain items={navItems} bottomItems={bottomItems} />
- </SidebarContent>
- </Sidebar>
-
- {/* `flex-row` so the settings rail sits flush against the primary
- sidebar and spans full height, as it does in the dashboard. */}
- <SidebarInset className="flex-row">
- <SettingsSidebar open={inSettings} tenantId={sellerId} />
- <div className="flex min-w-0 flex-1 flex-col">
- {/* The account menu carries sign-out, so the sidebar footer no
- longer does. */}
- <header className="flex h-14 shrink-0 items-center gap-2 border-border-subtle border-b px-4">
- <SidebarTrigger />
- <div className="ml-auto flex items-center gap-2">
- <TopBarUser />
- </div>
- </header>
-
- <div className="flex flex-1 flex-col gap-4 p-4 lg:p-6">{children}</div>
- </div>
- </SidebarInset>
+ <PanelShell sellerId={sellerId} inSettings={inSettings}>
+ {children}
+ </PanelShell>
</SidebarProvider>
</StickyHeaderProvider>
</TenantProvider>
)
}
+
+/**
+ * Inside `SidebarProvider` so it can drive the primary nav's collapsed state:
+ * settings brings its own full-width rail, and two stacked columns leave the
+ * content squeezed, so the primary one folds to icons for the duration.
+ */
+function PanelShell({
+ sellerId,
+ inSettings,
+ children,
+}: {
+ sellerId: string
+ inSettings: boolean
+ children: ReactNode
+}) {
+ useAutoCollapseSidebar(inSettings)
+
+ return (
+ <>
+ <AppSidebar tenantId={sellerId} header={<SellerSwitcher />} />
+
+ {/* `flex-row` so the settings rail sits flush against the primary
+ sidebar and spans full height, as it does in the dashboard. */}
+ <SidebarInset className="flex-row">
+ <SettingsSidebar open={inSettings} tenantId={sellerId} />
+ <div className="flex min-w-0 flex-1 flex-col">
+ {/* The account menu carries sign-out, so the sidebar footer no
+ longer does. */}
+ <header className="flex h-14 shrink-0 items-center gap-2 border-border-subtle border-b px-4">
+ <SidebarTrigger />
+ <div className="ml-auto flex items-center gap-2">
+ <TopBarUser />
+ </div>
+ </header>
+
+ {/* Settings pages bring their own padding, matching the dashboard. */}
+ {inSettings ? (
+ children
+ ) : (
+ <div className="flex flex-1 flex-col gap-4 p-4 lg:p-6">{children}</div>
+ )}
+ </div>
+ </SidebarInset>
+ </>
+ )
+}
diff --git a/packages/seller-dashboard/src/routes/_authenticated/$sellerId/settings.tsx b/packages/seller-dashboard/src/routes/_authenticated/$sellerId/settings.tsx
index 93ed8876f5..4a210ed02a 100644
--- a/packages/seller-dashboard/src/routes/_authenticated/$sellerId/settings.tsx
+++ b/packages/seller-dashboard/src/routes/_authenticated/$sellerId/settings.tsx
@@ -4,7 +4,15 @@ export const Route = createFileRoute('/_authenticated/$sellerId/settings')({
component: SettingsLayout,
})
-/** Content padding for the settings area; the sidebar lives in the chrome. */
+/**
+ * Content padding for the settings area. The rail itself lives in the chrome,
+ * one level up, so it can span full height beside the top bar — this layout
+ * owns only the right-hand column, matching the dashboard's settings layout.
+ */
function SettingsLayout() {
- return <Outlet />
+ return (
+ <div className="container mx-auto flex flex-1 flex-col gap-4 p-4 lg:p-6">
+ <Outlet />
+ </div>
+ )
}