1- import React , { useState } from 'react' ;
2- import { Icon } from '@iconify/react' ;
3- import { Link , useNavigate } from 'react-router-dom' ;
4- import { generalSectionItems , managementSectionItems , applicationsSectionItems , performanceSectionItems , adminSectionItems , applicantSidebarItems , additionalSidebarItems } from './sidebarItems' ;
1+ import React , { useState } from "react" ;
2+ import { Icon } from "@iconify/react" ;
3+ import { Link , useNavigate } from "react-router-dom" ;
4+ import {
5+ generalSectionItems ,
6+ managementSectionItems ,
7+ applicationsSectionItems ,
8+ performanceSectionItems ,
9+ adminSectionItems ,
10+ applicantSidebarItems ,
11+ additionalSidebarItems ,
12+ } from "./sidebarItems" ;
513import "./navslide.css" ;
614
7- const Sidebar = ( ) => {
8- const [ expanded , setExpanded ] = useState ( true ) ;
9- const navigate = useNavigate ( )
10- const [ openSections , setOpenSections ] = useState ( { general : true , management : true , applications : true , performance : true , admin : true , additional : true } ) ;
11- const roleName = localStorage . getItem ( 'roleName' ) ;
12- const sections = roleName === 'applicant' ? [ { title : 'Applicant Section' , items : applicantSidebarItems } ] : [
13- { title : 'General' , items : generalSectionItems } ,
14- { title : 'Management' , items : managementSectionItems } ,
15- { title : 'Applications' , items : applicationsSectionItems } ,
16- { title : 'Performance' , items : performanceSectionItems } ,
17- { title : 'Admin' , items : adminSectionItems } ,
18- { title : 'Additional' , items : additionalSidebarItems }
19- ] ;
15+ const Sidebar = ( { expanded, setExpanded } ) => {
16+ const navigate = useNavigate ( ) ;
17+ const [ openSections , setOpenSections ] = useState ( {
18+ general : true ,
19+ management : true ,
20+ applications : true ,
21+ performance : true ,
22+ admin : true ,
23+ additional : true ,
24+ } ) ;
25+ const roleName = localStorage . getItem ( "roleName" ) ;
26+ const sections =
27+ roleName === "applicant"
28+ ? [ { title : "Applicant Section" , items : applicantSidebarItems } ]
29+ : [
30+ { title : "General" , items : generalSectionItems } ,
31+ { title : "Management" , items : managementSectionItems } ,
32+ { title : "Applications" , items : applicationsSectionItems } ,
33+ { title : "Performance" , items : performanceSectionItems } ,
34+ { title : "Admin" , items : adminSectionItems } ,
35+ { title : "Additional" , items : additionalSidebarItems } ,
36+ ] ;
2037
21- const toggleSection = ( section ) => setOpenSections ( prev => ( { ...prev , [ section ] : ! prev [ section ] } ) ) ;
22- const handleLogout = ( ) => {
23- localStorage . clear ( ) ;
24- navigate ( '/login' ) ;
38+ const toggleSection = ( section ) =>
39+ setOpenSections ( ( prev ) => ( { ...prev , [ section ] : ! prev [ section ] } ) ) ;
40+ const handleLogout = ( ) => {
41+ localStorage . clear ( ) ;
42+ navigate ( "/login" ) ;
2543 } ;
2644
2745 return (
28- < div className = { `top-0 mt-[70px] ${ expanded ? 'w-[16rem]' : 'w-[4rem]' } fixed z-10 dark:bg-dark-bg bg-white border-r transition-width duration-300 h-screen overflow-y-auto custom-scrollbar` } >
29- < button onClick = { ( ) => setExpanded ( ! expanded ) } className = "p-1.5 rounded-lg bg-gray-50 absolute top-2 right-2 z-20" >
30- < Icon icon = { expanded ? 'material-symbols:menu-open' : 'mdi:menu-close' } color = "#000" />
46+ < div
47+ className = { `top-0 mt-[70px] ${
48+ expanded ? "w-[16rem]" : "w-[4rem]"
49+ } fixed z-10 dark:bg-dark-bg bg-white border-r transition-width duration-300 h-screen overflow-y-auto custom-scrollbar`}
50+ >
51+ < button
52+ onClick = { ( ) => setExpanded ( ! expanded ) }
53+ className = "p-1.5 rounded-lg bg-gray-50 absolute top-2 right-2 z-20"
54+ >
55+ < Icon
56+ icon = { expanded ? "material-symbols:menu-open" : "mdi:menu-close" }
57+ color = "#000"
58+ />
3159 </ button >
3260 < div className = "pt-12 pb-12 mb-20" >
3361 { sections . map ( ( section , idx ) => (
3462 < div key = { idx } >
35- < div onClick = { ( ) => toggleSection ( section . title . toLowerCase ( ) ) } className = "cursor-pointer p-2 flex items-center justify-between text-white" >
63+ < div
64+ onClick = { ( ) => toggleSection ( section . title . toLowerCase ( ) ) }
65+ className = "cursor-pointer p-2 flex items-center justify-between text-white"
66+ >
3667 { expanded && < span className = "font-bold" > { section . title } </ span > }
37- < Icon icon = { openSections [ section . title . toLowerCase ( ) ] ? 'akar-icons:chevron-down' : 'akar-icons:chevron-right' } />
68+ < Icon
69+ icon = {
70+ openSections [ section . title . toLowerCase ( ) ]
71+ ? "akar-icons:chevron-down"
72+ : "akar-icons:chevron-right"
73+ }
74+ />
3875 </ div >
3976 { openSections [ section . title . toLowerCase ( ) ] && (
4077 < ul className = "pl-4 mt-2" >
@@ -50,7 +87,10 @@ const Sidebar = () => {
5087 ) }
5188 </ div >
5289 ) ) }
53- < button onClick = { handleLogout } className = "flex items-center p-1 font-semibold hover:font-bold text-white focus:outline-none" >
90+ < button
91+ onClick = { handleLogout }
92+ className = "flex items-center p-1 font-semibold hover:font-bold text-white focus:outline-none"
93+ >
5494 < Icon icon = "nimbus:arrow-left" className = "mr-3" />
5595 { expanded && < span > Logout</ span > }
5696 </ button >
0 commit comments