import { AppstoreOutlined, LogoutOutlined, SnippetsOutlined, } from "@ant-design/icons"; import { Badge, Divider, Menu } from "antd"; import Sider from "antd/es/layout/Sider"; import { useContext, useEffect, useState } from "react"; import { useLocation, useNavigate } from "react-router-dom"; import PropTypes from "prop-types"; import { Constants, MyAvatar, UseUserSession, WebSocketContext, } from "../../utils"; export default function SideMenu({ setUserSession }) { const { userSession } = UseUserSession(); const location = useLocation(); const [selectedKeys, setSelectedKeys] = useState("/"); const webSocketContext = useContext(WebSocketContext); useEffect(() => { const pathName = location.pathname; setSelectedKeys(pathName); }, [location.pathname]); const navigate = useNavigate(); return (
J A N E X
Admin Dashboard
{ navigate(item.key); }} theme="light" selectedKeys={[selectedKeys]} items={[ { label: "Dashboard", icon: , key: "/", }, { label: "Group Tasks", icon: , key: "/group-tasks", }, ]} />
navigate(item.key)} items={[ { icon: ( ), key: "/users", }, { label: " " + webSocketContext.User.Username, icon: ( ), key: "/user-profile", }, { label: "Logout", icon: , onClick: () => { setUserSession(); window.location.href = "/"; fetch(`${Constants.API_ADDRESS}/user/auth/logout`, { method: "DELETE", headers: { "Content-Type": "application/json", "X-Authorization": userSession, }, }).catch(console.error); }, key: "/", }, ]} />
); } SideMenu.propTypes = { setUserSession: PropTypes.func.isRequired, };