import { AppShell, Avatar, Box, Burger, Group, Menu, NavLink, rem, ScrollArea, Stack, Text, Tooltip, } from "@mantine/core"; import { useDisclosure } from "@mantine/hooks"; import { modals } from "@mantine/modals"; import { IconChevronRight, IconHome, IconKey, IconLogout, IconSettings, IconUser, IconUsers, } from "@tabler/icons-react"; import { createFileRoute, Outlet, useLocation, useNavigate, } from "@tanstack/react-router"; import { useSnapshot } from "valtio"; import { protectedRouteMiddleware } from "@/middleware/authMiddleware"; import { authClient } from "@/utils/auth-client"; import { authStore } from "../../store/auth"; export const Route = createFileRoute("/admin")({ component: DashboardLayout, beforeLoad: protectedRouteMiddleware, onEnter({ context }) { authStore.user = context?.user as any; authStore.session = context?.session as any; }, }); function DashboardLayout() { const location = useLocation(); const navigate = useNavigate(); const snap = useSnapshot(authStore); const [mobileOpened, { toggle: toggleMobile }] = useDisclosure(); const [desktopOpened, { toggle: toggleDesktop }] = useDisclosure(true); const navItems = [ { icon: IconHome, label: "Beranda", to: "/admin", description: "Ringkasan sistem & statistik", }, { icon: IconUsers, label: "Pengguna", to: "/admin/users", description: "Kelola akun & hak akses", }, { icon: IconKey, label: "API Key", to: "/admin/apikey", description: "Manajemen kunci akses API", }, { icon: IconSettings, label: "Pengaturan", to: "/admin/settings", description: "Konfigurasi sistem", }, ]; const handleLogout = async () => { modals.openConfirmModal({ title: "Konfirmasi Keluar", centered: true, children: ( Apakah Anda yakin ingin keluar dari sistem? Sesi Anda akan berakhir. ), labels: { confirm: "Keluar", cancel: "Batal" }, confirmProps: { color: "red" }, onConfirm: async () => { await authClient.signOut(); navigate({ to: "/signin" }); }, }); }; const isActive = (path: string) => { const current = location.pathname; if (path === "/admin") return current === "/admin" || current === "/admin/"; return current.startsWith(path); }; return ( ADMIN PANEL
{snap.user?.name} Administrator
{snap.user?.name?.charAt(0)}
Akun } onClick={() => navigate({ to: "/profile" })} > Profil Saya } onClick={() => navigate({ to: "/admin/settings" })} > Pengaturan Bahaya } onClick={handleLogout} > Keluar Sistem
{navItems.map((item) => ( { navigate({ to: item.to }); if (mobileOpened) toggleMobile(); }} leftSection={ } label={ {item.label} } rightSection={} active={isActive(item.to)} variant="light" color="orange" styles={{ root: { borderRadius: rem(8), marginBottom: rem(4), }, label: { fontSize: rem(14), }, }} /> ))} } styles={{ root: { borderRadius: rem(8) } }} /> } c="red" styles={{ root: { borderRadius: rem(8) } }} />
); }