11"use client" ;
22import Link from "next/link" ;
33import Image from "next/image" ;
4- import { usePathname } from "next/navigation" ;
5- import { LayoutDashboard , ClipboardList , Users , Bot , User } from "lucide-react" ;
4+ import { usePathname , useRouter } from "next/navigation" ;
5+ import { useState } from "react" ;
6+ import { LayoutDashboard , ClipboardList , Users , Bot , User , LogOut } from "lucide-react" ;
7+
68const menuItems = [
79 { id : 1 , href : "/admin/dashboard" , icon : LayoutDashboard , name : "Dashboard" } ,
8- { id : 2 , href : "/admin/task-tracking" , icon : ClipboardList , name : "Tasks" } ,
10+ { id : 2 , href : "/admin/task-tracking" , icon : ClipboardList , name : "Tasks" } ,
911 { id : 3 , href : "/admin/organizations" , icon : Users , name : "Organizations" } ,
1012 { id : 4 , href : "/admin/performance" , icon : Bot , name : "Performance" } ,
1113] ;
14+
1215export default function Sidebar ( ) {
1316 const pathname = usePathname ( ) ;
17+ const router = useRouter ( ) ;
18+ const [ showLogoutConfirm , setShowLogoutConfirm ] = useState ( false ) ;
19+
20+ const handleLogoutClick = ( ) => setShowLogoutConfirm ( true ) ;
21+
22+ const handleLogoutConfirm = ( ) => {
23+ localStorage . removeItem ( "authToken" ) ;
24+ router . push ( "/onboarding/login" ) ;
25+ setShowLogoutConfirm ( false ) ;
26+ } ;
27+
28+ const handleLogoutCancel = ( ) => setShowLogoutConfirm ( false ) ;
29+
1430 return (
1531 < div className = "w-64 h-screen bg-teal-900 flex flex-col justify-between text-white" >
1632 < div className = "px-1 bg-teal-900 flex flex-col justify-between text-white" >
@@ -41,6 +57,16 @@ export default function Sidebar() {
4157 </ Link >
4258 ) ;
4359 } ) }
60+
61+ < button
62+ onClick = { handleLogoutClick }
63+ className = {
64+ `cursor-pointer px-6 py-3 mt-4 rounded-l-4xl gap-8 transition-colors flex items-center hover:bg-teal-700 w-63`
65+ }
66+ >
67+ < LogOut size = { 28 } />
68+ < label className = "text-md cursor-pointer" > Logout</ label >
69+ </ button >
4470 </ div >
4571 </ div >
4672 < div className = "flex items-center gap-5 px-6 py-4 bg-teal-800" >
@@ -49,6 +75,29 @@ export default function Sidebar() {
4975 </ div >
5076 < p className = "items-center font-medium" > Tesfa admin</ p >
5177 </ div >
78+
79+ { showLogoutConfirm && (
80+ < div className = "fixed inset-0 bg-black opacity-90 flex items-center justify-center z-50" >
81+ < div className = "bg-white p-6 rounded-lg shadow-lg max-w-xs w-full" >
82+ < h2 className = "text-lg font-bold mb-2 text-[#00363E]" > Confirm Logout</ h2 >
83+ < p className = "mb-4 text-gray-700" > Are you sure you want to logout?</ p >
84+ < div className = "flex justify-end gap-4" >
85+ < button
86+ onClick = { handleLogoutCancel }
87+ className = "px-4 py-2 rounded-2xl cursor-pointer bg-gray-200 hover:bg-gray-300 text-gray-800"
88+ >
89+ Cancel
90+ </ button >
91+ < button
92+ onClick = { handleLogoutConfirm }
93+ className = "px-4 py-2 cursor-pointer rounded-2xl bg-red-600 hover:bg-red-700 text-white"
94+ >
95+ Logout
96+ </ button >
97+ </ div >
98+ </ div >
99+ </ div >
100+ ) }
52101 </ div >
53102 ) ;
54- }
103+ }
0 commit comments