contiai / apps /web /src /components /AppShell.tsx
aliabozahra315's picture
Deploy eecad36
0e5aad3
Raw History Blame Contribute Delete
7.35 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";
import AnnouncementBar from "@/components/AnnouncementBar";
/* The rail, per ContiAI App.dc.html.
*
* It is a dark navy panel rather than a light one, which is the single change
* that gives the product its shape: the page floats as one bright field beside
* a fixed dark edge, and the active item - brand fill on navy - is legible at
* a glance.
*
* The page is RTL, so the first element in a flex row lands on the RIGHT. The
* rail is therefore first in the DOM; putting the main region first pushed the
* navigation to the left, which is wrong for Arabic.
*/
interface NavItem {
to: string;
label: string;
icon: IconName;
end?: boolean;
}
const NAV: NavItem[] = [
{ to: "/", label: t.nav.home, icon: "home", end: true },
{ to: "/create", label: t.nav.create, icon: "sparkle" },
{ to: "/library", label: t.nav.library, icon: "book" },
{ to: "/usage", label: t.nav.usage, icon: "clock" },
];
/** The founder's bag designer - shown to the owner account only. */
const DESIGN: NavItem = { to: "/design", label: "تصميم الحقائب والعروض", icon: "layers" };
/** «استوديو التصميم» - social designs and infographics, the owner account only. */
const STUDIO: NavItem = { to: "/studio", label: "استوديو التصميم", icon: "infographic" };
const FOOT: NavItem[] = [
{ to: "/profile", label: "الملف الشخصي", icon: "user" },
{ to: "/settings", label: t.nav.settings, icon: "cog" },
];
/** A rail row. Everything it wears is a rail token - none of the page's text
* or surface roles read correctly against navy. */
function Item({ item }: { item: NavItem }) {
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 AppShell() {
const { user, isAdmin, canDesign, signOut } = useAuth();
// the designers and the studio: whoever the founder opened them to
const designs = canDesign("bag") || canDesign("slides");
const nav = [...NAV, ...(designs ? [DESIGN] : []), ...(canDesign("studio") ? [STUDIO] : [])];
const location = useLocation();
const account = user?.full_name || user?.email?.split("@")[0] || "";
const initial = (account || "؟").trim().charAt(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)" }}
>
{/* The mark, oversized and nearly invisible in the corner. It reads as
texture rather than as a second logo. */}
<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="/"
className="relative flex items-center gap-3 px-2 pb-[18px] 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>
<p
className="relative px-2.5 pb-2 text-micro font-semibold tracking-[0.08em]"
style={{ color: "var(--rail-label)" }}
>
{t.nav.section}
</p>
<nav className="relative flex flex-col gap-1">
{nav.map((i) => (
<Item key={i.to} item={i} />
))}
</nav>
<div className="relative mt-auto flex flex-col gap-1">
{FOOT.map((i) => (
<Item key={i.to} item={i} />
))}
<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"
>
{initial}
</span>
<div className="min-w-0 flex-1">
{/* An account name is very often an email or a Latin name, and it
sits in an RTL column - isolate it or the domain migrates to
the wrong end of the truncation. */}
<p className="truncate text-caption font-semibold text-white">
<Ltr>{account}</Ltr>
</p>
<p className="text-micro" style={{ color: "var(--rail-role)" }}>
{isAdmin ? t.nav.roleAdmin : t.nav.roleUser}
</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>
{/* key on the path so each screen fades in on navigation */}
<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-[34px]"
>
<AnnouncementBar />
<Outlet />
</main>
{/* On small screens the rail becomes a bottom bar, and it keeps the rail's
own colours so the product still reads as itself. */}
<nav
className="fixed inset-x-0 bottom-0 z-20 flex justify-around py-1.5 lg:hidden"
style={{ background: "var(--rail)" }}
>
{nav.map((i) => (
<NavLink
key={i.to}
to={i.to}
end={i.end}
className={({ isActive }) =>
[
"flex min-h-11 min-w-11 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={i.icon} size={19} />
{i.label}
</NavLink>
))}
</nav>
</div>
);
}