feat(admin): pass current page title from server to AdminTop via props

This commit is contained in:
2026-04-22 17:52:48 -04:00
parent c41172a397
commit 7c92f34245
3 changed files with 10 additions and 8 deletions
+4 -1
View File
@@ -2,7 +2,7 @@ import AdminShell from './components/AdminShell.js';
import AdminPageClient from './AdminPage.client.js';
import { protectAdmin } from './protect.js';
import { buildNavigationSections } from './navigation.js';
import { collectWidgetData } from './registry.js';
import { collectWidgetData, getPage } from './registry.js';
import { logoutAction } from '@zen/core/features/auth/actions';
import { getAppName } from '@zen/core';
import './widgets/index.server.js';
@@ -14,6 +14,8 @@ export default async function AdminPage({ params }) {
const widgetData = await collectWidgetData();
const navigationSections = buildNavigationSections('/');
const slug = resolvedParams?.admin?.[0] || 'dashboard';
const currentPageTitle = getPage(slug)?.title;
return (
<AdminShell
@@ -21,6 +23,7 @@ export default async function AdminPage({ params }) {
onLogout={logoutAction}
appName={appName}
navigationSections={navigationSections}
currentPageTitle={currentPageTitle}
>
<AdminPageClient
params={resolvedParams}
+2 -1
View File
@@ -4,7 +4,7 @@ import { useState } from 'react';
import AdminSidebar from './AdminSidebar.js';
import AdminTop from './AdminTop.js';
export default function AdminShell({ children, user, onLogout, appName, navigationSections }) {
export default function AdminShell({ children, user, onLogout, appName, navigationSections, currentPageTitle }) {
const [isMobileMenuOpen, setIsMobileMenuOpen] = useState(false);
return (
@@ -23,6 +23,7 @@ export default function AdminShell({ children, user, onLogout, appName, navigati
onLogout={onLogout}
appName={appName}
navigationSections={navigationSections}
currentPageTitle={currentPageTitle}
/>
<main className="flex-1 overflow-y-auto bg-neutral-50 dark:bg-black">
<div className="px-8 py-7 pb-32 max-w-[1920px] mx-auto">
+4 -6
View File
@@ -8,7 +8,7 @@ import { useRouter, usePathname } from 'next/navigation';
import { getPages } from '../registry.js';
import { useTheme, getThemeIcon } from '@zen/core/themes';
const AdminTop = ({ isMobileMenuOpen, setIsMobileMenuOpen, user, onLogout, appName = 'ZEN', navigationSections = [] }) => {
const AdminTop = ({ isMobileMenuOpen, setIsMobileMenuOpen, user, onLogout, appName = 'ZEN', navigationSections = [], currentPageTitle }) => {
const router = useRouter();
const pathname = usePathname();
@@ -35,26 +35,24 @@ const AdminTop = ({ isMobileMenuOpen, setIsMobileMenuOpen, user, onLogout, appNa
const ThemeIcon = getThemeIcon(theme, systemIsDark);
const themeLabel = theme === 'light' ? 'Mode clair' : theme === 'dark' ? 'Mode sombre' : 'Thème système';
const getPageTitle = (s) => getPages().find(p => p.slug === s)?.title ?? s;
const buildBreadcrumbs = () => {
const crumbs = [{ icon: DashboardSquare03Icon, href: '/admin/dashboard' }];
const after = pathname.replace(/^\/admin\/?/, '');
if (!after) {
crumbs.push({ label: getPageTitle('dashboard') });
crumbs.push({ label: currentPageTitle });
return crumbs;
}
const segments = after.split('/').filter(Boolean);
if (!segments.length || (segments[0] === 'dashboard' && segments.length === 1)) {
crumbs.push({ label: getPageTitle('dashboard') });
crumbs.push({ label: currentPageTitle });
return crumbs;
}
const [first, second] = segments;
if (first === 'profile') {
crumbs.push({ label: getPageTitle('profile') });
crumbs.push({ label: currentPageTitle });
return crumbs;
}