From ef811306df08d256e7bf6be11a8816f05761f4ac Mon Sep 17 00:00:00 2001 From: Kartikey2011yadav Date: Fri, 27 Sep 2024 19:53:20 +0530 Subject: [PATCH] alert model set on logout --- src/Sidebar/Sidebar.jsx | 41 +++++++++++++++++++++++++++++++++++++---- 1 file changed, 37 insertions(+), 4 deletions(-) diff --git a/src/Sidebar/Sidebar.jsx b/src/Sidebar/Sidebar.jsx index b72ddf9..0789308 100644 --- a/src/Sidebar/Sidebar.jsx +++ b/src/Sidebar/Sidebar.jsx @@ -12,8 +12,31 @@ import { BsClipboardCheck } from 'react-icons/bs'; import { Link } from 'react-router-dom'; import { ThemeContext } from '../contexts/ThemeContext'; import { TbLogout } from 'react-icons/tb'; +import { useNavigate } from 'react-router-dom'; +import AlertModal from '../AlertModel/AlertModel'; const Sidebar = () => { + const navigate = useNavigate(); + const [modalOpen, setModalOpen] = useState(false); // Modal open state + const [modalMessage, setModalMessage] = useState(''); // Modal message + const [isError, setIsError] = useState(false); // Modal error state + + const handleLogout = () => { + setModalMessage('Attempting to Logout'); + setIsError(false); + setModalOpen(true); + }; + + const confirmLogout = () => { + localStorage.removeItem('sessionId'); + setModalOpen(false); + navigate('/'); + }; + + const closeModal = () => { + setModalOpen(false); + }; + const { theme } = useContext(ThemeContext); const menus = [ { name: 'Dashboard', link: '/', icon: MdOutlineDashboard }, @@ -84,14 +107,16 @@ const Sidebar = () => { ))}
{ + handleLogout(); + }} + className={` group flex items-center text-sm gap-3.5 font-medium p-2 rounded-md `} >
{React.createElement(TbLogout, { size: '28', color: 'red' })}

{

{'Logout'}

+ ); };