refactor(admin): derive pageTitle from state instead of inline in breadcrumb function
This commit is contained in:
@@ -1,6 +1,6 @@
|
|||||||
'use client';
|
'use client';
|
||||||
|
|
||||||
import { Fragment } from 'react';
|
import { Fragment, useState, useEffect } from 'react';
|
||||||
import { Menu, MenuButton, MenuItem, MenuItems, Transition } from '@headlessui/react';
|
import { Menu, MenuButton, MenuItem, MenuItems, Transition } from '@headlessui/react';
|
||||||
import { ChevronDownIcon, User03Icon, DashboardSquare03Icon } from '@zen/core/shared/icons';
|
import { ChevronDownIcon, User03Icon, DashboardSquare03Icon } from '@zen/core/shared/icons';
|
||||||
import { UserAvatar } from '@zen/core/shared/components';
|
import { UserAvatar } from '@zen/core/shared/components';
|
||||||
@@ -11,6 +11,13 @@ 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 = [] }) => {
|
||||||
const router = useRouter();
|
const router = useRouter();
|
||||||
const pathname = usePathname();
|
const pathname = usePathname();
|
||||||
|
const [pageTitle, setPageTitle] = useState('');
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
const segments = pathname.replace(/^\/admin\/?/, '').split('/').filter(Boolean);
|
||||||
|
const slug = segments[0] || 'dashboard';
|
||||||
|
setPageTitle(getPage(slug)?.title || '');
|
||||||
|
}, [pathname]);
|
||||||
|
|
||||||
const handleLogout = async () => {
|
const handleLogout = async () => {
|
||||||
try {
|
try {
|
||||||
@@ -40,7 +47,6 @@ const AdminTop = ({ isMobileMenuOpen, setIsMobileMenuOpen, user, onLogout, appNa
|
|||||||
const after = pathname.replace(/^\/admin\/?/, '');
|
const after = pathname.replace(/^\/admin\/?/, '');
|
||||||
const segments = after.split('/').filter(Boolean);
|
const segments = after.split('/').filter(Boolean);
|
||||||
const [first, second] = segments;
|
const [first, second] = segments;
|
||||||
const pageTitle = getPage(first || 'dashboard')?.title || '';
|
|
||||||
|
|
||||||
if (!after || !segments.length || (segments[0] === 'dashboard' && segments.length === 1)) {
|
if (!after || !segments.length || (segments[0] === 'dashboard' && segments.length === 1)) {
|
||||||
crumbs.push({ label: pageTitle });
|
crumbs.push({ label: pageTitle });
|
||||||
|
|||||||
Reference in New Issue
Block a user