Files
vitareba/components/admin/ProgrammeAssignmentForm.tsx
CatoandClaude ed5359a242 feat: every prose field is chatkit's DictationField (#190)
One app wrapper, components/shared/TextBox.tsx, around chatkit's
DictationField. Every textarea in the portal and the admin now uses it:
profile, clinical context, check-in notes, new message, booking notes,
cancellation reason, clinician bio, programme notes, clinical notes,
goal notes and admin profile edits. The two thread reply boxes (patient
and clinician) are now chatkit's Composer.

The microphone is off (voice={false}). These fields hold health data.
Without a transcribeUrl, chatkit falls back to the browser's speech
recogniser, which sends audio to the browser vendor, and AGENTS.md lets
health data go only to an EU/CH provider under a DPA. Turn it on in
TextBox once a consent-gated transcription route exists.

Textarea, compose-row and send-button CSS that nothing uses any more
is removed.


Claude-Session: https://claude.ai/code/session_019MDtmrZVd3q4PDcqQwfLT9

Co-authored-by: Claude <noreply@anthropic.com>
2026-11-15 18:46:11 +01:00

171 lines
4.8 KiB
TypeScript

"use client";
import { useState } from "react";
import styles from "@/app/(admin)/admin.module.css";
import { SAVED_FEEDBACK_MS, PATIENT_NOTE_MAX_LENGTH } from "@/lib/config/portal";
import {
PROGRAMME_CONFIG,
PHASE_CONFIG,
PROGRAMME_ENUM_VALUES,
PHASE_ENUM_VALUES,
phaseDescription,
} from "@/lib/config/programmes";
import type { ProgrammeKey, PhaseKey } from "@/lib/config/programmes";
import { TextBox } from "@/components/shared/TextBox";
type Assignment = {
programme: ProgrammeKey;
phase: PhaseKey;
startDate: string | null;
notes: string | null;
};
export function ProgrammeAssignmentForm({
patientId,
initial,
clinician,
}: {
patientId: string;
initial: Assignment | null;
/** This patient's clinician, so the preview shows the copy they will read. */
clinician: string;
}) {
const [programme, setProgramme] = useState<ProgrammeKey | "">(initial?.programme ?? "");
const [phase, setPhase] = useState<PhaseKey | "">(initial?.phase ?? "");
const [startDate, setStartDate] = useState(initial?.startDate ?? "");
const [notes, setNotes] = useState(initial?.notes ?? "");
const [saving, setSaving] = useState(false);
const [saved, setSaved] = useState(false);
const [error, setError] = useState("");
async function handleSubmit(e: React.FormEvent) {
e.preventDefault();
if (!programme || !phase) return;
setSaving(true);
setError("");
try {
const res = await fetch(`/api/admin/patients/${patientId}/programme`, {
method: "PATCH",
headers: { "Content-Type": "application/json" },
body: JSON.stringify({
programme,
phase,
startDate: startDate || null,
notes: notes || null,
}),
});
const data = await res.json();
if (!data.success) {
setError("Failed to save assignment.");
return;
}
setSaved(true);
setTimeout(() => setSaved(false), SAVED_FEEDBACK_MS);
} catch {
setError("Failed to save assignment.");
} finally {
setSaving(false);
}
}
return (
<form onSubmit={handleSubmit} className={styles.formStack}>
<div className={styles.formGrid2}>
<div>
<label htmlFor="prog-programme" className={styles.assignLabel}>
Programme
</label>
<select
id="prog-programme"
value={programme}
onChange={(e) => setProgramme(e.target.value as ProgrammeKey)}
className={styles.assignField}
>
<option value="">Select programme…</option>
{PROGRAMME_ENUM_VALUES.map((key) => (
<option key={key} value={key}>
{PROGRAMME_CONFIG[key].label}
</option>
))}
</select>
</div>
<div>
<label htmlFor="prog-phase" className={styles.assignLabel}>
Phase
</label>
<select
id="prog-phase"
value={phase}
onChange={(e) => setPhase(e.target.value as PhaseKey)}
className={styles.assignField}
>
<option value="">Select phase…</option>
{PHASE_ENUM_VALUES.map((key) => (
<option key={key} value={key}>
{PHASE_CONFIG[key].label}
</option>
))}
</select>
</div>
</div>
<div>
<label htmlFor="prog-start-date" className={styles.assignLabel}>
Start date (optional)
</label>
<input
id="prog-start-date"
type="date"
value={startDate}
onChange={(e) => setStartDate(e.target.value)}
className={styles.assignField}
/>
</div>
<div>
<label htmlFor="prog-notes" className={styles.assignLabel}>
Notes (optional)
</label>
<TextBox
id="prog-notes"
value={notes}
onValueChange={(v) => setNotes(v)}
rows={2}
maxLength={PATIENT_NOTE_MAX_LENGTH}
placeholder="Any notes about this assignment…"
/>
</div>
{programme && phase && (
<div className={styles.assignPreview}>
<strong className={styles.assignPreviewLabel}>
{PROGRAMME_CONFIG[programme as ProgrammeKey]?.label}
</strong>
{" — "}
{phaseDescription(phase as PhaseKey, clinician)}
</div>
)}
{error && <p className={styles.assignError}>{error}</p>}
<button
type="submit"
disabled={saving || !programme || !phase}
className={styles.assignSubmit}
>
{saving
? "Saving…"
: saved
? "Saved ✓"
: initial
? "Update assignment"
: "Assign programme"}
</button>
</form>
);
}