Archived
Every dashboard page now uses the shared BackLink, the small "← Back to dashboard" link above the page title that the Waitlist page already had, instead of a mix of grey Back buttons in different places. Pages that had no way back (site settings, profile, donate, manual registration) get one too. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
96 lines
5.1 KiB
TypeScript
96 lines
5.1 KiB
TypeScript
"use client";
|
|
|
|
import React, { useEffect, useState } from "react";
|
|
import { useAuth } from "@/hooks/useAuth";
|
|
import { apiFetch } from "@/lib/api";
|
|
import { formatDate } from "@/lib/date";
|
|
import { Users } from "lucide-react";
|
|
import { BackLink } from "@/components/shared/BackLink";
|
|
|
|
type Member = {
|
|
id: string; name: string; gender: string | null; dateOfBirth: string | null; phone: string | null;
|
|
parentName: string | null; parentPhone: string | null; bookedBy: string; bookedByPhone: string | null;
|
|
medical?: Record<string, string> | null; emergency?: Record<string, string> | null;
|
|
};
|
|
type MyGroup = { id: string; name: string; capacity: number | null; setName: string; event: { id: string; title: string; startDate: string }; members: Member[] };
|
|
|
|
const ageOn = (dob: string | null, on: string) => {
|
|
if (!dob) return null;
|
|
const d = new Date(dob), e = new Date(on);
|
|
let age = e.getFullYear() - d.getFullYear();
|
|
if (e.getMonth() < d.getMonth() || (e.getMonth() === d.getMonth() && e.getDate() < d.getDate())) age -= 1;
|
|
return age;
|
|
};
|
|
|
|
/** Groups the signed-in staff member leads (rooms, small groups, buses) and who's in them. */
|
|
export default function MyGroupsPage() {
|
|
const { token } = useAuth();
|
|
const [data, setData] = useState<{ medicalShown: boolean; groups: MyGroup[] } | null>(null);
|
|
const [error, setError] = useState<string | null>(null);
|
|
|
|
useEffect(() => {
|
|
if (!token) return;
|
|
apiFetch<{ medicalShown: boolean; groups: MyGroup[] }>("/api/allocations/my-groups", { authToken: token })
|
|
.then(setData).catch(e => setError(e?.message || "Failed to load your groups"));
|
|
}, [token]);
|
|
|
|
return (
|
|
<div className="max-w-4xl mx-auto w-full p-6">
|
|
<div className="flex items-center gap-3 mb-4">
|
|
<div className="w-10 h-10 rounded-xl bg-brand-50 flex items-center justify-center shrink-0">
|
|
<Users className="w-5 h-5 text-brand-600" />
|
|
</div>
|
|
<div>
|
|
<BackLink href="/dashboard" />
|
|
<h1 className="text-2xl font-semibold text-gray-900 mt-0.5">My groups</h1>
|
|
<p className="text-sm text-gray-500">Rooms, small groups and buses you lead</p>
|
|
</div>
|
|
</div>
|
|
{error && <div className="mb-3 p-3 border rounded bg-red-50 text-red-800 text-sm">{error}</div>}
|
|
{data && data.groups.length === 0 && <p className="text-sm text-gray-600">You aren't leading any groups for upcoming events.</p>}
|
|
<div className="space-y-4">
|
|
{data?.groups.map(g => (
|
|
<section key={g.id} className="border rounded-xl p-4 bg-white shadow-sm">
|
|
<div className="flex flex-wrap items-baseline justify-between gap-2 mb-2">
|
|
<h2 className="font-semibold">{g.name} <span className="text-sm font-normal text-gray-500">· {g.setName}</span></h2>
|
|
<span className="text-xs text-gray-500">{g.event.title} · {formatDate(new Date(g.event.startDate))} · {g.members.length}{g.capacity ? ` / ${g.capacity}` : ""} people</span>
|
|
</div>
|
|
{g.members.length === 0 ? <p className="text-sm text-gray-500">Nobody has been placed in this group yet.</p> : (
|
|
<div className="overflow-x-auto">
|
|
<table className="w-full text-sm">
|
|
<thead><tr className="text-left text-xs text-gray-500 border-b">
|
|
<th className="py-1 pr-3">Name</th><th className="py-1 pr-3">Age</th><th className="py-1 pr-3">Contact</th>
|
|
{data.medicalShown && <th className="py-1 pr-3">Medical</th>}
|
|
</tr></thead>
|
|
<tbody>
|
|
{g.members.map(m => {
|
|
const age = ageOn(m.dateOfBirth, g.event.startDate);
|
|
return (
|
|
<tr key={m.id} className="border-b last:border-0 align-top">
|
|
<td className="py-1.5 pr-3 font-medium">{m.name}</td>
|
|
<td className="py-1.5 pr-3">{age ?? "—"}</td>
|
|
<td className="py-1.5 pr-3 text-xs">
|
|
{m.phone && <div>{m.phone}</div>}
|
|
{m.parentName ? <div>Parent: {m.parentName}{m.parentPhone ? ` · ${m.parentPhone}` : ""}</div> : m.bookedBy && <div>Booked by {m.bookedBy}{m.bookedByPhone ? ` · ${m.bookedByPhone}` : ""}</div>}
|
|
</td>
|
|
{data.medicalShown && (
|
|
<td className="py-1.5 pr-3 text-xs">
|
|
{m.medical ? Object.values(m.medical).filter(Boolean).join("; ") || "—" : "—"}
|
|
{m.emergency && Object.values(m.emergency).some(Boolean) && <div className="text-gray-500">Emergency: {Object.values(m.emergency).filter(Boolean).join(", ")}</div>}
|
|
</td>
|
|
)}
|
|
</tr>
|
|
);
|
|
})}
|
|
</tbody>
|
|
</table>
|
|
</div>
|
|
)}
|
|
</section>
|
|
))}
|
|
</div>
|
|
{data && !data.medicalShown && data.groups.length > 0 && <p className="text-xs text-gray-500 mt-3">Medical details are only shown to supervisors. Ask one if you need them.</p>}
|
|
</div>
|
|
);
|
|
}
|