feat(admin): navigate to first section item when expanding collapsed sidebar section
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 } from 'next/navigation';
|
import { usePathname, useRouter } 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';
|
||||||
|
|
||||||
@@ -25,6 +25,7 @@ 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();
|
||||||
|
|
||||||
// State to manage collapsed sections (all open by default)
|
// State to manage collapsed sections (all open by default)
|
||||||
const [collapsedSections, setCollapsedSections] = useState(new Set());
|
const [collapsedSections, setCollapsedSections] = useState(new Set());
|
||||||
@@ -143,7 +144,12 @@ const AdminSidebar = ({ isMobileMenuOpen, setIsMobileMenuOpen, appName, enabledM
|
|||||||
return (
|
return (
|
||||||
<div key={section.id}>
|
<div key={section.id}>
|
||||||
<button
|
<button
|
||||||
onClick={() => toggleSection(section.id)}
|
onClick={() => {
|
||||||
|
if (isCollapsed && section.items.length > 0) {
|
||||||
|
router.push(section.items[0].href);
|
||||||
|
}
|
||||||
|
toggleSection(section.id);
|
||||||
|
}}
|
||||||
className="cursor-pointer w-full flex items-center justify-between border-y border-neutral-200 dark:border-neutral-800/70 px-4 py-2.5 -mb-[1px] text-[13px] text-neutral-900 dark:text-white tracking-wide hover:text-neutral-500 dark:hover:text-neutral-300 transition-colorsduration-0"
|
className="cursor-pointer w-full flex items-center justify-between border-y border-neutral-200 dark:border-neutral-800/70 px-4 py-2.5 -mb-[1px] text-[13px] text-neutral-900 dark:text-white tracking-wide hover:text-neutral-500 dark:hover:text-neutral-300 transition-colorsduration-0"
|
||||||
>
|
>
|
||||||
<div className="flex items-center">
|
<div className="flex items-center">
|
||||||
|
|||||||
Reference in New Issue
Block a user