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/kids/ChildForm.tsx
T

68 lines
4.0 KiB
TypeScript

"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>
);
}