diff --git a/src/features/admin/components/AdminHeader.js b/src/features/admin/components/AdminHeader.js index 0ec64c5..7691428 100644 --- a/src/features/admin/components/AdminHeader.js +++ b/src/features/admin/components/AdminHeader.js @@ -1,181 +1,29 @@ 'use client'; -import { Fragment } from 'react'; -import { Menu, MenuButton, MenuItem, MenuItems, Transition } from '@headlessui/react'; -import { ChevronDownIcon, User03Icon } from '@zen/core/shared/icons'; -import { UserAvatar } from '@zen/core/shared/components'; -import { useRouter, usePathname } from 'next/navigation'; -import { useTheme, getThemeIcon } from '@zen/core/themes'; +import { useRouter } from 'next/navigation'; +import { Button } from '@zen/core/shared/components'; -const AdminHeader = ({ isMobileMenuOpen, setIsMobileMenuOpen, user, onLogout, appName = 'ZEN', navigationSections = [] }) => { - const router = useRouter(); - const pathname = usePathname(); +const AdminHeader = ({ title, description, backHref, backLabel = '← Retour', action }) => { + const router = useRouter(); - const handleLogout = async () => { - try { - if (onLogout) { - const result = await onLogout(); - if (result && result.success) { - router.push('/auth/login'); - } else { - console.error('Logout failed:', result?.error); - router.push('/auth/login'); - } - } else { - router.push('/auth/login'); - } - } catch (error) { - console.error('Logout error:', error); - router.push('/auth/login'); - } - }; - - const { theme, toggle, systemIsDark } = useTheme(); - const ThemeIcon = getThemeIcon(theme, systemIsDark); - const themeLabel = theme === 'light' ? 'Mode clair' : theme === 'dark' ? 'Mode sombre' : 'Thème système'; - - const currentPageName = (() => { - for (const section of navigationSections) { - for (const item of section.items) { - if (pathname === item.href || pathname.startsWith(item.href + '/')) { - return item.name; - } - } - if (section.items.length === 1 && (pathname === section.items[0].href || pathname.startsWith(section.items[0].href + '/'))) { - return section.title; - } - } - return null; - })(); - - const quickLinks = []; - - return ( -
-
- {/* Left section — Mobile menu button + Logo / Desktop breadcrumb */} -
- -

{appName}

-
- - {/* Desktop breadcrumb */} - {currentPageName && ( -
- {appName} - - - - {currentPageName} -
- )} - - {/* Right section — Quick links + Profile */} -
- - - {/* User Profile Menu */} - - - - {/* Name — desktop only */} - - {user?.name || 'User'} - - - - - - -
- {/* Quick links — mobile only */} - {quickLinks.length > 0 && ( - <> - {quickLinks.map((link) => ( - - - - - - {link.name} - - - ))} -
- - )} - - {/* Profile */} - - - - Mon profil - - - - {/* Theme — pas de MenuItem pour ne pas fermer le menu au clic */} - - -
- - {/* Logout */} - - - -
- - -
-
-
-
- ); + return ( +
+
+ {backHref && ( + + )} +
+

{title}

+ {description && ( +

{description}

+ )} +
+
+ {action} +
+ ); }; export default AdminHeader; diff --git a/src/features/admin/components/AdminShell.js b/src/features/admin/components/AdminShell.js index c29d107..2684dc4 100644 --- a/src/features/admin/components/AdminShell.js +++ b/src/features/admin/components/AdminShell.js @@ -2,7 +2,7 @@ import { useState } from 'react'; import AdminSidebar from './AdminSidebar.js'; -import AdminHeader from './AdminHeader.js'; +import AdminTop from './AdminTop.js'; export default function AdminShell({ children, user, onLogout, appName, navigationSections }) { const [isMobileMenuOpen, setIsMobileMenuOpen] = useState(false); @@ -16,7 +16,7 @@ export default function AdminShell({ children, user, onLogout, appName, navigati navigationSections={navigationSections} />
- { + const router = useRouter(); + const pathname = usePathname(); + + const handleLogout = async () => { + try { + if (onLogout) { + const result = await onLogout(); + if (result && result.success) { + router.push('/auth/login'); + } else { + console.error('Logout failed:', result?.error); + router.push('/auth/login'); + } + } else { + router.push('/auth/login'); + } + } catch (error) { + console.error('Logout error:', error); + router.push('/auth/login'); + } + }; + + const { theme, toggle, systemIsDark } = useTheme(); + const ThemeIcon = getThemeIcon(theme, systemIsDark); + const themeLabel = theme === 'light' ? 'Mode clair' : theme === 'dark' ? 'Mode sombre' : 'Thème système'; + + const currentPageName = (() => { + for (const section of navigationSections) { + for (const item of section.items) { + if (pathname === item.href || pathname.startsWith(item.href + '/')) { + return item.name; + } + } + if (section.items.length === 1 && (pathname === section.items[0].href || pathname.startsWith(section.items[0].href + '/'))) { + return section.title; + } + } + return null; + })(); + + const quickLinks = []; + + return ( +
+
+ {/* Left section — Mobile menu button + Logo / Desktop breadcrumb */} +
+ +

{appName}

+
+ + {/* Desktop breadcrumb */} + {currentPageName && ( +
+ {appName} + + + + {currentPageName} +
+ )} + + {/* Right section — Quick links + Profile */} +
+ + + {/* User Profile Menu */} + + + + {/* Name — desktop only */} + + {user?.name || 'User'} + + + + + + +
+ {/* Quick links — mobile only */} + {quickLinks.length > 0 && ( + <> + {quickLinks.map((link) => ( + + + + + + {link.name} + + + ))} +
+ + )} + + {/* Profile */} + + + + Mon profil + + + + {/* Theme — pas de MenuItem pour ne pas fermer le menu au clic */} + + +
+ + {/* Logout */} + + + +
+ + +
+
+
+
+ ); +}; + +export default AdminTop; diff --git a/src/features/admin/components/index.js b/src/features/admin/components/index.js index 47b9170..8d4bd38 100644 --- a/src/features/admin/components/index.js +++ b/src/features/admin/components/index.js @@ -2,5 +2,6 @@ export { default as AdminShell } from './AdminShell.js'; export { default as AdminSidebar } from './AdminSidebar.js'; +export { default as AdminTop } from './AdminTop.js'; export { default as AdminHeader } from './AdminHeader.js'; export { default as ThemeToggle } from './ThemeToggle.js'; diff --git a/src/features/admin/pages/DashboardPage.client.js b/src/features/admin/pages/DashboardPage.client.js index 9ff1ec4..0014e7d 100644 --- a/src/features/admin/pages/DashboardPage.client.js +++ b/src/features/admin/pages/DashboardPage.client.js @@ -1,6 +1,7 @@ 'use client'; import { getWidgets } from '../registry.js'; +import AdminHeader from '../components/AdminHeader.js'; export default function DashboardPage({ stats }) { const loading = stats === null || stats === undefined; @@ -8,10 +9,7 @@ export default function DashboardPage({ stats }) { return (
-
-

Tableau de bord

-

Vue d'ensemble de votre application

-
+
{widgets.map(({ id, Component }) => ( diff --git a/src/features/admin/pages/ProfilePage.client.js b/src/features/admin/pages/ProfilePage.client.js index 7f6ca96..a3ee13b 100644 --- a/src/features/admin/pages/ProfilePage.client.js +++ b/src/features/admin/pages/ProfilePage.client.js @@ -3,6 +3,7 @@ import React, { useState, useEffect, useRef } from 'react'; import { Card, Input, Button } from '@zen/core/shared/components'; import { useToast } from '@zen/core/toast'; +import AdminHeader from '../components/AdminHeader.js'; const ProfilePage = ({ user: initialUser }) => { const toast = useToast(); @@ -181,17 +182,7 @@ const ProfilePage = ({ user: initialUser }) => { return (
- {/* Header */} -
-
-

- Mon profil -

-

- Gérez les informations de votre compte -

-
-
+ {/* Content */}
diff --git a/src/features/admin/pages/RoleEditPage.client.js b/src/features/admin/pages/RoleEditPage.client.js index 3d2dcda..11304d4 100644 --- a/src/features/admin/pages/RoleEditPage.client.js +++ b/src/features/admin/pages/RoleEditPage.client.js @@ -5,6 +5,7 @@ import { useRouter } from 'next/navigation'; import { Card, Button, Input, Textarea, Switch } from '@zen/core/shared/components'; import { useToast } from '@zen/core/toast'; import { getPermissionGroups } from '@zen/core/users/constants'; +import AdminHeader from '../components/AdminHeader.js'; const PERMISSION_GROUPS = getPermissionGroups(); @@ -115,17 +116,11 @@ const RoleEditPage = ({ roleId }) => { return (
-
- -
-

{title}

- {isSystem && ( -

Rôle système — le nom ne peut pas être modifié

- )} -
-
+
diff --git a/src/features/admin/pages/RolesPage.client.js b/src/features/admin/pages/RolesPage.client.js index 0f6f985..02d4830 100644 --- a/src/features/admin/pages/RolesPage.client.js +++ b/src/features/admin/pages/RolesPage.client.js @@ -5,6 +5,7 @@ import { useRouter } from 'next/navigation'; import { Card, Table, Button, Badge } from '@zen/core/shared/components'; import { PencilEdit01Icon, Cancel01Icon } from '@zen/core/shared/icons'; import { useToast } from '@zen/core/toast'; +import AdminHeader from '../components/AdminHeader.js'; const RolesPageClient = () => { const router = useRouter(); @@ -146,21 +147,15 @@ const RolesPage = () => { return (
-
-
-

Rôles

-

- Gérez les rôles et leurs permissions -

-
- -
+ router.push('/admin/roles/new')}> + Nouveau rôle + + } + />
); diff --git a/src/features/admin/pages/UserEditPage.client.js b/src/features/admin/pages/UserEditPage.client.js index e552718..04e7e05 100644 --- a/src/features/admin/pages/UserEditPage.client.js +++ b/src/features/admin/pages/UserEditPage.client.js @@ -4,6 +4,7 @@ import { useState, useEffect } from 'react'; import { useRouter } from 'next/navigation'; import { Button, Card, Input, Select, Loading, TagInput } from '@zen/core/shared/components'; import { useToast } from '@zen/core/toast'; +import AdminHeader from '../components/AdminHeader.js'; const UserEditPage = ({ userId }) => { const router = useRouter(); @@ -158,15 +159,12 @@ const UserEditPage = ({ userId }) => { if (!userData) { return (
-
-
-

Modifier l'utilisateur

-

Utilisateur introuvable

-
- -
+

Utilisateur introuvable

@@ -179,15 +177,12 @@ const UserEditPage = ({ userId }) => { return (
-
-
-

Modifier l'utilisateur

-

{userData.email}

-
- -
+ diff --git a/src/features/admin/pages/UsersPage.client.js b/src/features/admin/pages/UsersPage.client.js index 0b1088b..df56ab5 100644 --- a/src/features/admin/pages/UsersPage.client.js +++ b/src/features/admin/pages/UsersPage.client.js @@ -5,6 +5,7 @@ import { useRouter } from 'next/navigation'; import { Card, Table, Badge, StatusBadge, Button, UserAvatar } from '@zen/core/shared/components'; import { PencilEdit01Icon } from '@zen/core/shared/icons'; import { useToast } from '@zen/core/toast'; +import AdminHeader from '../components/AdminHeader.js'; const UsersPageClient = () => { const router = useRouter(); @@ -211,14 +212,7 @@ const UsersPageClient = () => { const UsersPage = () => { return (
-
-
-

Utilisateurs

-

- Gérez les comptes utilisateurs -

-
-
+
);