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