refactor(admin): simplify sidebar toggle by removing router navigation and active section guard
This commit is contained in:
@@ -2,7 +2,7 @@
|
||||
|
||||
import React, { useState, useEffect } from 'react';
|
||||
import Link from 'next/link';
|
||||
import { usePathname, useRouter } from 'next/navigation';
|
||||
import { usePathname } from 'next/navigation';
|
||||
import * as Icons from '@zen/core/shared/icons';
|
||||
import { ChevronDownIcon } from '@zen/core/shared/icons';
|
||||
|
||||
@@ -22,17 +22,10 @@ function resolveIcon(iconNameOrComponent) {
|
||||
|
||||
const AdminSidebar = ({ isMobileMenuOpen, setIsMobileMenuOpen, appName, enabledModules, navigationSections: serverNavigationSections }) => {
|
||||
const pathname = usePathname();
|
||||
const router = useRouter();
|
||||
|
||||
const [collapsedSections, setCollapsedSections] = useState(new Set());
|
||||
|
||||
const toggleSection = (sectionId) => {
|
||||
const section = navigationSections.find(s => s.id === sectionId);
|
||||
|
||||
if (section && isSectionActive(section)) {
|
||||
return;
|
||||
}
|
||||
|
||||
setCollapsedSections(prev => {
|
||||
const newCollapsed = new Set(prev);
|
||||
if (newCollapsed.has(sectionId)) {
|
||||
@@ -131,12 +124,7 @@ const AdminSidebar = ({ isMobileMenuOpen, setIsMobileMenuOpen, appName, enabledM
|
||||
return (
|
||||
<div key={section.id}>
|
||||
<button
|
||||
onClick={() => {
|
||||
if (isCollapsed && section.items.length > 0) {
|
||||
router.push(section.items[0].href);
|
||||
}
|
||||
toggleSection(section.id);
|
||||
}}
|
||||
onClick={() => toggleSection(section.id)}
|
||||
className={`cursor-pointer ${parentBase} ${isActive && isCollapsed ? parentActif : isActive ? parentActifOuvert : inactive}`}
|
||||
>
|
||||
<div className="flex items-center gap-2">
|
||||
|
||||
Reference in New Issue
Block a user