Kids check-in: desk, room screen, setup and parent pages, help, e2e
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,67 @@
|
||||
"use client";
|
||||
|
||||
import React, { useState } from "react";
|
||||
import type { KidsChild } from "@/lib/kids";
|
||||
|
||||
export type ChildInput = {
|
||||
firstName: string; lastName: string; dateOfBirth: string; gender: string;
|
||||
allergies: string; medicalNotes: string; custodyNotes?: string;
|
||||
};
|
||||
|
||||
const inputCls = "w-full border rounded-lg px-3 py-2 text-sm focus:outline-none focus:ring-2 focus:ring-brand-500";
|
||||
|
||||
export function childToInput(c?: KidsChild | null): ChildInput {
|
||||
return {
|
||||
firstName: c?.firstName || "", lastName: c?.lastName || "",
|
||||
dateOfBirth: c?.dateOfBirth ? c.dateOfBirth.slice(0, 10) : "", gender: c?.gender || "",
|
||||
allergies: c?.allergies || "", medicalNotes: c?.medicalNotes || "", custodyNotes: c?.custodyNotes || "",
|
||||
};
|
||||
}
|
||||
|
||||
type Props = {
|
||||
initial?: KidsChild | null;
|
||||
/** Show the custody notes box (parents, supervisors and admins). */
|
||||
custody: boolean;
|
||||
busy?: boolean;
|
||||
onSave: (input: ChildInput) => void;
|
||||
onCancel?: () => void;
|
||||
saveLabel?: string;
|
||||
};
|
||||
|
||||
/** Add or change a child: name, date of birth, allergies, medical and (optionally) custody notes. */
|
||||
export function ChildForm({ initial, custody, busy, onSave, onCancel, saveLabel = "Save" }: Props) {
|
||||
const [v, setV] = useState<ChildInput>(() => childToInput(initial));
|
||||
const set = (k: keyof ChildInput) => (e: React.ChangeEvent<HTMLInputElement | HTMLTextAreaElement | HTMLSelectElement>) => setV(prev => ({ ...prev, [k]: e.target.value }));
|
||||
return (
|
||||
<form
|
||||
className="space-y-3"
|
||||
onSubmit={e => {
|
||||
e.preventDefault();
|
||||
const out = { ...v };
|
||||
if (!custody) delete out.custodyNotes;
|
||||
onSave(out);
|
||||
}}
|
||||
>
|
||||
<div className="grid sm:grid-cols-2 gap-3">
|
||||
<label className="text-sm"><span className="block text-xs text-gray-500 mb-1">First name *</span><input className={inputCls} value={v.firstName} onChange={set("firstName")} required maxLength={60} /></label>
|
||||
<label className="text-sm"><span className="block text-xs text-gray-500 mb-1">Surname</span><input className={inputCls} value={v.lastName} onChange={set("lastName")} maxLength={60} /></label>
|
||||
<label className="text-sm"><span className="block text-xs text-gray-500 mb-1">Date of birth</span><input type="date" className={inputCls} value={v.dateOfBirth} onChange={set("dateOfBirth")} max={new Date().toISOString().slice(0, 10)} /></label>
|
||||
<label className="text-sm"><span className="block text-xs text-gray-500 mb-1">Gender</span>
|
||||
<select className={inputCls} value={v.gender} onChange={set("gender")}>
|
||||
<option value="">—</option><option value="female">Girl</option><option value="male">Boy</option>
|
||||
</select>
|
||||
</label>
|
||||
</div>
|
||||
<label className="block text-sm"><span className="block text-xs text-gray-500 mb-1">Allergies</span><input className={inputCls} value={v.allergies} onChange={set("allergies")} maxLength={300} placeholder="e.g. Peanuts, bee stings" /></label>
|
||||
<label className="block text-sm"><span className="block text-xs text-gray-500 mb-1">Medical notes</span><textarea className={inputCls} rows={2} value={v.medicalNotes} onChange={set("medicalNotes")} maxLength={1000} placeholder="Conditions, medicine, what leaders should know" /></label>
|
||||
{custody && (
|
||||
<label className="block text-sm"><span className="block text-xs text-gray-500 mb-1">Custody notes (room leaders only)</span><textarea className={inputCls} rows={2} value={v.custodyNotes} onChange={set("custodyNotes")} maxLength={1000} placeholder='e.g. "Do not release to …"' /></label>
|
||||
)}
|
||||
<p className="text-xs text-gray-500">Allergies, medical and custody notes are stored encrypted and only shown to kids-ministry staff. They are never sent in messages.</p>
|
||||
<div className="flex gap-2">
|
||||
<button type="submit" disabled={busy} className="px-4 py-2 rounded-lg bg-brand-600 text-white text-sm font-medium disabled:opacity-50">{busy ? "Saving…" : saveLabel}</button>
|
||||
{onCancel && <button type="button" onClick={onCancel} className="px-4 py-2 rounded-lg border text-sm">Cancel</button>}
|
||||
</div>
|
||||
</form>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,67 @@
|
||||
"use client";
|
||||
|
||||
import React, { useEffect, useState } from "react";
|
||||
import { apiFetch } from "@/lib/api";
|
||||
import { formatDate } from "@/lib/date";
|
||||
import type { KidsEvent } from "@/lib/kids";
|
||||
|
||||
type Props = {
|
||||
token: string | null;
|
||||
eventId: string;
|
||||
sessionId: string;
|
||||
onChange: (eventId: string, sessionId: string) => void;
|
||||
};
|
||||
|
||||
const STORAGE = "hope_events_kids_event";
|
||||
|
||||
/** Picks the kids event (and session) the desk or room screen works on; remembers the choice. */
|
||||
export function KidsEventPicker({ token, eventId, sessionId, onChange }: Props) {
|
||||
const [events, setEvents] = useState<KidsEvent[] | null>(null);
|
||||
const [error, setError] = useState<string | null>(null);
|
||||
|
||||
useEffect(() => {
|
||||
if (!token) return;
|
||||
apiFetch<KidsEvent[]>("/api/kids/events", { authToken: token })
|
||||
.then(list => {
|
||||
setEvents(list);
|
||||
if (eventId || !list.length) return;
|
||||
let remembered = "";
|
||||
try { remembered = localStorage.getItem(STORAGE) || ""; } catch { /* ignore */ }
|
||||
const now = Date.now();
|
||||
const current = list.find(e => e.id === remembered) || list.find(e => new Date(e.endDate).getTime() >= now) || list[0];
|
||||
onChange(current.id, "");
|
||||
})
|
||||
.catch(e => setError(e?.message || "Could not load events"));
|
||||
}, [token]); // eslint-disable-line react-hooks/exhaustive-deps
|
||||
|
||||
const event = events?.find(e => e.id === eventId);
|
||||
const pick = (id: string, sid = "") => {
|
||||
try { localStorage.setItem(STORAGE, id); } catch { /* ignore */ }
|
||||
onChange(id, sid);
|
||||
};
|
||||
|
||||
if (error) return <div className="p-3 border rounded bg-red-50 text-red-800 text-sm">{error}</div>;
|
||||
if (events && !events.length) {
|
||||
return <div className="p-3 border rounded bg-amber-50 text-amber-800 text-sm">No events have kids check-in switched on. A supervisor sets it up under Supervisor → Kids check-in setup.</div>;
|
||||
}
|
||||
return (
|
||||
<div className="flex flex-wrap gap-2 items-end">
|
||||
<label className="text-sm">
|
||||
<span className="block text-xs text-gray-500 mb-1">Event</span>
|
||||
<select className="border rounded-lg px-3 py-2 text-sm min-w-[14rem]" value={eventId} onChange={e => pick(e.target.value)}>
|
||||
{!eventId && <option value="">Choose an event…</option>}
|
||||
{events?.map(e => <option key={e.id} value={e.id}>{e.title} · {formatDate(new Date(e.startDate))}</option>)}
|
||||
</select>
|
||||
</label>
|
||||
{event?.scheduleType === "sessions" && (
|
||||
<label className="text-sm">
|
||||
<span className="block text-xs text-gray-500 mb-1">Session</span>
|
||||
<select className="border rounded-lg px-3 py-2 text-sm" value={sessionId} onChange={e => pick(event.id, e.target.value)}>
|
||||
<option value="">Today's session</option>
|
||||
{event.sessions.map((s, i) => <option key={s.id} value={s.id}>{s.label || `Session ${i + 1}`} · {formatDate(new Date(s.startsAt))}</option>)}
|
||||
</select>
|
||||
</label>
|
||||
)}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,147 @@
|
||||
"use client";
|
||||
|
||||
import React, { useState } from "react";
|
||||
import { apiFetch } from "@/lib/api";
|
||||
import { errorMessage } from "@/lib/utils";
|
||||
import { AlertTriangle, BellRing, HeartPulse, LogOut, ShieldAlert, Users } from "lucide-react";
|
||||
import { ageRange, type KidsBoard, type KidsCheckIn, type KidsRoom } from "@/lib/kids";
|
||||
|
||||
type Props = {
|
||||
board: KidsBoard;
|
||||
token: string | null;
|
||||
/** Only this room ('' = every room). */
|
||||
roomId: string;
|
||||
onChanged: () => void;
|
||||
onMessage: (m: { type: "ok" | "err"; text: string }) => void;
|
||||
};
|
||||
|
||||
const time = (iso: string) => new Date(iso).toLocaleTimeString([], { hour: "2-digit", minute: "2-digit" });
|
||||
|
||||
export function RoomStatusBadges({ room }: { room: KidsRoom }) {
|
||||
return (
|
||||
<span className="inline-flex flex-wrap gap-1 text-xs">
|
||||
<span className="px-2 py-0.5 rounded-full bg-gray-100 text-gray-700">{room.children}{room.capacity ? ` / ${room.capacity}` : ""} in</span>
|
||||
<span className={`px-2 py-0.5 rounded-full ${room.overRatio ? "bg-red-100 text-red-800" : "bg-gray-100 text-gray-700"}`}>
|
||||
{room.leaders} leader{room.leaders === 1 ? "" : "s"}{room.ratio ? ` (needs ${room.leadersNeeded})` : ""}
|
||||
</span>
|
||||
{room.full && <span className="px-2 py-0.5 rounded-full bg-amber-100 text-amber-800">Full</span>}
|
||||
{room.overRatio && <span className="px-2 py-0.5 rounded-full bg-red-100 text-red-800">Over ratio</span>}
|
||||
</span>
|
||||
);
|
||||
}
|
||||
|
||||
/** Live cards of the children in the rooms, with paging, moving and checking out without the code. */
|
||||
export function RoomBoard({ board, token, roomId, onChanged, onMessage }: Props) {
|
||||
const [busy, setBusy] = useState<string | null>(null);
|
||||
const rooms = board.rooms.filter(r => !roomId || r.id === roomId);
|
||||
const alerts = board.alerts.filter(a => !a.resolvedAt && a.kind === "wrong_code" && (!roomId || !a.roomId || a.roomId === roomId));
|
||||
|
||||
const act = async (id: string, fn: () => Promise<unknown>, ok: string) => {
|
||||
setBusy(id);
|
||||
try {
|
||||
await fn();
|
||||
onMessage({ type: "ok", text: ok });
|
||||
onChanged();
|
||||
} catch (e) {
|
||||
onMessage({ type: "err", text: errorMessage(e) || "Something went wrong" });
|
||||
} finally {
|
||||
setBusy(null);
|
||||
}
|
||||
};
|
||||
|
||||
const page = (c: KidsCheckIn) => {
|
||||
const extra = prompt(`Message the parents of ${c.firstName}? They'll be asked to come to the room. Add a note (optional):`, "");
|
||||
if (extra === null) return;
|
||||
act(c.id, () => apiFetch(`/api/kids/check-ins/${c.id}/page`, { method: "POST", authToken: token, body: { message: extra } }), `Message sent to ${c.firstName}'s parents.`);
|
||||
};
|
||||
const override = (c: KidsCheckIn) => {
|
||||
const who = prompt(`Who is collecting ${c.firstName}?`, c.family?.parents[0]?.name || "");
|
||||
if (!who) return;
|
||||
const reason = prompt("Why without the pickup code? (recorded in the audit log)", "");
|
||||
if (!reason) return;
|
||||
act(c.id, () => apiFetch(`/api/kids/check-ins/${c.id}/override`, { method: "POST", authToken: token, body: { collectedBy: who, reason } }), `${c.firstName} checked out.`);
|
||||
};
|
||||
const move = (c: KidsCheckIn, to: string) => act(c.id, () => apiFetch(`/api/kids/check-ins/${c.id}/room`, { method: "PUT", authToken: token, body: { roomId: to } }), `${c.firstName} moved.`);
|
||||
const resolve = (id: string) => act(id, () => apiFetch(`/api/kids/alerts/${id}/resolve`, { method: "POST", authToken: token }), "Alert cleared.");
|
||||
|
||||
return (
|
||||
<div className="space-y-4">
|
||||
{alerts.map(a => (
|
||||
<div key={a.id} role="alert" className="p-3 rounded-xl border-2 border-red-500 bg-red-50 flex items-start justify-between gap-3">
|
||||
<div className="flex gap-2"><ShieldAlert className="w-5 h-5 text-red-600 shrink-0" />
|
||||
<div><div className="font-semibold text-red-900">{a.message}</div><div className="text-xs text-red-700">{time(a.at)}{a.by ? ` · ${a.by}` : ""} — check who is collecting before handing over any child.</div></div>
|
||||
</div>
|
||||
<button disabled={busy === a.id} onClick={() => resolve(a.id)} className="text-sm px-3 py-1 rounded-lg border border-red-300 bg-white">Dealt with</button>
|
||||
</div>
|
||||
))}
|
||||
{rooms.map(r => {
|
||||
const inRoom = board.checkIns.filter(c => c.roomId === r.id && !c.checkedOutAt);
|
||||
const out = board.checkIns.filter(c => c.roomId === r.id && c.checkedOutAt);
|
||||
return (
|
||||
<section key={r.id} className="border rounded-xl p-4 bg-white shadow-sm">
|
||||
<div className="flex flex-wrap items-center justify-between gap-2 mb-3">
|
||||
<h2 className="font-semibold text-lg">{r.name} <span className="text-sm font-normal text-gray-500">{ageRange(r)}</span></h2>
|
||||
<RoomStatusBadges room={r} />
|
||||
</div>
|
||||
{r.leaderNames.length > 0 && <div className="text-xs text-gray-500 mb-2 flex items-center gap-1"><Users className="w-3.5 h-3.5" /> On duty: {r.leaderNames.join(", ")}</div>}
|
||||
{inRoom.length === 0 && <p className="text-sm text-gray-500">No children in this room.</p>}
|
||||
<div className="grid sm:grid-cols-2 gap-3">
|
||||
{inRoom.map(c => (
|
||||
<div key={c.id} className={`border rounded-lg p-3 ${c.custodyNotes ? "border-red-400" : c.allergies || c.medicalNotes ? "border-amber-400" : ""}`} data-testid="kids-card">
|
||||
<div className="flex items-start justify-between gap-2">
|
||||
<div>
|
||||
<div className="font-semibold">{c.name}{c.age != null && <span className="text-sm font-normal text-gray-500"> · {c.age}</span>}</div>
|
||||
<div className="text-xs text-gray-500">In {time(c.checkedInAt)} · code <span className="font-mono font-semibold text-gray-800">{c.code}</span>{c.offline ? " · offline" : ""}</div>
|
||||
</div>
|
||||
</div>
|
||||
{c.allergies && <div className="mt-1 text-sm text-red-800 flex gap-1"><AlertTriangle className="w-4 h-4 shrink-0" /> Allergies: {c.allergies}</div>}
|
||||
{c.medicalNotes && <div className="mt-1 text-sm text-amber-800 flex gap-1"><HeartPulse className="w-4 h-4 shrink-0" /> {c.medicalNotes}</div>}
|
||||
{c.custodyNotes && <div className="mt-1 text-sm text-red-900 bg-red-50 rounded px-2 py-1 flex gap-1"><ShieldAlert className="w-4 h-4 shrink-0" /> {c.custodyNotes}</div>}
|
||||
{c.family && (
|
||||
<div className="mt-2 text-xs text-gray-600">
|
||||
{c.family.parents.map(p => <div key={p.userId}>{p.name}{p.phone ? ` · ${p.phone}` : ""}</div>)}
|
||||
{c.family.adults.length > 0 && <div>May also collect: {c.family.adults.map(a => `${a.name}${a.relationship ? ` (${a.relationship})` : ""}`).join(", ")}</div>}
|
||||
</div>
|
||||
)}
|
||||
<div className="mt-2 flex flex-wrap gap-1.5">
|
||||
<button disabled={busy === c.id} onClick={() => page(c)} className="inline-flex items-center gap-1 text-xs px-2 py-1 rounded-lg border"><BellRing className="w-3.5 h-3.5" /> Call parent</button>
|
||||
<select aria-label={`Move ${c.firstName}`} value="" onChange={e => e.target.value && move(c, e.target.value)} className="text-xs border rounded-lg px-2 py-1">
|
||||
<option value="">Move to…</option>
|
||||
{board.rooms.filter(o => o.id !== r.id).map(o => <option key={o.id} value={o.id}>{o.name}</option>)}
|
||||
</select>
|
||||
<button disabled={busy === c.id} onClick={() => override(c)} className="inline-flex items-center gap-1 text-xs px-2 py-1 rounded-lg border text-gray-600"><LogOut className="w-3.5 h-3.5" /> Without code</button>
|
||||
</div>
|
||||
</div>
|
||||
))}
|
||||
</div>
|
||||
{out.length > 0 && (
|
||||
<details className="mt-3 text-sm">
|
||||
<summary className="cursor-pointer text-gray-500">Collected ({out.length})</summary>
|
||||
<ul className="mt-1 space-y-0.5 text-xs text-gray-600">
|
||||
{out.map(c => <li key={c.id}>{c.name} — {time(c.checkedOutAt!)} by {c.collectedBy || "—"}{c.override ? " (without code)" : ""}</li>)}
|
||||
</ul>
|
||||
</details>
|
||||
)}
|
||||
</section>
|
||||
);
|
||||
})}
|
||||
{!roomId && board.checkIns.some(c => !c.roomId && !c.checkedOutAt) && (
|
||||
<section className="border border-amber-300 rounded-xl p-4 bg-amber-50">
|
||||
<h2 className="font-semibold mb-2">No room</h2>
|
||||
<p className="text-xs text-amber-800 mb-2">Their room was deleted — choose a new one.</p>
|
||||
<ul className="space-y-1 text-sm">
|
||||
{board.checkIns.filter(c => !c.roomId && !c.checkedOutAt).map(c => (
|
||||
<li key={c.id} className="flex items-center gap-2">
|
||||
<span>{c.name}</span>
|
||||
<select aria-label={`Move ${c.firstName}`} value="" onChange={e => e.target.value && move(c, e.target.value)} className="text-xs border rounded-lg px-2 py-1 bg-white">
|
||||
<option value="">Move to…</option>
|
||||
{board.rooms.map(o => <option key={o.id} value={o.id}>{o.name}</option>)}
|
||||
</select>
|
||||
</li>
|
||||
))}
|
||||
</ul>
|
||||
</section>
|
||||
)}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,37 @@
|
||||
import React from "react";
|
||||
|
||||
type Props = {
|
||||
code: string;
|
||||
/** Checked in on an offline desk: nothing was sent to the parents. */
|
||||
offline?: boolean;
|
||||
kids: { id: string; firstName: string; room: string | null; sticker: string; already?: boolean }[];
|
||||
};
|
||||
|
||||
/**
|
||||
* "Write on the sticker": what volunteers copy onto a blank name sticker for each child — first
|
||||
* name, room, pickup code and a short allergy/medical alert — in print big enough to copy at a
|
||||
* glance. Nothing is printed; the full details stay on screen.
|
||||
*/
|
||||
export function StickerPanel({ code, kids, offline = false }: Props) {
|
||||
return (
|
||||
<div>
|
||||
<div className="text-center mb-3">
|
||||
<div className="text-xs uppercase tracking-wide text-gray-500">Pickup code</div>
|
||||
<div className="text-6xl font-black font-mono tracking-[0.25em]" data-testid="desk-code">{code}</div>
|
||||
<div className="text-xs text-gray-500">{offline ? "Offline: nothing was sent — tell the parent the code." : "Sent to the parents. Tell them too, in case the message is slow."}</div>
|
||||
</div>
|
||||
<div className="text-xs uppercase tracking-wide text-gray-500 mb-2">Write on the sticker</div>
|
||||
<div className="grid sm:grid-cols-2 gap-3">
|
||||
{kids.map(c => (
|
||||
<div key={c.id} className="border-2 border-dashed border-gray-400 rounded-xl p-4 bg-white" data-testid="sticker">
|
||||
<div className="text-3xl font-bold leading-tight">{c.firstName}</div>
|
||||
<div className="text-lg text-gray-700">{c.room || "—"}</div>
|
||||
<div className="mt-1 text-2xl font-mono font-bold tracking-widest">{code}</div>
|
||||
{c.sticker && <div className="mt-1 text-lg font-bold text-red-700">{c.sticker}</div>}
|
||||
{c.already && <div className="mt-1 text-xs text-gray-500">Was already checked in.</div>}
|
||||
</div>
|
||||
))}
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
@@ -2,7 +2,7 @@
|
||||
|
||||
import React, { useState } from "react";
|
||||
import Link from "next/link";
|
||||
import { Calendar, User, LayoutDashboard, ShieldCheck, Globe, Menu, Lock, type LucideIcon } from "lucide-react";
|
||||
import { Calendar, User, LayoutDashboard, ShieldCheck, Globe, Menu, Lock, Baby, type LucideIcon } from "lucide-react";
|
||||
import { useAuth } from "@/hooks/useAuth";
|
||||
import { RoleBadge, type Role } from "@/components/shared/RoleBadge";
|
||||
import { UserAvatar } from "@/components/shared/UserAvatar";
|
||||
@@ -12,6 +12,7 @@ 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/kids", label: "Kids", icon: Baby, 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"] },
|
||||
|
||||
Reference in New Issue
Block a user