refactor(admin): migrate page titles from static map to self-registering pages
This commit is contained in:
@@ -1,7 +1,10 @@
|
||||
'use client';
|
||||
|
||||
import { getPage } from './registry.js';
|
||||
import './pages/index.client.js';
|
||||
import './pages/DashboardPage.client.js';
|
||||
import './pages/UsersPage.client.js';
|
||||
import './pages/RolesPage.client.js';
|
||||
import './pages/ProfilePage.client.js';
|
||||
import './widgets/index.client.js';
|
||||
|
||||
export default function AdminPageClient({ params, user, widgetData }) {
|
||||
|
||||
@@ -6,7 +6,6 @@ import { ChevronDownIcon, User03Icon, DashboardSquare03Icon } from '@zen/core/sh
|
||||
import { UserAvatar } from '@zen/core/shared/components';
|
||||
import { useRouter, usePathname } from 'next/navigation';
|
||||
import { getPages } from '../registry.js';
|
||||
import { PAGE_TITLES } from '../pages/titles.js';
|
||||
import { useTheme, getThemeIcon } from '@zen/core/themes';
|
||||
|
||||
const AdminTop = ({ isMobileMenuOpen, setIsMobileMenuOpen, user, onLogout, appName = 'ZEN', navigationSections = [] }) => {
|
||||
@@ -36,24 +35,26 @@ 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: PAGE_TITLES.dashboard });
|
||||
crumbs.push({ label: getPageTitle('dashboard') });
|
||||
return crumbs;
|
||||
}
|
||||
|
||||
const segments = after.split('/').filter(Boolean);
|
||||
if (!segments.length || (segments[0] === 'dashboard' && segments.length === 1)) {
|
||||
crumbs.push({ label: PAGE_TITLES.dashboard });
|
||||
crumbs.push({ label: getPageTitle('dashboard') });
|
||||
return crumbs;
|
||||
}
|
||||
|
||||
const [first, second] = segments;
|
||||
|
||||
if (first === 'profile') {
|
||||
crumbs.push({ label: PAGE_TITLES.profile });
|
||||
crumbs.push({ label: getPageTitle('profile') });
|
||||
return crumbs;
|
||||
}
|
||||
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
'use client';
|
||||
|
||||
import { getWidgets } from '../registry.js';
|
||||
import { getWidgets, registerPage } from '../registry.js';
|
||||
import AdminHeader from '../components/AdminHeader.js';
|
||||
|
||||
export default function DashboardPage({ stats }) {
|
||||
@@ -18,3 +18,5 @@ export default function DashboardPage({ stats }) {
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
registerPage({ slug: 'dashboard', title: 'Tableau de bord', Component: DashboardPage });
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
'use client';
|
||||
|
||||
import { registerPage } from '../registry.js';
|
||||
import React, { useState, useEffect, useRef } from 'react';
|
||||
import { Card, Input, Button } from '@zen/core/shared/components';
|
||||
import { useToast } from '@zen/core/toast';
|
||||
@@ -320,3 +321,5 @@ const ProfilePage = ({ user: initialUser }) => {
|
||||
};
|
||||
|
||||
export default ProfilePage;
|
||||
|
||||
registerPage({ slug: 'profile', title: 'Mon profil', Component: ProfilePage });
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
'use client';
|
||||
|
||||
import { registerPage } from '../registry.js';
|
||||
import { useState, useEffect } from 'react';
|
||||
import { Card, Table, Button, Badge } from '@zen/core/shared/components';
|
||||
import { PencilEdit01Icon, Cancel01Icon } from '@zen/core/shared/icons';
|
||||
@@ -193,3 +194,5 @@ const RolesPageHeader = () => {
|
||||
};
|
||||
|
||||
export default RolesPage;
|
||||
|
||||
registerPage({ slug: 'roles', title: 'Rôles', Component: RolesPage });
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
'use client';
|
||||
|
||||
import { registerPage } from '../registry.js';
|
||||
import { useState, useEffect } from 'react';
|
||||
import { Card, Table, Badge, StatusBadge, Button, UserAvatar, RelativeDate } from '@zen/core/shared/components';
|
||||
import { PencilEdit01Icon } from '@zen/core/shared/icons';
|
||||
@@ -179,3 +180,5 @@ const UsersPage = () => (
|
||||
);
|
||||
|
||||
export default UsersPage;
|
||||
|
||||
registerPage({ slug: 'users', title: 'Utilisateurs', Component: UsersPage });
|
||||
|
||||
@@ -1,13 +0,0 @@
|
||||
'use client';
|
||||
|
||||
import { registerPage } from '../registry.js';
|
||||
import { PAGE_TITLES } from './titles.js';
|
||||
import DashboardPage from './DashboardPage.client.js';
|
||||
import UsersPage from './UsersPage.client.js';
|
||||
import RolesPage from './RolesPage.client.js';
|
||||
import ProfilePage from './ProfilePage.client.js';
|
||||
|
||||
registerPage({ slug: 'dashboard', Component: DashboardPage, title: PAGE_TITLES.dashboard });
|
||||
registerPage({ slug: 'users', Component: UsersPage, title: PAGE_TITLES.users });
|
||||
registerPage({ slug: 'roles', Component: RolesPage, title: PAGE_TITLES.roles });
|
||||
registerPage({ slug: 'profile', Component: ProfilePage, title: PAGE_TITLES.profile });
|
||||
@@ -1,6 +0,0 @@
|
||||
export const PAGE_TITLES = {
|
||||
dashboard: 'Tableau de bord',
|
||||
profile: 'Mon profil',
|
||||
users: 'Utilisateurs',
|
||||
roles: 'Rôles',
|
||||
};
|
||||
Reference in New Issue
Block a user