Hope Events is now Cross Events. Protocol identifiers (hel1. tokens, CEH- keys) are unchanged so existing installs keep working. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
67 lines
2.9 KiB
TypeScript
67 lines
2.9 KiB
TypeScript
"use client";
|
|
|
|
import React, { useEffect, useState } from "react";
|
|
import Link from "next/link";
|
|
import { usePathname, useRouter } from "next/navigation";
|
|
import { LayoutDashboard, Building2, BellRing, Settings, LogOut } from "lucide-react";
|
|
import { api, getToken, setToken } from "@/lib/api";
|
|
import { Logo } from "@/components/ui";
|
|
|
|
type Me = { id: string; name: string; email: string };
|
|
|
|
const NAV = [
|
|
{ href: "/", label: "Installs", icon: LayoutDashboard },
|
|
{ href: "/customers", label: "Customers", icon: Building2 },
|
|
{ href: "/alerts", label: "Alerts", icon: BellRing },
|
|
{ href: "/settings", label: "Settings", icon: Settings },
|
|
];
|
|
|
|
/** Everything except /login: requires a session, with the side navigation. */
|
|
export default function HubLayout({ children }: { children: React.ReactNode }) {
|
|
const router = useRouter();
|
|
const pathname = usePathname();
|
|
const [me, setMe] = useState<Me | null>(null);
|
|
|
|
useEffect(() => {
|
|
if (!getToken()) { router.replace("/login"); return; }
|
|
api<Me>("/api/auth/me").then(setMe).catch(() => router.replace("/login"));
|
|
}, [router]);
|
|
|
|
if (!me) return <div className="flex min-h-screen items-center justify-center text-sm text-slate-400">Loading…</div>;
|
|
|
|
const active = (href: string) => (href === "/" ? pathname === "/" || pathname.startsWith("/installs") : pathname.startsWith(href));
|
|
|
|
return (
|
|
<div className="flex min-h-screen">
|
|
<aside className="hidden w-56 shrink-0 border-r border-slate-200 bg-white p-4 md:flex md:flex-col">
|
|
<div className="mb-6 px-2">
|
|
<Logo />
|
|
<div className="mt-1 pl-[2.625rem] text-xs text-slate-500">{me.name}</div>
|
|
</div>
|
|
<nav className="space-y-1">
|
|
{NAV.map(n => {
|
|
const Icon = n.icon;
|
|
return (
|
|
<Link key={n.href} href={n.href} className={`flex items-center gap-2 rounded-lg px-3 py-2 text-sm ${active(n.href) ? "bg-indigo-50 font-medium text-indigo-700" : "text-slate-600 hover:bg-slate-50"}`}>
|
|
<Icon className="h-4 w-4" /> {n.label}
|
|
</Link>
|
|
);
|
|
})}
|
|
</nav>
|
|
<button onClick={() => { setToken(null); router.replace("/login"); }} className="mt-auto flex items-center gap-2 rounded-lg px-3 py-2 text-sm text-slate-600 hover:bg-slate-50">
|
|
<LogOut className="h-4 w-4" /> Sign out
|
|
</button>
|
|
</aside>
|
|
<div className="flex-1 min-w-0">
|
|
<nav className="flex items-center gap-1 overflow-x-auto border-b border-slate-200 bg-white px-3 py-2 md:hidden">
|
|
<Logo markOnly className="mr-1 h-7 w-7" />
|
|
{NAV.map(n => (
|
|
<Link key={n.href} href={n.href} className={`whitespace-nowrap rounded-lg px-3 py-1.5 text-sm ${active(n.href) ? "bg-indigo-50 font-medium text-indigo-700" : "text-slate-600"}`}>{n.label}</Link>
|
|
))}
|
|
</nav>
|
|
<main className="mx-auto max-w-6xl p-4 md:p-8">{children}</main>
|
|
</div>
|
|
</div>
|
|
);
|
|
}
|