mirror of
https://github.com/bitbaum/vitareba.git
synced 2026-12-04 04:37:16 +01:00
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>
88 lines
2.5 KiB
TypeScript
88 lines
2.5 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 { formatDateShort } from "@/lib/utils/format";
|
|
import { TextBox } from "@/components/shared/TextBox";
|
|
|
|
type Note = {
|
|
id: string;
|
|
body: string;
|
|
createdAt: string;
|
|
adminName: string | null;
|
|
};
|
|
|
|
export function AdminNotesForm({
|
|
patientId,
|
|
initialNotes,
|
|
}: {
|
|
patientId: string;
|
|
initialNotes: Note[];
|
|
}) {
|
|
const [notes, setNotes] = useState<Note[]>(initialNotes);
|
|
const [body, setBody] = useState("");
|
|
const [saving, setSaving] = useState(false);
|
|
const [saved, setSaved] = useState(false);
|
|
const [error, setError] = useState("");
|
|
|
|
async function handleSubmit(e: React.FormEvent) {
|
|
e.preventDefault();
|
|
if (!body.trim()) return;
|
|
setSaving(true);
|
|
setError("");
|
|
try {
|
|
const res = await fetch(`/api/admin/patients/${patientId}/notes`, {
|
|
method: "POST",
|
|
headers: { "Content-Type": "application/json" },
|
|
body: JSON.stringify({ body: body.trim() }),
|
|
});
|
|
const data = await res.json();
|
|
if (!data.success) {
|
|
setError("Failed to save note.");
|
|
return;
|
|
}
|
|
setNotes((prev) => [data.data, ...prev]);
|
|
setBody("");
|
|
setSaved(true);
|
|
setTimeout(() => setSaved(false), SAVED_FEEDBACK_MS);
|
|
} catch {
|
|
setError("Failed to save note.");
|
|
} finally {
|
|
setSaving(false);
|
|
}
|
|
}
|
|
|
|
return (
|
|
<div>
|
|
{notes.length > 0 && (
|
|
<div className={styles.notesList}>
|
|
{notes.map((n) => (
|
|
<div key={n.id} className={styles.noteItem}>
|
|
<div className={styles.noteMeta}>
|
|
{n.adminName ?? "Admin"} · {formatDateShort(n.createdAt)}
|
|
</div>
|
|
<p className={styles.noteBody}>{n.body}</p>
|
|
</div>
|
|
))}
|
|
</div>
|
|
)}
|
|
|
|
<form onSubmit={handleSubmit} className={styles.noteForm}>
|
|
<TextBox
|
|
ariaLabel="Clinical note"
|
|
value={body}
|
|
onValueChange={(v) => setBody(v)}
|
|
maxLength={PATIENT_NOTE_MAX_LENGTH}
|
|
placeholder="Add a clinical note…"
|
|
rows={3}
|
|
/>
|
|
{error && <p className={styles.assignError}>{error}</p>}
|
|
<button type="submit" disabled={saving || !body.trim()} className={styles.assignSubmit}>
|
|
{saving ? "Saving…" : saved ? "Saved ✓" : "Add note"}
|
|
</button>
|
|
</form>
|
|
</div>
|
|
);
|
|
}
|