This repository has been archived on 2026-11-23. You can view files and clone it. You cannot open issues or pull requests or push a commit.
Files
hope-events/frontend/src/components/layout/Sidebar.tsx
T
joshuaandClaude Opus 5.5 594cb35a85 POPIA toolkit part 1: privacy page, unsubscribe, WhatsApp STOP, data requests
- Privacy page: news opt-in per channel with history, download my data
  (JSON + PDF), correction and deletion requests
- Bulk messages are an Event update or News & announcements; news only
  reaches people who opted in, with unsubscribe links, one-click
  List-Unsubscribe headers and "Reply STOP" on WhatsApp
- WhatsApp STOP via WAWP's message webhook, checked against a secret in
  the webhook URL
- Sign-up opt-in box; existing accounts kept opted in and asked once
- Admin -> Data requests with 30-day due dates and a daily reminder job
- Deleting an account is a request; anonymising now covers attendees,
  form answers, consent details, payer details in provider payloads, etc.
- Unit tests (privacy.test.js) and e2e (privacy.spec.ts); docs

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_012mt6TCv85T9VKRq3cV7rXq
2026-10-23 18:13:47 +02:00

102 lines
4.0 KiB
TypeScript

"use client";
import React, { useState } from "react";
import Link from "next/link";
import { Calendar, User, LayoutDashboard, ShieldCheck, Globe, Menu, Lock, type LucideIcon } from "lucide-react";
import { useAuth } from "@/hooks/useAuth";
import { RoleBadge, type Role } from "@/components/shared/RoleBadge";
import { UserAvatar } from "@/components/shared/UserAvatar";
import { usePathname } from "next/navigation";
import { Sheet, SheetContent, SheetTrigger } from "@/components/ui/sheet";
const navLinks: { href: string; label: string; icon: LucideIcon; roles?: string[] }[] = [
{ href: "/dashboard/user", label: "My Events", icon: Calendar, roles: ["user", "staff", "supervisor", "admin"] },
{ href: "/dashboard/user/profile", label: "Profile & Security", icon: User, roles: ["user", "staff", "supervisor", "admin"] },
{ href: "/dashboard/user/privacy", label: "Privacy", icon: Lock, roles: ["user", "staff", "supervisor", "admin"] },
{ href: "/dashboard/staff", label: "Staff", icon: LayoutDashboard, roles: ["staff"] },
{ href: "/dashboard/supervisor", label: "Supervisor", icon: LayoutDashboard, roles: ["supervisor"] },
{ href: "/dashboard/admin", label: "Admin", icon: ShieldCheck, roles: ["admin"] },
{ href: "/dashboard/admin/settings", label: "Site Settings", icon: Globe, roles: ["admin"] },
];
function SidebarNavContent({ onNavigate }: { onNavigate?: () => void }) {
const { user } = useAuth();
const role = (user?.role || "user") as Role;
const pathname = usePathname();
const links = navLinks.filter(l => !l.roles || l.roles.includes(role));
return (
<div className="flex flex-col h-full">
{user && (
<div className="mb-6 flex items-center gap-3">
<UserAvatar name={user.name} />
<div className="min-w-0">
<div className="text-sm font-semibold text-gray-900 truncate">{user.name}</div>
<RoleBadge role={role} className="mt-0.5" />
</div>
</div>
)}
<nav className="space-y-1">
{links.map(l => {
const Icon = l.icon;
const active = pathname === l.href;
return (
<Link
key={l.href}
href={l.href}
onClick={onNavigate}
className={
"flex items-center gap-3 rounded-lg px-3 py-2 text-sm transition-colors " +
(active ? "bg-brand-50 text-brand-700 font-medium" : "text-gray-600 hover:bg-gray-50")
}
>
<Icon className="w-4 h-4 shrink-0" />
{l.label}
</Link>
);
})}
</nav>
</div>
);
}
/** Desktop sidebar — fixed/pinned, does not scroll with page content. */
export function Sidebar() {
return (
<aside className="hidden md:flex md:flex-col w-64 shrink-0 h-full overflow-y-auto border-r bg-white p-4">
<SidebarNavContent />
</aside>
);
}
/** Mobile equivalent — a slim top strip with a hamburger that opens the same nav in a drawer. */
export function MobileSidebar() {
const { user } = useAuth();
const role = (user?.role || "user") as Role;
const [open, setOpen] = useState(false);
return (
<div className="md:hidden border-b bg-white px-4 py-3 shadow-sm flex items-center justify-between shrink-0">
{user && (
<div className="flex items-center gap-2 min-w-0">
<UserAvatar name={user.name} className="w-8 h-8 text-xs" />
<div className="min-w-0">
<div className="text-sm font-semibold text-gray-900 truncate">{user.name}</div>
<RoleBadge role={role} />
</div>
</div>
)}
<Sheet open={open} onOpenChange={setOpen}>
<SheetTrigger asChild>
<button type="button" aria-label="Open navigation" className="p-2 rounded-md hover:bg-gray-100 shrink-0">
<Menu className="w-5 h-5" />
</button>
</SheetTrigger>
<SheetContent side="left" className="w-72 p-4">
<SidebarNavContent onNavigate={() => setOpen(false)} />
</SheetContent>
</Sheet>
</div>
);
}