diff --git a/client/src/shared/components/organisms/sidebar/hooks/index.ts b/client/src/shared/components/organisms/sidebar/hooks/index.ts
index c4ffe0d4..6cb4ec0f 100644
--- a/client/src/shared/components/organisms/sidebar/hooks/index.ts
+++ b/client/src/shared/components/organisms/sidebar/hooks/index.ts
@@ -12,7 +12,6 @@ import {
} from '../../../../../app/routes/constants/routes';
import { useAuth } from '../../../../hooks/use-auth';
-
const logoutStyle = {
marginTop: 'auto',
marginBottom: 0,
@@ -20,8 +19,20 @@ const logoutStyle = {
const useSidebar = () => {
const [showExpandedView, setShowExpandedView] = useState(false);
+ const [showLogoutModal, setShowLogoutModal] = useState(false);
+
const { logout } = useAuth();
+ // open modal
+ const handleLogoutClick = useCallback(() => {
+ setShowLogoutModal(true);
+ }, []);
+
+ // confirm logout
+ const confirmLogout = useCallback(() => {
+ setShowLogoutModal(false);
+ logout();
+ }, [logout]);
const handleMouseHoverIn = useCallback(() => {
setShowExpandedView(true);
@@ -31,7 +42,6 @@ const useSidebar = () => {
setShowExpandedView(false);
}, []);
-
const sidebarItems = useMemo(() => {
const items: SideBarItemsType[] = [
{
@@ -68,27 +78,33 @@ const useSidebar = () => {
screenName: ROUTES_PAGE_V1.SETTINGS,
},
];
-
+
const secondaryItems: SideBarItemsType[] = [
{
icon: PowerSettingsNewIcon,
- onClick: logout,
+ onClick: handleLogoutClick,
title: 'Logout',
style: logoutStyle,
},
];
+
return {
items: items.filter(({ disable }) => !disable),
secondaryItems: secondaryItems.filter(({ disable }) => !disable),
};
- }, [logout]);
-
+ }, [handleLogoutClick]);
return {
showExpandedView,
handleMouseHoverIn,
handleMouseHoverOut,
sidebarItems,
+
+ // modal controls
+ showLogoutModal,
+ setShowLogoutModal,
+ confirmLogout,
};
};
+
export default useSidebar;
diff --git a/client/src/shared/components/organisms/sidebar/index.tsx b/client/src/shared/components/organisms/sidebar/index.tsx
index dca2e209..17d0a0f6 100644
--- a/client/src/shared/components/organisms/sidebar/index.tsx
+++ b/client/src/shared/components/organisms/sidebar/index.tsx
@@ -1,4 +1,12 @@
-import { Box, Typography, SxProps, Theme, ButtonBase } from '@mui/material';
+import {
+ Box,
+ Typography,
+ SxProps,
+ Theme,
+ ButtonBase,
+ Button,
+ Modal,
+} from '@mui/material';
import { ORGANISATION_TITLE_HEIGHT, SIDEBAR_WIDTH } from './constants';
import useSidebar from './hooks';
import SidebarMenuItem from './components/SidebarMenuItem';
@@ -12,217 +20,224 @@ const Sidebar = () => {
handleMouseHoverIn,
handleMouseHoverOut,
sidebarItems,
+ showLogoutModal,
+ setShowLogoutModal,
+ confirmLogout,
} = useSidebar();
+
const { items, secondaryItems } = sidebarItems;
return (
- theme.zIndex.drawer + 1,
- left: 0,
- width: showExpandedView ? '230px' : `${SIDEBAR_WIDTH}px`,
- minWidth: showExpandedView ? '230px' : `${SIDEBAR_WIDTH}px`,
- maxWidth: showExpandedView ? '230px' : `${SIDEBAR_WIDTH}px`,
- transition:
- 'width 280ms ease-in-out, min-width 280ms ease-in-out, max-width 280ms ease-in-out',
- alignItems: 'center',
- justifyContent: 'flex-start',
- }}
- >
+ <>
theme.zIndex.drawer + 1,
+ left: 0,
+ width: showExpandedView ? '230px' : `${SIDEBAR_WIDTH}px`,
+ minWidth: showExpandedView ? '230px' : `${SIDEBAR_WIDTH}px`,
+ maxWidth: showExpandedView ? '230px' : `${SIDEBAR_WIDTH}px`,
+ transition:
+ 'width 280ms ease-in-out, min-width 280ms ease-in-out, max-width 280ms ease-in-out',
+ alignItems: 'center',
+ justifyContent: 'flex-start',
}}
>
-
- {showExpandedView ? (
-
- ) : (
-
- )}
-
-
-
-
- {items.map(
- (
- {
- icon,
- path,
- onClick,
- title,
- style,
- component,
- screenName,
- hasAccess,
- hideRipple,
- hide,
- },
- index
- ) => {
- return (
- }
- component={component}
- screenName={screenName}
- hideRipple={hideRipple}
- hide={hide}
+
+ {showExpandedView ? (
+
- );
- }
- )}
-
-
-
- {secondaryItems.map(
- (
- {
- icon,
- path,
- onClick,
- title,
- style,
- component,
- screenName,
- hasAccess,
- hideRipple,
- },
- index
- ) => {
- return (
- }
- component={component}
- screenName={screenName}
- hideRipple={hideRipple}
+ ) : (
+
- );
- }
- )}
-
+ )}
+
+
- {appVersion && (
+ {/* Main Items */}
- (
+ }
+ component={item.component}
+ screenName={item.screenName}
+ hideRipple={item.hideRipple}
+ hide={item.hide}
+ />
+ ))}
+
+
+ {/* Secondary Items (Logout) */}
+
+ {secondaryItems.map((item, index) => (
+ }
+ component={item.component}
+ screenName={item.screenName}
+ hideRipple={item.hideRipple}
+ />
+ ))}
+
+
+ {/* App Version */}
+ {appVersion && (
+
- {showExpandedView ? `APP VERSION: ${appVersion}` : appVersion}
+
+ {showExpandedView ? `APP VERSION: ${appVersion}` : appVersion}
+
+
+ )}
+
+
+ {/* Logout Confirmation Modal */}
+ setShowLogoutModal(false)}>
+
+
+ Confirm Logout
+
+
+ Are you sure you want to logout?
+
+
+
+
+
+
- )}
-
+
+ >
);
};