From 46b17cb97171b5b4a910c2ad0726b0d894932fd9 Mon Sep 17 00:00:00 2001 From: ashmeetsmonga Date: Fri, 18 Aug 2023 19:14:34 +0530 Subject: [PATCH 1/2] fix: menu not highlighted while navigating via url fixed --- frontend/src/app/Navigation/index.jsx | 34 +++++++++++++++------------ 1 file changed, 19 insertions(+), 15 deletions(-) diff --git a/frontend/src/app/Navigation/index.jsx b/frontend/src/app/Navigation/index.jsx index a8eef05a0..ce5e8333d 100644 --- a/frontend/src/app/Navigation/index.jsx +++ b/frontend/src/app/Navigation/index.jsx @@ -1,5 +1,5 @@ import { useState, useEffect } from 'react'; -import { Link } from 'react-router-dom'; +import { Link, useLocation } from 'react-router-dom'; import { Button, Drawer, Layout, Menu } from 'antd'; import { useAppContext } from '@/context/appContext'; @@ -34,10 +34,17 @@ export default function Navigation() { } function Sidebar({ collapsible }) { + let location = useLocation(); + const { state: stateApp, appContextAction } = useAppContext(); const { isNavMenuClose } = stateApp; const { navMenu } = appContextAction; const [showLogoApp, setLogoApp] = useState(isNavMenuClose); + const [currentPath, setCurrentPath] = useState(location.pathname); + + useEffect(() => { + if (location) if (currentPath !== location.pathname) setCurrentPath(location.pathname); + }, [location, currentPath]); useEffect(() => { if (isNavMenuClose) { @@ -56,7 +63,6 @@ function Sidebar({ collapsible }) { return ( <> - )} - - - - }> + + }> Dashboard - }> + }> Customer - }> + }> Invoice - }> + }> Quote - }> + }> Payment Invoice - }> + }> Employee - }> + }> Admin } title={'Settings'}> - + General Settings - + Payment Mode - + Role From 2262ca191b1ee42cb033bd849de4b35d88768f2d Mon Sep 17 00:00:00 2001 From: ashmeetsmonga Date: Mon, 21 Aug 2023 15:42:11 +0530 Subject: [PATCH 2/2] fix:added a constant array for sidebar menu and submenu items in navigation --- frontend/src/app/Navigation/index.jsx | 68 +++++++++++---------------- 1 file changed, 28 insertions(+), 40 deletions(-) diff --git a/frontend/src/app/Navigation/index.jsx b/frontend/src/app/Navigation/index.jsx index ce5e8333d..19f48388a 100644 --- a/frontend/src/app/Navigation/index.jsx +++ b/frontend/src/app/Navigation/index.jsx @@ -19,6 +19,22 @@ import { MenuOutlined, } from '@ant-design/icons'; +const SIDEBAR_MENU = [ + { key: '/', icon: , title: 'Dashboard' }, + { key: '/customer', icon: , title: 'Customer' }, + { key: '/invoice', icon: , title: 'Invoice' }, + { key: '/quote', icon: , title: 'Quote' }, + { key: '/payment/invoice', icon: , title: 'Payment Invoice' }, + { key: '/employee', icon: , title: 'Employee' }, + { key: '/admin', icon: , title: 'Admin' }, +]; + +const SETTINGS_SUBMENU = [ + { key: '/settings', title: 'General Settings' }, + { key: '/payment/mode', title: 'Payment Mode' }, + { key: '/role', title: 'Role' }, +]; + const { Sider } = Layout; const { SubMenu } = Menu; @@ -81,47 +97,19 @@ function Sidebar({ collapsible }) { )} - }> - - Dashboard - - }> - - Customer - - }> - - Invoice - - }> - - Quote - - }> - - Payment Invoice - - }> - - Employee - - }> - - Admin - - } title={'Settings'}> - - - General Settings - - - - Payment Mode - - - - Role + {SIDEBAR_MENU.map((menuItem) => ( + + + {menuItem.title} + ))} + } title={'Settings'}> + {SETTINGS_SUBMENU.map((menuItem) => ( + + + {menuItem.title} + + ))}