Download apps/web/src/components/AdminShell.tsx from aliroya/contiai: direct link, hf CLI and curl.
- Browser
- Download file 8.41 kB
-
https://huggingface.co/spaces/aliroya/contiai/resolve/main/apps/web/src/components/AdminShell.tsx
- Command line
-
hf download hf://spaces/aliroya/contiai/apps/web/src/components/AdminShell.tsx
-
curl -L -o AdminShell.tsx https://huggingface.co/spaces/aliroya/contiai/resolve/main/apps/web/src/components/AdminShell.tsx
8.41 kB
| import { NavLink, Outlet, useLocation } from "react-router-dom"; | |
| import { useAuth } from "@/features/auth/AuthProvider"; | |
| import { Icon, type IconName } from "@/components/Icon"; | |
| import { Ltr } from "@/components/ui"; | |
| import { t } from "@/strings/ar"; | |
| /** | |
| * The administration space, per ContiAI Admin.dc.html. | |
| * | |
| * Same rail as the product - dark navy, 258px, the mark as a watermark - so | |
| * the two spaces are recognisably one system. What distinguishes them is the | |
| * navigation itself, which is the honest signal: seven administrative | |
| * destinations rather than four working ones. | |
| * | |
| * There is deliberately no banner across the top. The rail already says where | |
| * you are on every screen, and a fixed bar repeating it cost 46px of vertical | |
| * space on every page to tell an administrator something they knew. | |
| */ | |
| const NAV: { to: string; label: string; icon: IconName; end?: boolean }[] = [ | |
| { to: "/admin", label: t.admin.overview, icon: "grid", end: true }, | |
| { to: "/admin/users", label: t.admin.users, icon: "user" }, | |
| { to: "/admin/usage", label: "الاستهلاك التفصيلي", icon: "bars" }, | |
| { to: "/admin/runs", label: t.admin.runs, icon: "playRing" }, | |
| { to: "/admin/task-types", label: t.admin.taskTypes, icon: "book" }, | |
| { to: "/admin/announcements", label: t.admin.announcements, icon: "bell" }, | |
| { to: "/admin/audit", label: t.admin.audit, icon: "shield" }, | |
| ]; | |
| function Item({ item }: { item: (typeof NAV)[number] }) { | |
| return ( | |
| <NavLink | |
| to={item.to} | |
| end={item.end} | |
| className={({ isActive }) => | |
| [ | |
| "flex min-h-11 items-center gap-3 rounded-md px-3 py-2.5", | |
| "text-item transition-colors duration-200", | |
| isActive | |
| ? "bg-[var(--color-brand-700)] font-bold text-white" | |
| : "font-medium text-[var(--rail-item)] hover:bg-white/[0.07]", | |
| ].join(" ") | |
| } | |
| > | |
| {({ isActive }) => ( | |
| <> | |
| <span | |
| className="grid size-5 shrink-0 place-items-center" | |
| style={{ color: isActive ? "#fff" : "var(--rail-icon)" }} | |
| > | |
| <Icon name={item.icon} size={19} /> | |
| </span> | |
| <span>{item.label}</span> | |
| </> | |
| )} | |
| </NavLink> | |
| ); | |
| } | |
| export default function AdminShell() { | |
| const { user, signOut } = useAuth(); | |
| const location = useLocation(); | |
| const account = user?.full_name || user?.email?.split("@")[0] || ""; | |
| return ( | |
| <div className="flex min-h-screen bg-[var(--surface-subtle)]"> | |
| {/* rail first == right side in RTL */} | |
| <aside | |
| className="sticky top-0 hidden h-screen w-[258px] shrink-0 flex-col overflow-hidden | |
| px-4 pb-4 pt-5 lg:flex" | |
| style={{ background: "var(--rail)" }} | |
| > | |
| <img | |
| src="/logo/mark-white.png" | |
| alt="" | |
| aria-hidden | |
| className="pointer-events-none absolute -bottom-8 -left-10 size-[220px] object-contain | |
| opacity-[0.07]" | |
| /> | |
| <NavLink | |
| to="/admin" | |
| className="relative flex items-center gap-3 px-2 pb-5 pt-1.5 | |
| transition-opacity hover:opacity-80" | |
| > | |
| <img src="/logo/mark-white.png" alt="" className="size-[34px] object-contain" /> | |
| <img src="/logo/lockup-white.png" alt="كونتي AI" className="h-5 object-contain" /> | |
| </NavLink> | |
| <nav className="relative flex flex-col gap-1"> | |
| {NAV.map((item) => ( | |
| <Item key={item.to} item={item} /> | |
| ))} | |
| </nav> | |
| <div className="relative mt-auto flex flex-col gap-1"> | |
| {/* The way back to the product. It belongs with the account controls | |
| rather than in a banner: leaving is something you do once, at the | |
| end, not something the screen should announce continuously. */} | |
| <NavLink | |
| to="/" | |
| className="flex min-h-11 items-center gap-3 rounded-md px-3 py-2.5 text-item | |
| font-medium text-[var(--rail-item)] transition-colors | |
| hover:bg-white/[0.07]" | |
| > | |
| <span | |
| className="grid size-5 shrink-0 place-items-center" | |
| style={{ color: "var(--rail-icon)" }} | |
| > | |
| <Icon name="exit" size={19} /> | |
| </span> | |
| {t.admin.exit} | |
| </NavLink> | |
| <div | |
| className="mt-2 flex items-center gap-3 rounded-[var(--radius-btn)] border px-3 py-2.5" | |
| style={{ background: "var(--rail-card)", borderColor: "var(--rail-card-bd)" }} | |
| > | |
| <span | |
| className="grid size-[34px] shrink-0 place-items-center rounded-full | |
| bg-[var(--color-brand-500)] text-item font-bold text-white" | |
| > | |
| {(account || "؟").trim().charAt(0)} | |
| </span> | |
| <div className="min-w-0 flex-1"> | |
| <p className="truncate text-caption font-semibold text-white"> | |
| <Ltr>{account}</Ltr> | |
| </p> | |
| <p className="text-micro" style={{ color: "var(--rail-role)" }}> | |
| {t.nav.roleAdmin} | |
| </p> | |
| </div> | |
| <button | |
| onClick={signOut} | |
| title={t.nav.signOut} | |
| aria-label={t.nav.signOut} | |
| className="tap shrink-0 rounded-md transition-colors hover:text-white" | |
| style={{ color: "var(--rail-label)" }} | |
| > | |
| <Icon name="exit" size={17} /> | |
| </button> | |
| </div> | |
| </div> | |
| </aside> | |
| <main | |
| key={location.pathname} | |
| className="min-w-0 flex-1 animate-[fade_.22s_ease-out] px-6 pb-24 pt-8 | |
| lg:px-10 lg:pb-[60px] lg:pt-[30px]" | |
| > | |
| <Outlet /> | |
| </main> | |
| <nav | |
| className="fixed inset-x-0 bottom-0 z-20 flex justify-around overflow-x-auto py-1.5 lg:hidden" | |
| style={{ background: "var(--rail)" }} | |
| > | |
| {NAV.map((item) => ( | |
| <NavLink | |
| key={item.to} | |
| to={item.to} | |
| end={item.end} | |
| className={({ isActive }) => | |
| [ | |
| "flex min-h-11 min-w-11 shrink-0 flex-col items-center justify-center gap-0.5 px-3", | |
| "text-micro font-semibold transition-colors", | |
| isActive ? "text-white" : "text-[var(--rail-item)]", | |
| ].join(" ") | |
| } | |
| > | |
| <Icon name={item.icon} size={19} /> | |
| {item.label} | |
| </NavLink> | |
| ))} | |
| </nav> | |
| </div> | |
| ); | |
| } | |
| /** Shared page header for admin screens. | |
| * | |
| * The admin file sets its title at 34/800 rather than the product's 40 - an | |
| * administrative page carries more per screen and the smaller title leaves | |
| * the room for it. */ | |
| export function AdminHeader({ | |
| title, | |
| subtitle, | |
| action, | |
| }: { | |
| title: string; | |
| subtitle?: string; | |
| action?: React.ReactNode; | |
| }) { | |
| return ( | |
| <header className="mb-[22px] flex flex-wrap items-start justify-between gap-5"> | |
| <div className="min-w-0"> | |
| <h1 className="text-h1 text-[var(--text-strong)]"> | |
| {title} | |
| </h1> | |
| {subtitle && ( | |
| <p className="mt-1.5 max-w-2xl text-item text-[var(--text-muted)]">{subtitle}</p> | |
| )} | |
| </div> | |
| {action} | |
| </header> | |
| ); | |
| } | |
| /** The week/month/quarter/year switch. Full-height pills, per the admin file. */ | |
| export function RangeSwitch({ | |
| value, | |
| onChange, | |
| options = [ | |
| { days: 7, label: "أسبوع" }, | |
| { days: 30, label: "شهر" }, | |
| { days: 90, label: "٣ أشهر" }, | |
| { days: 365, label: "سنة" }, | |
| ], | |
| }: { | |
| value: number; | |
| onChange: (days: number) => void; | |
| options?: { days: number; label: string }[]; | |
| }) { | |
| return ( | |
| <div className="flex shrink-0 items-center gap-1.5"> | |
| {options.map((o) => ( | |
| <button | |
| key={o.days} | |
| type="button" | |
| onClick={() => onChange(o.days)} | |
| className={[ | |
| "min-h-11 rounded-md border px-4 py-2 text-caption transition-all", | |
| value === o.days | |
| ? "border-[var(--color-brand-700)] bg-[var(--color-brand-700)] font-bold text-white" | |
| : "border-[var(--border-subtle)] bg-[var(--surface)] font-medium " + | |
| "text-[var(--text-muted)] hover:border-[var(--brand)]", | |
| ].join(" ")} | |
| > | |
| {o.label} | |
| </button> | |
| ))} | |
| </div> | |
| ); | |
| } | |