admin-sidebar.tsx68 lines, 1.9 KB
| 1 | "use client"; |
| 2 | |
| 3 | import { usePathname } from "next/navigation"; |
| 4 | import { getNavItems, NavItem } from "./nav-items"; |
| 5 | import Link from "next/link"; |
| 6 | import { cn } from "@/lib/utils"; |
| 7 | import { Button } from "../ui/button"; |
| 8 | import { ChevronRight } from "lucide-react"; |
| 9 | |
| 10 | export function AdminSidebar() { |
| 11 | const pathname = usePathname(); |
| 12 | const navItems = getNavItems(); |
| 13 | |
| 14 | const isActive = (item: NavItem) => { |
| 15 | if (item.exact) { |
| 16 | return pathname === item.href; |
| 17 | } |
| 18 | |
| 19 | if ( |
| 20 | item.href === "/admin/urls" && |
| 21 | pathname.includes("/admin/urls/flagged") |
| 22 | ) { |
| 23 | return false; |
| 24 | } |
| 25 | |
| 26 | return pathname === item.href || pathname.startsWith(`${item.href}/`); |
| 27 | }; |
| 28 | |
| 29 | return ( |
| 30 | <div className="hidden md:flex md:w-64 md:flex-col md:fixed md:inset-y-0 md:pt-14 md:z-30 border-r bg-muted/40"> |
| 31 | <div className="flex h-14 items-center border-b px-4"> |
| 32 | <h2 className="text-lg font-semibold">Admin Dashbboard</h2> |
| 33 | </div> |
| 34 | <nav className="flex-1 overflow-auto py-4"> |
| 35 | <ul className="space-y-1 px-2"> |
| 36 | {navItems.map((item: NavItem) => ( |
| 37 | <li key={item.href}> |
| 38 | <Link |
| 39 | href={item.href} |
| 40 | className={cn( |
| 41 | "flex items-center gap-3 rounded-md px-3 py-2 text-sm font-medium transition-colors", |
| 42 | isActive(item) |
| 43 | ? "bg-primary text-primary-foreground" |
| 44 | : "hover:bg-muted" |
| 45 | )} |
| 46 | > |
| 47 | {item.icon} |
| 48 | {item.name} |
| 49 | </Link> |
| 50 | </li> |
| 51 | ))} |
| 52 | </ul> |
| 53 | </nav> |
| 54 | <div className="border-t p-4"> |
| 55 | <Link href={"/dashboard"}> |
| 56 | <Button |
| 57 | variant={"outline"} |
| 58 | size={"sm"} |
| 59 | className="w-full justify-start gap-2" |
| 60 | > |
| 61 | <ChevronRight className="size-4" /> |
| 62 | Back to App |
| 63 | </Button> |
| 64 | </Link> |
| 65 | </div> |
| 66 | </div> |
| 67 | ); |
| 68 | } |