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