|
| 1 | +import { useAuth } from "@/domains/auth/application/AuthContext"; |
| 2 | +import { cn } from "@/shared/lib/utils"; |
| 3 | +import { |
| 4 | + BriefcaseBusiness, |
| 5 | + ChartNoAxesColumn, |
| 6 | + Headphones, |
| 7 | + Home, |
| 8 | + LogOut, |
| 9 | + UserRound, |
| 10 | + UsersRound, |
| 11 | +} from "lucide-react"; |
| 12 | +import type { LucideIcon } from "lucide-react"; |
| 13 | +import { Link, useLocation, useNavigate } from "react-router-dom"; |
| 14 | + |
| 15 | +interface NavigationItem { |
| 16 | + label: string; |
| 17 | + to: string; |
| 18 | + icon: LucideIcon; |
| 19 | + activePaths: string[]; |
| 20 | + exact?: boolean; |
| 21 | + showChevron?: boolean; |
| 22 | +} |
| 23 | + |
| 24 | +const navigationItems: NavigationItem[] = [ |
| 25 | + { |
| 26 | + label: "Início", |
| 27 | + to: "/home", |
| 28 | + icon: Home, |
| 29 | + activePaths: ["/home"], |
| 30 | + exact: true, |
| 31 | + }, |
| 32 | + { |
| 33 | + label: "Dashboard", |
| 34 | + to: "/dashboard", |
| 35 | + icon: ChartNoAxesColumn, |
| 36 | + activePaths: ["/dashboard"], |
| 37 | + }, |
| 38 | + { |
| 39 | + label: "Vagas", |
| 40 | + to: "/vagas", |
| 41 | + icon: BriefcaseBusiness, |
| 42 | + activePaths: ["/vagas"], |
| 43 | + }, |
| 44 | + { |
| 45 | + label: "Mentoria", |
| 46 | + to: "/mentoria", |
| 47 | + icon: UsersRound, |
| 48 | + activePaths: ["/mentoria"], |
| 49 | + }, |
| 50 | +]; |
| 51 | + |
| 52 | +const sidebarItemClasses = |
| 53 | + "flex h-10 items-center gap-3 rounded-[5px] border text-sm tracking-[0.1px] transition-colors"; |
| 54 | + |
| 55 | +const inactiveSidebarItemClasses = |
| 56 | + "border-border/70 bg-card text-card-foreground hover:border-primary/35 hover:bg-muted dark:border-border/60 dark:bg-muted/15 dark:hover:bg-muted/35"; |
| 57 | + |
| 58 | +const activeSidebarItemClasses = |
| 59 | + "border-primary bg-primary font-bold text-primary-foreground shadow-sm shadow-primary/20"; |
| 60 | + |
| 61 | +function isRouteActive(pathname: string, item: NavigationItem) { |
| 62 | + return item.activePaths.some((activePath) => { |
| 63 | + if (pathname === activePath) return true; |
| 64 | + if (item.exact) return false; |
| 65 | + return pathname.startsWith(`${activePath}/`); |
| 66 | + }); |
| 67 | +} |
| 68 | + |
| 69 | +function BrandLogo() { |
| 70 | + return ( |
| 71 | + <p className="select-none whitespace-nowrap text-[32px] font-semibold leading-none text-foreground"> |
| 72 | + <span className="text-[#8ecaff]"><</span> |
| 73 | + <span>Cand</span> |
| 74 | + <span className="text-[#fea50b]">!</span> |
| 75 | + <span>Date</span> |
| 76 | + <span className="text-[#955dfc]">!</span> |
| 77 | + <span className="text-[#8ecaff]">></span> |
| 78 | + </p> |
| 79 | + ); |
| 80 | +} |
| 81 | + |
| 82 | +export function AuthenticatedSidebar() { |
| 83 | + const { logout } = useAuth(); |
| 84 | + const navigate = useNavigate(); |
| 85 | + const location = useLocation(); |
| 86 | + |
| 87 | + const handleLogout = async () => { |
| 88 | + await logout(); |
| 89 | + navigate("/login", { replace: true }); |
| 90 | + }; |
| 91 | + |
| 92 | + return ( |
| 93 | + <aside |
| 94 | + className="flex h-screen w-[249px] shrink-0 flex-col border-r border-border bg-card text-card-foreground shadow-[0_0_20px_rgba(0,0,0,0.04)] dark:shadow-[0_0_24px_rgba(0,0,0,0.22)]" |
| 95 | + aria-label="Menu lateral" |
| 96 | + > |
| 97 | + <div className="flex h-[103px] shrink-0 items-center px-[10px] pt-1"> |
| 98 | + <BrandLogo /> |
| 99 | + </div> |
| 100 | + |
| 101 | + <nav |
| 102 | + className="flex flex-1 flex-col gap-[22px] border-t border-dashed border-border/70 px-[13px] pt-[28px]" |
| 103 | + aria-label="Navegação principal" |
| 104 | + > |
| 105 | + {navigationItems.map((item) => { |
| 106 | + const Icon = item.icon; |
| 107 | + const isActive = isRouteActive(location.pathname, item); |
| 108 | + |
| 109 | + return ( |
| 110 | + <Link |
| 111 | + key={item.label} |
| 112 | + to={item.to} |
| 113 | + aria-current={isActive ? "page" : undefined} |
| 114 | + className={cn( |
| 115 | + sidebarItemClasses, |
| 116 | + "px-[13px]", |
| 117 | + isActive |
| 118 | + ? activeSidebarItemClasses |
| 119 | + : inactiveSidebarItemClasses, |
| 120 | + )} |
| 121 | + > |
| 122 | + <Icon |
| 123 | + className="h-6 w-6 shrink-0" |
| 124 | + strokeWidth={isActive ? 2.5 : 2.25} |
| 125 | + /> |
| 126 | + <span className="min-w-0 flex-1 truncate">{item.label}</span> |
| 127 | + </Link> |
| 128 | + ); |
| 129 | + })} |
| 130 | + </nav> |
| 131 | + |
| 132 | + <div className="flex shrink-0 flex-col gap-[22px] border-t border-dashed border-border/70 px-[13px] pb-[29px] pt-[28px]"> |
| 133 | + <button |
| 134 | + type="button" |
| 135 | + className={cn( |
| 136 | + sidebarItemClasses, |
| 137 | + inactiveSidebarItemClasses, |
| 138 | + "px-[8px] font-normal", |
| 139 | + )} |
| 140 | + > |
| 141 | + <UserRound className="h-6 w-6 shrink-0" strokeWidth={2.25} /> |
| 142 | + <span>Perfil</span> |
| 143 | + </button> |
| 144 | + <button |
| 145 | + type="button" |
| 146 | + className={cn( |
| 147 | + sidebarItemClasses, |
| 148 | + inactiveSidebarItemClasses, |
| 149 | + "px-[8px] font-normal", |
| 150 | + )} |
| 151 | + > |
| 152 | + <Headphones className="h-6 w-6 shrink-0" strokeWidth={2.25} /> |
| 153 | + <span>Ajuda</span> |
| 154 | + </button> |
| 155 | + <button |
| 156 | + type="button" |
| 157 | + className={cn( |
| 158 | + sidebarItemClasses, |
| 159 | + inactiveSidebarItemClasses, |
| 160 | + "px-[8px] font-normal", |
| 161 | + )} |
| 162 | + onClick={handleLogout} |
| 163 | + > |
| 164 | + <LogOut className="h-6 w-6 shrink-0" strokeWidth={2.25} /> |
| 165 | + <span>Sair</span> |
| 166 | + </button> |
| 167 | + </div> |
| 168 | + </aside> |
| 169 | + ); |
| 170 | +} |
0 commit comments