From ea0b946371ca7c0df3566bf5302ca5bfb26be8d4 Mon Sep 17 00:00:00 2001 From: Pratyush Jha Date: Sat, 24 Jan 2026 16:43:45 +0530 Subject: [PATCH 1/2] fix: logout button not working in sidebar --- .../sidebar/components/SidebarMenuItem.tsx | 11 +++++--- .../organisms/sidebar/hooks/index.ts | 27 ++++++++++++++++--- 2 files changed, 31 insertions(+), 7 deletions(-) diff --git a/client/src/shared/components/organisms/sidebar/components/SidebarMenuItem.tsx b/client/src/shared/components/organisms/sidebar/components/SidebarMenuItem.tsx index b570cef1..f9f98c56 100644 --- a/client/src/shared/components/organisms/sidebar/components/SidebarMenuItem.tsx +++ b/client/src/shared/components/organisms/sidebar/components/SidebarMenuItem.tsx @@ -132,19 +132,22 @@ const SidebarMenuItem: FC<{ }); } + if (onClick) { + onClick(event); + return; + } + if (path) { if ( event.ctrlKey || event.shiftKey || - event.metaKey || // apple - (event.button && event.button === 1) // middle click, >IE9 + everyone else + event.metaKey || + (event.button && event.button === 1) ) { openPopup(path, '_blank'); } else { navigate({ pathname: path }, { clearExistingParams: true }); } - } else { - onClick?.(event); } }, [isLocked, onClick, path, navigate, addNotification] diff --git a/client/src/shared/components/organisms/sidebar/hooks/index.ts b/client/src/shared/components/organisms/sidebar/hooks/index.ts index 7b49829a..f04ec392 100644 --- a/client/src/shared/components/organisms/sidebar/hooks/index.ts +++ b/client/src/shared/components/organisms/sidebar/hooks/index.ts @@ -10,6 +10,7 @@ import { ROUTES_PAGE_V1, ROUTES_V1, } from '../../../../../app/routes/constants/routes'; +import { useAuth } from '../../../../hooks/use-auth'; const logoutStyle = { marginTop: 'auto', @@ -18,6 +19,7 @@ const logoutStyle = { const useSidebar = () => { const [showExpandedView, setShowExpandedView] = useState(false); + const { logout } = useAuth(); const handleMouseHoverIn = useCallback(() => { setShowExpandedView(true); @@ -27,6 +29,24 @@ const useSidebar = () => { setShowExpandedView(false); }, []); + const onLogout = useCallback(() => { + console.log('🚪 Logging out...'); + + try { + logout(); + + console.log('✅ Logout successful, redirecting...'); + + // Redirect to login page + window.location.href = '/login'; + + } catch (error) { + console.error('❌ Logout error:', error); + logout(); + window.location.href = '/login'; + } + }, [logout]); + const sidebarItems = useMemo(() => { const items: SideBarItemsType[] = [ { @@ -62,11 +82,11 @@ const useSidebar = () => { title: 'Settings', screenName: ROUTES_PAGE_V1.SETTINGS, }, - ]; + ]; const secondaryItems: SideBarItemsType[] = [ { icon: PowerSettingsNewIcon, - // onClick: onLogout, + onClick: onLogout, title: 'Logout', style: logoutStyle, }, @@ -75,7 +95,8 @@ const useSidebar = () => { items: items.filter(({ disable }) => !disable), secondaryItems: secondaryItems.filter(({ disable }) => !disable), }; - }, []); + }, [onLogout]); + return { showExpandedView, From 59f7ddb7b273f4185749cf2412fb84cc0d29c801 Mon Sep 17 00:00:00 2001 From: Pratyush Jha Date: Sun, 25 Jan 2026 13:18:56 +0530 Subject: [PATCH 2/2] refactor: simplify logout implementation as per review feedback --- .../sidebar/components/SidebarMenuItem.tsx | 11 +++---- .../organisms/sidebar/hooks/index.ts | 31 +++++-------------- 2 files changed, 12 insertions(+), 30 deletions(-) diff --git a/client/src/shared/components/organisms/sidebar/components/SidebarMenuItem.tsx b/client/src/shared/components/organisms/sidebar/components/SidebarMenuItem.tsx index f9f98c56..b570cef1 100644 --- a/client/src/shared/components/organisms/sidebar/components/SidebarMenuItem.tsx +++ b/client/src/shared/components/organisms/sidebar/components/SidebarMenuItem.tsx @@ -132,22 +132,19 @@ const SidebarMenuItem: FC<{ }); } - if (onClick) { - onClick(event); - return; - } - if (path) { if ( event.ctrlKey || event.shiftKey || - event.metaKey || - (event.button && event.button === 1) + event.metaKey || // apple + (event.button && event.button === 1) // middle click, >IE9 + everyone else ) { openPopup(path, '_blank'); } else { navigate({ pathname: path }, { clearExistingParams: true }); } + } else { + onClick?.(event); } }, [isLocked, onClick, path, navigate, addNotification] diff --git a/client/src/shared/components/organisms/sidebar/hooks/index.ts b/client/src/shared/components/organisms/sidebar/hooks/index.ts index f04ec392..c4ffe0d4 100644 --- a/client/src/shared/components/organisms/sidebar/hooks/index.ts +++ b/client/src/shared/components/organisms/sidebar/hooks/index.ts @@ -10,7 +10,8 @@ import { ROUTES_PAGE_V1, ROUTES_V1, } from '../../../../../app/routes/constants/routes'; -import { useAuth } from '../../../../hooks/use-auth'; +import { useAuth } from '../../../../hooks/use-auth'; + const logoutStyle = { marginTop: 'auto', @@ -19,7 +20,8 @@ const logoutStyle = { const useSidebar = () => { const [showExpandedView, setShowExpandedView] = useState(false); - const { logout } = useAuth(); + const { logout } = useAuth(); + const handleMouseHoverIn = useCallback(() => { setShowExpandedView(true); @@ -29,23 +31,6 @@ const useSidebar = () => { setShowExpandedView(false); }, []); - const onLogout = useCallback(() => { - console.log('🚪 Logging out...'); - - try { - logout(); - - console.log('✅ Logout successful, redirecting...'); - - // Redirect to login page - window.location.href = '/login'; - - } catch (error) { - console.error('❌ Logout error:', error); - logout(); - window.location.href = '/login'; - } - }, [logout]); const sidebarItems = useMemo(() => { const items: SideBarItemsType[] = [ @@ -82,11 +67,12 @@ const useSidebar = () => { title: 'Settings', screenName: ROUTES_PAGE_V1.SETTINGS, }, - ]; + ]; + const secondaryItems: SideBarItemsType[] = [ { icon: PowerSettingsNewIcon, - onClick: onLogout, + onClick: logout, title: 'Logout', style: logoutStyle, }, @@ -95,7 +81,7 @@ const useSidebar = () => { items: items.filter(({ disable }) => !disable), secondaryItems: secondaryItems.filter(({ disable }) => !disable), }; - }, [onLogout]); + }, [logout]); return { @@ -105,5 +91,4 @@ const useSidebar = () => { sidebarItems, }; }; - export default useSidebar;