| 1 | "use client"; |
| 2 | |
| 3 | import { usePathname, useRouter } from "next/navigation"; |
| 4 | import { useTranslations } |
| 5 | import { |
| 6 | Sidebar, |
| 7 | SidebarHeader, |
| 8 | SidebarContent, |
| 9 | SidebarGroup, |
| 10 | SidebarGroupContent, |
| 11 | SidebarMenu, |
| 12 | SidebarMenuItem, |
| 13 | SidebarMenuButton, |
| 14 | SidebarTrigger, |
| 15 | } from "@struxa/ui/components/sidebar"; |
| 16 | import { |
| 17 | DropdownMenu, |
| 18 | DropdownMenuContent, |
| 19 | DropdownMenuItem, |
| 20 | DropdownMenuSeparator, |
| 21 | DropdownMenuTrigger, |
| 22 | } from "@struxa/ui/components/dropdown-menu"; |
| 23 | import { |
| 24 | LayoutDashboard, |
| 25 | Server, |
| 26 | Package, |
| 27 | Database, |
| 28 | Monitor, |
| 29 | Users, |
| 30 | Settings2, |
| 31 | LogOut, |
| 32 | ChevronLeft, |
| 33 | Activity, |
| 34 | CreditCard, |
| 35 | } from "lucide-react"; |
| 36 | import Link from "next/link |
| 37 | import { authClient } |
| 38 | import { DitherAvatar } |
| 39 | |
| 40 | export function AdminSidebar() |
| 41 | const t = |
| 42 | const tc = |
| 43 | const pathname = |
| 44 | const router = |
| 45 | const { data: |
| 46 | const user = |
| 47 | const avatarImage = |
| 48 | |
| 49 | async function handleLogout |
| 50 | await authClient.signOut |
| 51 | router.push("/login |
| 52 | } |
| 53 | |
| 54 | function isActive(href |
| 55 | if (href === |
| 56 | return pathname.startsWith |
| 57 | } |
| 58 | |
| 59 | const NAV_ITEMS = |
| 60 | { key: "dashboard", |
| 61 | { key: "nodes", |
| 62 | { key: "nests", |
| 63 | { key: "database-hosts", |
| 64 | { key: "servers", |
| 65 | { key: "users", |
| 66 | { key: "billing", |
| 67 | { key: "activity", |
| 68 | { key: "settings", |
| 69 | ]; |
| 70 | |
| 71 | return ( |
| 72 | <Sidebar collapsible=" |
| 73 | <SidebarHeader className=" |
| 74 | <div className="hidden group-data-[collapsible=icon]:flex justify-center py-2 |
| 75 | <DropdownMenu> |
| 76 | <DropdownMenuTrigger className=" |
| 77 | {avatarImage ? ( |
| 78 | // eslint-disable-next-line @next/next/no-img-element |
| 79 | <img src={avatarImage |
| 80 | ) : ( |
| 81 | <DitherAvatar name={ |
| 82 | )} |
| 83 | </DropdownMenuTrigger> |
| 84 | <DropdownMenuContent side=" |
| 85 | <DropdownMenuItem |
| 86 | onClick={() => |
| 87 | className="flex cursor-pointer items-center gap-2.5 rounded-lg px-3 py-2 text-sm text-muted-foreground hover:bg-muted hover:text-foreground focus:bg-muted focus:text-foreground" |
| 88 | > |
| 89 | <ChevronLeft className=" |
| 90 | {tc("backToPanel") |
| 91 | </DropdownMenuItem> |
| 92 | <DropdownMenuSeparator className=" |
| 93 | <DropdownMenuItem |
| 94 | onClick={handleLogout} |
| 95 | className="flex cursor-pointer items-center gap-2.5 rounded-lg px-3 py-2 text-sm text-muted-foreground hover:bg-muted hover:text-foreground focus:bg-muted focus:text-foreground" |
| 96 | > |
| 97 | <LogOut className=" |
| 98 | {tc("signOut") |
| 99 | </DropdownMenuItem> |
| 100 | </DropdownMenuContent> |
| 101 | </DropdownMenu> |
| 102 | </div> |
| 103 | |
| 104 | <div className="group-data-[collapsible=icon]:hidden px-2 py-1.5 |
| 105 | <DropdownMenu> |
| 106 | <DropdownMenuTrigger className=" |
| 107 | <div className="flex h-6 w-6 shrink-0 items-center justify-center rounded-md bg-muted text-xs font-semibold text-foreground overflow-hidden |
| 108 | {avatarImage ? ( |
| 109 | // eslint-disable-next-line @next/next/no-img-element |
| 110 | <img src={avatarImage |
| 111 | ) : ( |
| 112 | <DitherAvatar name={ |
| 113 | )} |
| 114 | </div> |
| 115 | <div className="min-w-0 flex-1 text-left |
| 116 | <p className="truncate text-sm font-medium text-foreground |
| 117 | </div> |
| 118 | </DropdownMenuTrigger> |
| 119 | <DropdownMenuContent side=" |
| 120 | <DropdownMenuItem |
| 121 | onClick={() => |
| 122 | className="flex cursor-pointer items-center gap-2.5 rounded-lg px-3 py-2 text-sm text-muted-foreground hover:bg-muted hover:text-foreground focus:bg-muted focus:text-foreground" |
| 123 | > |
| 124 | <ChevronLeft className=" |
| 125 | {tc("backToPanel") |
| 126 | </DropdownMenuItem> |
| 127 | <DropdownMenuSeparator className=" |
| 128 | <DropdownMenuItem |
| 129 | onClick={handleLogout} |
| 130 | className="flex cursor-pointer items-center gap-2.5 rounded-lg px-3 py-2 text-sm text-muted-foreground hover:bg-muted hover:text-foreground focus:bg-muted focus:text-foreground" |
| 131 | > |
| 132 | <LogOut className=" |
| 133 | {tc("signOut") |
| 134 | </DropdownMenuItem> |
| 135 | </DropdownMenuContent> |
| 136 | </DropdownMenu> |
| 137 | </div> |
| 138 | </SidebarHeader> |
| 139 | |
| 140 | <SidebarContent className=" |
| 141 | <SidebarGroup className=" |
| 142 | <SidebarGroupContent> |
| 143 | <SidebarMenu> |
| 144 | {NAV_ITEMS.map(( |
| 145 | <SidebarMenuItem key={ |
| 146 | <SidebarMenuButton |
| 147 | render={<Link |
| 148 | isActive={isActive(item |
| 149 | tooltip={item.label |
| 150 | className="h-auto gap-2 rounded-lg py-2 px-3 text-sm" |
| 151 | > |
| 152 | <item.icon className=" |
| 153 | {item.label} |
| 154 | </SidebarMenuButton> |
| 155 | </SidebarMenuItem> |
| 156 | ))} |
| 157 | </SidebarMenu> |
| 158 | </SidebarGroupContent> |
| 159 | </SidebarGroup> |
| 160 | </SidebarContent> |
| 161 | |
| 162 | <div className="border-t border-sidebar-border |
| 163 | <div className="hidden group-data-[collapsible=icon]:flex justify-center py-3 |
| 164 | <SidebarTrigger className=" |
| 165 | </div> |
| 166 | <div className="group-data-[collapsible=icon]:hidden flex items-center gap-2 px-4 py-3 |
| 167 | <SidebarTrigger className=" |
| 168 | <div> |
| 169 | <p className="text-[10px] text-muted-foreground/50 |
| 170 | <p className="text-[10px] text-muted-foreground/40 |
| 171 | {process.env.NODE_ENV |
| 172 | ? "in-dev" |
| 173 | : [process.env |
| 174 | </p> |
| 175 | </div> |
| 176 | </div> |
| 177 | </div> |
| 178 | </Sidebar> |
| 179 | ); |
| 180 | } |