feat(admin): sync page title to admin shell via context
This commit is contained in:
@@ -1,6 +1,8 @@
|
|||||||
'use client';
|
'use client';
|
||||||
|
|
||||||
|
import { useEffect } from 'react';
|
||||||
import { getPage } from './registry.js';
|
import { getPage } from './registry.js';
|
||||||
|
import { useAdminPageTitle } from './components/AdminPageTitleContext.js';
|
||||||
import './pages/DashboardPage.client.js';
|
import './pages/DashboardPage.client.js';
|
||||||
import './pages/UsersPage.client.js';
|
import './pages/UsersPage.client.js';
|
||||||
import './pages/RolesPage.client.js';
|
import './pages/RolesPage.client.js';
|
||||||
@@ -9,10 +11,16 @@ import './widgets/index.client.js';
|
|||||||
|
|
||||||
export default function AdminPageClient({ params, user, widgetData }) {
|
export default function AdminPageClient({ params, user, widgetData }) {
|
||||||
const parts = params?.admin || [];
|
const parts = params?.admin || [];
|
||||||
const [first, second, third] = parts;
|
const [first] = parts;
|
||||||
|
|
||||||
const slug = first || 'dashboard';
|
const slug = first || 'dashboard';
|
||||||
const page = getPage(slug) || getPage('dashboard');
|
const page = getPage(slug) || getPage('dashboard');
|
||||||
|
const { setTitle } = useAdminPageTitle();
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
if (page?.title) setTitle(page.title);
|
||||||
|
}, [page?.title]);
|
||||||
|
|
||||||
if (!page) return null;
|
if (!page) return null;
|
||||||
|
|
||||||
const { Component } = page;
|
const { Component } = page;
|
||||||
|
|||||||
@@ -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, getPage } from './registry.js';
|
import { collectWidgetData } 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,8 +14,6 @@ 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
|
||||||
@@ -23,7 +21,6 @@ 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}
|
||||||
|
|||||||
Reference in New Issue
Block a user