%PDF- %PDF-
| Direktori : /home2/rezakur1/ai.rezakurnia.com/zh-router-frontend/src/components/layout/ |
| Current File : /home2/rezakur1/ai.rezakurnia.com/zh-router-frontend/src/components/layout/Sidebar.tsx |
import { NavLink } from "react-router-dom";
import { useAuth } from "@/contexts/AuthContext";
import { usePendingTopups } from "@/hooks/usePendingTopups";
import { useSidebarView, type SidebarView } from "@/hooks/useSidebarView";
import PartOf from "@/components/ui/PartOf";
export interface NavItem {
to: string;
label: string;
end?: boolean;
icon: (active: boolean) => React.ReactNode;
}
export const navItems: NavItem[] = [
{
to: "/dashboard",
label: "Dashboard",
end: true,
icon: (active) => (
<svg
className={`h-4 w-4 ${active ? "text-brand-300" : "text-slate-500"}`}
fill="none"
viewBox="0 0 24 24"
stroke="currentColor"
strokeWidth={1.7}
>
<path
strokeLinecap="round"
strokeLinejoin="round"
d="M3.75 6A2.25 2.25 0 016 3.75h2.25A2.25 2.25 0 0110.5 6v2.25a2.25 2.25 0 01-2.25 2.25H6a2.25 2.25 0 01-2.25-2.25V6zM3.75 15.75A2.25 2.25 0 016 13.5h2.25a2.25 2.25 0 012.25 2.25V18a2.25 2.25 0 01-2.25 2.25H6A2.25 2.25 0 013.75 18v-2.25zM13.5 6a2.25 2.25 0 012.25-2.25H18A2.25 2.25 0 0120.25 6v2.25A2.25 2.25 0 0118 10.5h-2.25a2.25 2.25 0 01-2.25-2.25V6zM13.5 15.75a2.25 2.25 0 012.25-2.25H18a2.25 2.25 0 012.25 2.25V18A2.25 2.25 0 0118 20.25h-2.25A2.25 2.25 0 0113.5 18v-2.25z"
/>
</svg>
),
},
{
to: "/keys",
label: "API Keys",
icon: (active) => (
<svg
className={`h-4 w-4 ${active ? "text-brand-300" : "text-slate-500"}`}
fill="none"
viewBox="0 0 24 24"
stroke="currentColor"
strokeWidth={1.7}
>
<path
strokeLinecap="round"
strokeLinejoin="round"
d="M15.75 5.25a3 3 0 013 3m3 0a6 6 0 01-7.029 5.912c-.563-.097-1.159.026-1.563.43L10.5 17.25H8.25v2.25H6v2.25H2.25v-2.818c0-.597.237-1.17.659-1.591l6.499-6.499c.404-.404.527-1 .43-1.563A6 6 0 1121.75 8.25z"
/>
</svg>
),
},
{
to: "/usage",
label: "Usage",
icon: (active) => (
<svg
className={`h-4 w-4 ${active ? "text-brand-300" : "text-slate-500"}`}
fill="none"
viewBox="0 0 24 24"
stroke="currentColor"
strokeWidth={1.7}
>
<path
strokeLinecap="round"
strokeLinejoin="round"
d="M3 13.125C3 12.504 3.504 12 4.125 12h2.25c.621 0 1.125.504 1.125 1.125v6.75C7.5 20.496 6.996 21 6.375 21h-2.25A1.125 1.125 0 013 19.875v-6.75zM9.75 9.75c0-.621.504-1.125 1.125-1.125h2.25c.621 0 1.125.504 1.125 1.125v10.125c0 .621-.504 1.125-1.125 1.125h-2.25a1.125 1.125 0 01-1.125-1.125V9.75zM16.5 6v0c0-.621.504-1.125 1.125-1.125h2.25C20.496 4.875 21 5.379 21 6v12.75c0 .621-.504 1.125-1.125 1.125h-2.25a1.125 1.125 0 01-1.125-1.125V6z"
/>
</svg>
),
},
{
to: "/models",
label: "Model",
icon: (active) => (
<svg
className={`h-4 w-4 ${active ? "text-brand-300" : "text-slate-500"}`}
fill="none"
viewBox="0 0 24 24"
stroke="currentColor"
strokeWidth={1.7}
>
<path
strokeLinecap="round"
strokeLinejoin="round"
d="M9.813 15.904L9 18.75l-.813-2.846a4.5 4.5 0 00-3.09-3.09L2.25 12l2.846-.813a4.5 4.5 0 003.09-3.09L9 5.25l.813 2.846a4.5 4.5 0 003.09 3.09L15.75 12l-2.846.813a4.5 4.5 0 00-3.09 3.09zM18.259 8.715L18 9.75l-.259-1.035a3.375 3.375 0 00-2.455-2.456L14.25 6l1.036-.259a3.375 3.375 0 002.455-2.456L18 2.25l.259 1.035a3.375 3.375 0 002.456 2.456L21.75 6l-1.035.259a3.375 3.375 0 00-2.456 2.456z"
/>
</svg>
),
},
{
to: "/docs",
label: "API Docs",
icon: (active) => (
<svg
className={`h-4 w-4 ${active ? "text-brand-300" : "text-slate-500"}`}
fill="none"
viewBox="0 0 24 24"
stroke="currentColor"
strokeWidth={1.7}
>
<path
strokeLinecap="round"
strokeLinejoin="round"
d="M12 6.042A8.967 8.967 0 006 3.75c-1.052 0-2.062.18-3 .512v14.25A8.987 8.987 0 016 18c1.896 0 3.68.586 5.132 1.585M12 6.042c1.052-.657 2.27-1.042 3.55-1.042 1.052 0 2.062.18 3 .512v14.25A8.987 8.987 0 0018 18c-1.896 0-3.68.586-5.132 1.585"
/>
</svg>
),
},
{
to: "/topup",
label: "Top Up",
icon: (active) => (
<svg
className={`h-4 w-4 ${active ? "text-brand-300" : "text-slate-500"}`}
fill="none"
viewBox="0 0 24 24"
stroke="currentColor"
strokeWidth={1.7}
>
<path
strokeLinecap="round"
strokeLinejoin="round"
d="M21 12a2.25 2.25 0 00-2.25-2.25H15a3 3 0 11-6 0H5.25A2.25 2.25 0 003 12m18 0v6a2.25 2.25 0 01-2.25 2.25H5.25A2.25 2.25 0 013 18v-6m18 0V9M3 12V9m18 0a2.25 2.25 0 00-2.25-2.25H5.25A2.25 2.25 0 003 9m18 0V6a2.25 2.25 0 00-2.25-2.25H5.25A2.25 2.25 0 003 6v3"
/>
</svg>
),
},
{
to: "/billing",
label: "Billing",
icon: (active) => (
<svg
className={`h-4 w-4 ${active ? "text-brand-300" : "text-slate-500"}`}
fill="none"
viewBox="0 0 24 24"
stroke="currentColor"
strokeWidth={1.7}
>
<path
strokeLinecap="round"
strokeLinejoin="round"
d="M2.25 18.75a60.07 60.07 0 0115.797 2.101c.727.198 1.453-.342 1.453-1.096V18.75M3.75 4.5v.75A.75.75 0 013 6h-.75m0 0v-.375c0-.621.504-1.125 1.125-1.125H20.25M2.25 6v9m18-10.5v.75c0 .414.336.75.75.75h.75m-1.5-1.5h.375c.621 0 1.125.504 1.125 1.125v9.75c0 .621-.504 1.125-1.125 1.125h-.375m1.5-1.5H21a.75.75 0 00-.75.75v.75m0 0H3.75m0 0h-.375a1.125 1.125 0 01-1.125-1.125V15m1.5 1.5v-.75A.75.75 0 003 15h-.75M15 10.5a3 3 0 11-6 0 3 3 0 016 0zm3 0h.008v.008H18V10.5zm-12 0h.008v.008H6V10.5z"
/>
</svg>
),
},
{
to: "/packages",
label: "Paket",
icon: (active) => (
<svg
className={`h-4 w-4 ${active ? "text-brand-300" : "text-slate-500"}`}
fill="none"
viewBox="0 0 24 24"
stroke="currentColor"
strokeWidth={1.7}
>
<path
strokeLinecap="round"
strokeLinejoin="round"
d="M20.25 7.5l-.625 10.632a2.25 2.25 0 01-2.247 2.118H6.622a2.25 2.25 0 01-2.247-2.118L3.75 7.5M10 11.25h4M3.375 7.5h17.25c.621 0 1.125-.504 1.125-1.125v-1.5c0-.621-.504-1.125-1.125-1.125H3.375c-.621 0-1.125.504-1.125 1.125v1.5c0 .621.504 1.125 1.125 1.125z"
/>
</svg>
),
},
{
to: "/profile",
label: "Profil",
icon: (active) => (
<svg
className={`h-4 w-4 ${active ? "text-brand-300" : "text-slate-500"}`}
fill="none"
viewBox="0 0 24 24"
stroke="currentColor"
strokeWidth={1.7}
>
<path
strokeLinecap="round"
strokeLinejoin="round"
d="M15.75 6a3.75 3.75 0 11-7.5 0 3.75 3.75 0 017.5 0zM4.501 20.118a7.5 7.5 0 0114.998 0A17.933 17.933 0 0112 21.75c-2.676 0-5.216-.584-7.499-1.632z"
/>
</svg>
),
},
];
export const adminItems: NavItem[] = [
{
to: "/admin",
label: "Dashboard Admin",
end: true,
icon: (active) => (
<svg
className={`h-4 w-4 ${active ? "text-brand-300" : "text-slate-500"}`}
fill="none"
viewBox="0 0 24 24"
stroke="currentColor"
strokeWidth={1.7}
>
<path
strokeLinecap="round"
strokeLinejoin="round"
d="M3.75 6A2.25 2.25 0 016 3.75h2.25A2.25 2.25 0 0110.5 6v2.25a2.25 2.25 0 01-2.25 2.25H6a2.25 2.25 0 01-2.25-2.25V6zM3.75 15.75A2.25 2.25 0 016 13.5h2.25a2.25 2.25 0 012.25 2.25V18a2.25 2.25 0 01-2.25 2.25H6A2.25 2.25 0 013.75 18v-2.25zM13.5 6a2.25 2.25 0 012.25-2.25H18A2.25 2.25 0 0120.25 6v2.25A2.25 2.25 0 0118 10.5h-2.25a2.25 2.25 0 01-2.25-2.25V6zM13.5 15.75a2.25 2.25 0 012.25-2.25H18a2.25 2.25 0 012.25 2.25V18A2.25 2.25 0 0118 20.25h-2.25A2.25 2.25 0 0113.5 18v-2.25z"
/>
</svg>
),
},
{
to: "/admin/service-status",
label: "Service Status",
icon: (active) => (
<svg
className={`h-4 w-4 ${active ? "text-brand-300" : "text-slate-500"}`}
fill="none"
viewBox="0 0 24 24"
stroke="currentColor"
strokeWidth={1.7}
>
<path
strokeLinecap="round"
strokeLinejoin="round"
d="M21.75 17.25v-.228a4.5 4.5 0 00-.12-1.03l-2.268-9.64a3.375 3.375 0 00-3.285-2.602H7.923a3.375 3.375 0 00-3.285 2.602l-2.268 9.64a4.5 4.5 0 00-.12 1.03v.228m19.5 0a3 3 0 01-3 3H5.25a3 3 0 01-3-3m19.5 0a3 3 0 00-3-3H5.25a3 3 0 00-3 3m16.5 0h.008v.008h-.008v-.008zm-3 0h.008v.008h-.008v-.008z"
/>
</svg>
),
},
{
to: "/admin/users",
label: "Pengguna",
icon: (active) => (
<svg
className={`h-4 w-4 ${active ? "text-brand-300" : "text-slate-500"}`}
fill="none"
viewBox="0 0 24 24"
stroke="currentColor"
strokeWidth={1.7}
>
<path
strokeLinecap="round"
strokeLinejoin="round"
d="M15 19.128a9.38 9.38 0 002.625.372 9.337 9.337 0 004.121-.952 4.125 4.125 0 00-7.533-2.493M15 19.128v-.003c0-1.113-.285-2.16-.786-3.07M15 19.128v.106A12.318 12.318 0 018.624 21c-2.331 0-4.512-.645-6.374-1.766l-.001-.109a6.375 6.375 0 0111.964-3.07M12 6.375a3.375 3.375 0 11-6.75 0 3.375 3.375 0 016.75 0zm8.25 2.25a2.625 2.625 0 11-5.25 0 2.625 2.625 0 015.25 0z"
/>
</svg>
),
},
{
to: "/admin/analytics",
label: "Analisa User",
icon: (active) => (
<svg
className={`h-4 w-4 ${active ? "text-brand-300" : "text-slate-500"}`}
fill="none"
viewBox="0 0 24 24"
stroke="currentColor"
strokeWidth={1.7}
>
<path
strokeLinecap="round"
strokeLinejoin="round"
d="M3 13.125C3 12.504 3.504 12 4.125 12h2.25c.621 0 1.125.504 1.125 1.125v6.75C7.5 20.496 6.996 21 6.375 21h-2.25A1.125 1.125 0 013 19.875v-6.75zM9.75 9.75c0-.621.504-1.125 1.125-1.125h2.25c.621 0 1.125.504 1.125 1.125v10.125c0 .621-.504 1.125-1.125 1.125h-2.25a1.125 1.125 0 01-1.125-1.125V9.75zM16.5 6v0c0-.621.504-1.125 1.125-1.125h2.25C20.496 4.875 21 5.379 21 6v12.75c0 .621-.504 1.125-1.125 1.125h-2.25a1.125 1.125 0 01-1.125-1.125V6z"
/>
</svg>
),
},
{
to: "/admin/usage",
label: "Penggunaan",
icon: (active) => (
<svg
className={`h-4 w-4 ${active ? "text-brand-300" : "text-slate-500"}`}
fill="none"
viewBox="0 0 24 24"
stroke="currentColor"
strokeWidth={1.7}
>
<path
strokeLinecap="round"
strokeLinejoin="round"
d="M3 13.125C3 12.504 3.504 12 4.125 12h2.25c.621 0 1.125.504 1.125 1.125v6.75C7.5 20.496 6.996 21 6.375 21h-2.25A1.125 1.125 0 013 19.875v-6.75zM9.75 9.75c0-.621.504-1.125 1.125-1.125h2.25c.621 0 1.125.504 1.125 1.125v10.125c0 .621-.504 1.125-1.125 1.125h-2.25a1.125 1.125 0 01-1.125-1.125V9.75zM16.5 6v0c0-.621.504-1.125 1.125-1.125h2.25C20.496 4.875 21 5.379 21 6v12.75c0 .621-.504 1.125-1.125 1.125h-2.25a1.125 1.125 0 01-1.125-1.125V6z"
/>
</svg>
),
},
{
to: "/admin/topup",
label: "Verifikasi Top Up",
icon: (active) => (
<svg
className={`h-4 w-4 ${active ? "text-brand-300" : "text-slate-500"}`}
fill="none"
viewBox="0 0 24 24"
stroke="currentColor"
strokeWidth={1.7}
>
<path
strokeLinecap="round"
strokeLinejoin="round"
d="M2.25 8.25h19.5m-16.5.75h12a2.25 2.25 0 012.25 2.25v3a2.25 2.25 0 01-2.25 2.25h-12A2.25 2.25 0 012.25 14.25v-3a2.25 2.25 0 012.25-2.25z"
/>
</svg>
),
},
{
to: "/admin/qris",
label: "QRIS",
icon: (active) => (
<svg
className={`h-4 w-4 ${active ? "text-brand-300" : "text-slate-500"}`}
fill="none"
viewBox="0 0 24 24"
stroke="currentColor"
strokeWidth={1.7}
>
<path
strokeLinecap="round"
strokeLinejoin="round"
d="M3.75 4.875c0-.621.504-1.125 1.125-1.125h4.5c.621 0 1.125.504 1.125 1.125v4.5c0 .621-.504 1.125-1.125 1.125h-4.5A1.125 1.125 0 013.75 9.375v-4.5zM3.75 14.625c0-.621.504-1.125 1.125-1.125h4.5c.621 0 1.125.504 1.125 1.125v4.5c0 .621-.504 1.125-1.125 1.125h-4.5a1.125 1.125 0 01-1.125-1.125v-4.5zM13.5 4.875c0-.621.504-1.125 1.125-1.125h4.5c.621 0 1.125.504 1.125 1.125v4.5c0 .621-.504 1.125-1.125 1.125h-4.5A1.125 1.125 0 0113.5 9.375v-4.5zM13.5 14.625c0-.621.504-1.125 1.125-1.125h4.5c.621 0 1.125.504 1.125 1.125v4.5c0 .621-.504 1.125-1.125 1.125h-4.5a1.125 1.125 0 01-1.125-1.125v-4.5z"
/>
</svg>
),
},
{
to: "/admin/packages",
label: "Paket",
icon: (active) => (
<svg
className={`h-4 w-4 ${active ? "text-brand-300" : "text-slate-500"}`}
fill="none"
viewBox="0 0 24 24"
stroke="currentColor"
strokeWidth={1.7}
>
<path
strokeLinecap="round"
strokeLinejoin="round"
d="M20.25 7.5l-.625 10.632a2.25 2.25 0 01-2.247 2.118H6.622a2.25 2.25 0 01-2.247-2.118L3.75 7.5M10 11.25h4M3.375 7.5h17.25c.621 0 1.125-.504 1.125-1.125v-1.5c0-.621-.504-1.125-1.125-1.125H3.375c-.621 0-1.125.504-1.125 1.125v1.5c0 .621.504 1.125 1.125 1.125z"
/>
</svg>
),
},
{
to: "/admin/models",
label: "Model",
icon: (active) => (
<svg
className={`h-4 w-4 ${active ? "text-brand-300" : "text-slate-500"}`}
fill="none"
viewBox="0 0 24 24"
stroke="currentColor"
strokeWidth={1.7}
>
<path
strokeLinecap="round"
strokeLinejoin="round"
d="M9.813 15.904L9 18.75l-.813-2.846a4.5 4.5 0 00-3.09-3.09L2.25 12l2.846-.813a4.5 4.5 0 003.09-3.09L9 5.25l.813 2.846a4.5 4.5 0 003.09 3.09L15.75 12l-2.846.813a4.5 4.5 0 00-3.09 3.09zM18.259 8.715L18 9.75l-.259-1.035a3.375 3.375 0 00-2.455-2.456L14.25 6l1.036-.259a3.375 3.375 0 002.455-2.456L18 2.25l.259 1.035a3.375 3.375 0 002.456 2.456L21.75 6l-1.035.259a3.375 3.375 0 00-2.456 2.456z"
/>
</svg>
),
},
];
function Logo() {
return (
<div className="flex items-center gap-3 px-5 py-5">
<img
src="/logo-kd.png"
alt="KURNIADEV AI"
className="h-9 w-auto shrink-0 rounded-lg object-contain"
/>
<div className="leading-tight">
<p className="text-[13px] font-semibold tracking-tight text-white">
KURNIADEV AI
</p>
<p className="text-[11px] font-medium text-slate-500">API Gateway</p>
</div>
</div>
);
}
function NavItemLink({
item,
badge,
}: {
item: NavItem;
badge?: number;
}) { return (
<NavLink
to={item.to}
end={item.end}
className={({ isActive }) =>
`relative flex items-center gap-2.5 rounded-lg px-2.5 py-1.5 text-sm font-medium transition-colors duration-150 ${
isActive
? "bg-white/[0.06] text-white"
: "text-slate-400 hover:bg-white/[0.03] hover:text-slate-200"
}`
}
>
{({ isActive }) => (
<>
{isActive && (
<span className="absolute left-0 top-1/2 h-4 w-0.5 -translate-y-1/2 rounded-full bg-blue-400" />
)}
<span
className={`flex h-7 w-7 shrink-0 items-center justify-center rounded-lg border transition-colors ${
isActive
? "border-brand-400/20 bg-brand-500/10"
: "border-white/[0.05] bg-white/[0.02]"
}`}
>
{item.icon(isActive)}
</span>
{item.label}
{badge !== undefined && badge > 0 && (
<span
title={`${badge} order menunggu verifikasi`}
className="ml-auto flex h-5 min-w-[20px] items-center justify-center rounded-full border border-brand-400/25 bg-brand-500/15 px-1.5 text-[10px] font-bold leading-none tabular-nums text-brand-300"
>
{badge > 99 ? "99+" : badge}
</span>
)}
</>
)}
</NavLink>
);
}
/** Toggle mode sidebar: menu pengguna ↔ menu admin (hanya untuk admin). */
function ViewToggle({
view,
onChange,
}: {
view: SidebarView;
onChange: (v: SidebarView) => void;
}) {
const options: { value: SidebarView; label: string; icon: string }[] = [
{
value: "user",
label: "Pengguna",
icon: "M15.75 6a3.75 3.75 0 11-7.5 0 3.75 3.75 0 017.5 0zM4.501 20.118a7.5 7.5 0 0114.998 0A17.933 17.933 0 0112 21.75c-2.676 0-5.216-.584-7.499-1.632z",
},
{
value: "admin",
label: "Admin",
icon: "M9 12.75L11.25 15 15 9.75m-3-7.036A11.959 11.959 0 013.598 6 11.99 11.99 0 003 9.749c0 5.592 3.824 10.29 9 11.623 5.176-1.332 9-6.03 9-11.622 0-1.31-.21-2.571-.598-3.751h-.152c-3.196 0-6.1-1.248-8.25-3.285z",
},
];
return (
<div className="mx-3 mt-2 grid grid-cols-2 gap-1 rounded-xl border border-white/[0.06] bg-white/[0.02] p-1">
{options.map((opt) => (
<button
key={opt.value}
type="button"
onClick={() => onChange(opt.value)}
aria-pressed={view === opt.value}
className={`flex items-center justify-center gap-1.5 rounded-lg px-2 py-1.5 text-xs font-medium transition-colors ${
view === opt.value
? "bg-white/[0.08] text-white"
: "text-slate-500 hover:text-slate-300"
}`}
>
<svg
className="h-3.5 w-3.5"
fill="none"
viewBox="0 0 24 24"
stroke="currentColor"
strokeWidth={1.7}
>
<path
strokeLinecap="round"
strokeLinejoin="round"
d={opt.icon}
/>
</svg>
{opt.label}
</button>
))}
</div>
);
}
export default function Sidebar() {
const { user } = useAuth();
const { count: pendingTopups } = usePendingTopups();
const { view, setView } = useSidebarView();
const isAdmin = Number(user?.is_admin) === 1;
const activeView: SidebarView = isAdmin ? view : "user";
const visibleNavItems = activeView === "admin" ? adminItems : navItems;
const sectionLabel = activeView === "admin" ? "Menu Administrasi" : "Menu Utama";
return (
<aside className="fixed inset-y-0 left-0 z-30 hidden w-64 flex-col border-r border-white/[0.06] bg-ink/80 backdrop-blur-xl lg:flex">
<Logo />
{isAdmin && <ViewToggle view={view} onChange={setView} />}
<nav className="flex-1 space-y-0.25 px-3">
<p className="px-3.5 pb-1.5 pt-3 text-[10px] font-semibold uppercase tracking-widest text-slate-600">
{sectionLabel}
</p>
{visibleNavItems.map((item) => (
<NavItemLink
key={item.to}
item={item}
badge={item.to === "/admin/topup" ? pendingTopups : undefined}
/>
))}
</nav>
{/* Kartu user */}
{user && (
<div className="m-3 rounded-xl border border-white/[0.06] bg-white/[0.03] p-3">
<div className="flex items-center gap-3">
<div className="relative">
<div className="flex h-8 w-8 items-center justify-center rounded-full bg-ink-700 text-sm font-semibold text-white">
{user.name.charAt(0).toUpperCase()}
</div>
<span className="absolute -bottom-0.5 -right-0.5 h-2.5 w-2.5 rounded-full border-2 border-ink-900 bg-emerald-400" />
</div>
<div className="min-w-0">
<p className="truncate text-sm font-medium text-white">
{user.name}
</p>
<p className="truncate text-[11px] text-slate-500">
{user.email}
</p>
</div>
</div>
</div>
)}
{/* Part Of — badge di bagian bawah sidebar */}
<div className="flex flex-col items-center gap-1.5 pb-4">
<PartOf />
<p className="text-[10px] font-medium tracking-wide text-slate-600">
v{__APP_VERSION__} · build {__BUILD_TIME__}
</p>
</div>
</aside>
);
}