"use client"; import React, { useEffect, useState } from "react"; import { useAuth } from "@/hooks/useAuth"; import { formatDate } from "@/lib/date"; import { Users } from "lucide-react"; import { BackLink } from "@/components/shared/BackLink"; import { apiV2Data } from "@/lib/apiV2"; 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 | null; emergency?: Record | 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(null); useEffect(() => { if (!token) return; (apiV2Data("get", "/me/allocation-groups", { authToken: token }) as Promise<{ medicalShown: boolean; groups: MyGroup[] }>) .then(setData).catch(e => setError(e?.message || "Failed to load your groups")); }, [token]); return (

My groups

Rooms, small groups and buses you lead

{error &&
{error}
} {data && data.groups.length === 0 &&

You aren't leading any groups for upcoming events.

}
{data?.groups.map(g => (

{g.name} · {g.setName}

{g.event.title} · {formatDate(new Date(g.event.startDate))} · {g.members.length}{g.capacity ? ` / ${g.capacity}` : ""} people
{g.members.length === 0 ?

Nobody has been placed in this group yet.

: (
{data.medicalShown && } {g.members.map(m => { const age = ageOn(m.dateOfBirth, g.event.startDate); return ( {data.medicalShown && ( )} ); })}
NameAgeContactMedical
{m.name} {age ?? "—"} {m.phone &&
{m.phone}
} {m.parentName ?
Parent: {m.parentName}{m.parentPhone ? ` · ${m.parentPhone}` : ""}
: m.bookedBy &&
Booked by {m.bookedBy}{m.bookedByPhone ? ` · ${m.bookedByPhone}` : ""}
}
{m.medical ? Object.values(m.medical).filter(Boolean).join("; ") || "—" : "—"} {m.emergency && Object.values(m.emergency).some(Boolean) &&
Emergency: {Object.values(m.emergency).filter(Boolean).join(", ")}
}
)}
))}
{data && !data.medicalShown && data.groups.length > 0 &&

Medical details are only shown to supervisors. Ask one if you need them.

}
); }