Spaces:
Running
Running
File size: 8,543 Bytes
f1ef83d 6ab74c7 f1ef83d 6ab74c7 f1ef83d 6ab74c7 f1ef83d 6ab74c7 f1ef83d 6ab74c7 f1ef83d 6ab74c7 f1ef83d 6ab74c7 f1ef83d | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 | "use client";
import React, { useState } from "react";
import Link from "next/link";
import { usePathname, useRouter } from "next/navigation";
import {
Activity,
ArrowRight,
BarChart3,
CloudUpload,
FolderOpen,
Lock,
LogOut,
Menu,
Shield,
Terminal,
X,
} from "lucide-react";
import { useAuth } from "@/features/auth";
import { SITE_CONFIG } from "@/shared/config/site";
import { Button, Pill, Skeleton } from "@/shared/ui";
const TABS = [
{ href: "/dashboard", label: "Tổng quan", icon: BarChart3 },
{ href: "/explorer", label: "Kho tệp", icon: FolderOpen },
{ href: "/activity", label: "Nhật ký", icon: Activity },
{ href: "/developers", label: "API Docs", icon: Terminal },
{ href: "/admin", label: "Quản trị RBAC", icon: Shield, adminOnly: true },
] as const;
export function TopCommandShell({ children }: { children: React.ReactNode }) {
const pathname = usePathname();
const router = useRouter();
const { user, loading, healthOk, bucketName, isAdmin, logout } = useAuth();
const [mobileMenu, setMobileMenu] = useState(false);
if (loading) {
return (
<div className="min-h-screen flex items-center justify-center bg-drafting-grid p-6">
<div className="paper-card rounded-2xl p-8 w-full max-w-sm space-y-4">
<div className="flex items-center gap-3">
<div className="w-10 h-10 rounded-xl bg-orange-50 border border-orange-200 flex items-center justify-center text-[#c2410c]">
<CloudUpload className="w-5 h-5 animate-pulse" aria-hidden="true" />
</div>
<div className="space-y-1.5 flex-1">
<Skeleton className="h-3.5 w-36" />
<Skeleton className="h-3 w-48" />
</div>
</div>
<Skeleton className="h-2.5 w-full" />
</div>
</div>
);
}
if (!user) {
return (
<div className="min-h-screen flex items-center justify-center bg-drafting-grid p-6">
<div className="paper-card rounded-3xl p-8 max-w-md w-full text-center space-y-5">
<div className="w-12 h-12 rounded-2xl bg-orange-50 border border-orange-200 flex items-center justify-center text-[#c2410c] mx-auto">
<Lock className="w-6 h-6" aria-hidden="true" />
</div>
<div className="space-y-2">
<h1 className="text-xl font-bold text-[#111318] font-display">
Vui lòng đăng nhập Studio
</h1>
<p className="text-xs sm:text-sm text-slate-600 leading-relaxed">
Phiên làm việc chưa được xác thực. Đăng nhập để quản lý kho tệp của bạn.
</p>
</div>
<div className="flex flex-wrap justify-center gap-3">
<Link
href="/login"
className="px-5 py-2.5 rounded-xl bg-[#c2410c] hover:bg-[#9a3412] text-white font-bold text-sm inline-flex items-center gap-2"
>
<span>Đăng nhập</span>
<ArrowRight className="w-4 h-4" aria-hidden="true" />
</Link>
<Link
href="/"
className="px-5 py-2.5 rounded-xl bg-white border border-[#e7e5e0] text-[#111318] font-semibold text-sm hover:bg-[#f5f4f0]"
>
Trang chủ
</Link>
</div>
</div>
</div>
);
}
const visibleTabs = TABS.filter((tab) => !("adminOnly" in tab && tab.adminOnly) || isAdmin);
const handleSignOut = async () => {
await logout();
router.push("/login");
};
return (
<div className="min-h-screen flex flex-col bg-drafting-grid">
<header className="sticky top-0 z-40 paper-panel border-x-0 border-t-0">
<div className="max-w-7xl mx-auto px-4 sm:px-8 h-16 flex items-center justify-between gap-4">
<div className="flex items-center gap-4 min-w-0">
<Link href="/" className="flex items-center gap-2.5 shrink-0">
<div className="w-8 h-8 rounded-lg bg-[#c2410c] text-white flex items-center justify-center font-black text-xs font-display">
UT
</div>
<span className="font-bold text-sm sm:text-base text-[#111318] font-display">
{SITE_CONFIG.name}
</span>
</Link>
<span className="hidden md:inline text-xs font-mono text-slate-400 border-l border-[#e7e5e0] pl-4 truncate">
{bucketName}
</span>
</div>
<div className="flex items-center gap-2.5">
<Pill tone={healthOk ? "emerald" : "amber"} className="hidden sm:inline-flex">
<span
className={`w-1.5 h-1.5 rounded-full ${healthOk ? "bg-emerald-500" : "bg-amber-500"}`}
aria-hidden="true"
/>
<span>{healthOk ? "Ready" : "Sync"}</span>
</Pill>
<Pill tone={isAdmin ? "vermilion" : "ink"}>@{user.username}</Pill>
<Button
variant="ghost"
size="sm"
onClick={handleSignOut}
className="hidden sm:inline-flex text-rose-700 hover:bg-rose-50"
>
<LogOut className="w-3.5 h-3.5" aria-hidden="true" />
<span>Thoát</span>
</Button>
<button
type="button"
onClick={() => setMobileMenu((prev) => !prev)}
aria-label={mobileMenu ? "Đóng menu" : "Mở menu"}
className="md:hidden p-2 rounded-lg border border-[#e7e5e0] bg-white text-[#111318]"
>
{mobileMenu ? (
<X className="w-4 h-4" aria-hidden="true" />
) : (
<Menu className="w-4 h-4" aria-hidden="true" />
)}
</button>
</div>
</div>
{/* Horizontal Studio Tabs */}
<div className="hidden md:block border-t border-[#e7e5e0] bg-[#fafaf8]/90">
<nav
aria-label="Điều hướng Studio"
className="max-w-7xl mx-auto px-4 sm:px-8 flex items-center gap-1 overflow-x-auto"
>
{visibleTabs.map((tab) => {
const Icon = tab.icon;
const active = pathname === tab.href;
return (
<Link
key={tab.href}
href={tab.href}
aria-current={active ? "page" : undefined}
className={`inline-flex items-center gap-2 px-4 py-3 text-xs font-semibold border-b-2 transition whitespace-nowrap ${
active
? "border-[#c2410c] text-[#111318]"
: "border-transparent text-slate-600 hover:text-[#111318]"
}`}
>
<Icon
className={`w-3.5 h-3.5 ${active ? "text-[#c2410c]" : "text-slate-400"}`}
aria-hidden="true"
/>
<span>{tab.label}</span>
</Link>
);
})}
</nav>
</div>
{mobileMenu && (
<nav
aria-label="Điều hướng di động"
className="md:hidden border-t border-[#e7e5e0] bg-white px-4 py-3 space-y-1"
>
{visibleTabs.map((tab) => {
const Icon = tab.icon;
const active = pathname === tab.href;
return (
<Link
key={tab.href}
href={tab.href}
onClick={() => setMobileMenu(false)}
className={`flex items-center gap-2.5 px-3 py-2.5 rounded-xl text-xs font-semibold ${
active
? "bg-orange-50 text-[#c2410c]"
: "text-slate-700 hover:bg-[#fafaf8]"
}`}
>
<Icon className="w-4 h-4" aria-hidden="true" />
<span>{tab.label}</span>
</Link>
);
})}
<button
type="button"
onClick={handleSignOut}
className="w-full flex items-center gap-2.5 px-3 py-2.5 rounded-xl text-xs font-semibold text-rose-700 hover:bg-rose-50"
>
<LogOut className="w-4 h-4" aria-hidden="true" />
<span>Đăng xuất</span>
</button>
</nav>
)}
</header>
<main id="main-content" className="flex-1 flex flex-col">
{children}
</main>
</div>
);
}
|