Files
events-hub/frontend/src/app/(hub)/layout.tsx
T
joshuaandClaude Opus 5.5 1449e5046e Releases with what's new, notices to churches, withdrawn update requests
- Releases page: each Cross Events version with notes and an urgent flag; the
  newest is the latest version (moved off Settings; the old setting becomes the
  first release). Installs get the notes for every newer version.
- Notices page: a banner for site admins and supervisors (with a time window),
  an email to the customer and admin contact, or both; for every install or
  chosen ones.
- POST /api/installs/update-request/cancel resolves the request and emails Joshua.
- Protocol doc: releases and notices in the heartbeat/register replies.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-28 08:54:35 +02:00

70 lines
3.2 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, Rocket, Megaphone } 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: "/releases", label: "Releases", icon: Rocket },
{ href: "/notices", label: "Notices", icon: Megaphone },
{ 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">
{/* Pinned to the window, so Sign out stays in view however long the page is. */}
<aside className="sticky top-0 hidden h-screen w-56 shrink-0 overflow-y-auto 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>
);
}