mirror of
https://github.com/bitbaum/vitareba.git
synced 2026-12-04 05:37:46 +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>
107 lines
3.1 KiB
TypeScript
107 lines
3.1 KiB
TypeScript
"use client";
|
|
|
|
import { useState } from "react";
|
|
import Link from "next/link";
|
|
import styles from "@/app/(admin)/admin.module.css";
|
|
import { MESSAGE_SUBJECT_MAX_LENGTH, MESSAGE_BODY_MAX_LENGTH } from "@/lib/config/portal";
|
|
import { ADMIN_ROUTES } from "@/lib/config/routes";
|
|
import { TextBox } from "@/components/shared/TextBox";
|
|
|
|
export function InlineMessageCompose({ patientId }: { patientId: string }) {
|
|
const [expanded, setExpanded] = useState(false);
|
|
const [subject, setSubject] = useState("");
|
|
const [body, setBody] = useState("");
|
|
const [sending, setSending] = useState(false);
|
|
const [sentThreadId, setSentThreadId] = useState<string | null>(null);
|
|
const [error, setError] = useState("");
|
|
|
|
async function handleSubmit(e: React.FormEvent) {
|
|
e.preventDefault();
|
|
if (!subject.trim() || !body.trim()) return;
|
|
setSending(true);
|
|
setError("");
|
|
try {
|
|
const res = await fetch("/api/messages", {
|
|
method: "POST",
|
|
headers: { "Content-Type": "application/json" },
|
|
body: JSON.stringify({ subject: subject.trim(), body: body.trim(), patientId }),
|
|
});
|
|
const data = await res.json();
|
|
if (!data.success) {
|
|
setError("Failed to send message.");
|
|
return;
|
|
}
|
|
setSentThreadId(data.data?.threadId ?? data.data?.id ?? null);
|
|
setExpanded(false);
|
|
setSubject("");
|
|
setBody("");
|
|
} catch {
|
|
setError("Failed to send message.");
|
|
} finally {
|
|
setSending(false);
|
|
}
|
|
}
|
|
|
|
if (sentThreadId) {
|
|
return (
|
|
<div className={styles.composeSent}>
|
|
Sent —{" "}
|
|
<Link href={`${ADMIN_ROUTES.messages}/${sentThreadId}`} className={styles.composeSentLink}>
|
|
View conversation →
|
|
</Link>
|
|
</div>
|
|
);
|
|
}
|
|
|
|
if (!expanded) {
|
|
return (
|
|
<button type="button" onClick={() => setExpanded(true)} className={styles.composeNewBtn}>
|
|
New message +
|
|
</button>
|
|
);
|
|
}
|
|
|
|
return (
|
|
<form onSubmit={handleSubmit} className={styles.composeForm}>
|
|
<input
|
|
type="text"
|
|
aria-label="Message subject"
|
|
value={subject}
|
|
onChange={(e) => setSubject(e.target.value)}
|
|
maxLength={MESSAGE_SUBJECT_MAX_LENGTH}
|
|
placeholder="Subject"
|
|
className={styles.composeInput}
|
|
/>
|
|
<TextBox
|
|
ariaLabel="Message body"
|
|
value={body}
|
|
onValueChange={(v) => setBody(v)}
|
|
maxLength={MESSAGE_BODY_MAX_LENGTH}
|
|
placeholder="Write a message…"
|
|
rows={3}
|
|
/>
|
|
{error && <p className={styles.assignError}>{error}</p>}
|
|
<div className={styles.goalFormActions}>
|
|
<button
|
|
type="submit"
|
|
disabled={sending || !subject.trim() || !body.trim()}
|
|
className={styles.composeSend}
|
|
>
|
|
{sending ? "Sending…" : "Send"}
|
|
</button>
|
|
<button
|
|
type="button"
|
|
onClick={() => {
|
|
setExpanded(false);
|
|
setError("");
|
|
}}
|
|
aria-label="Discard message and close compose form"
|
|
className={styles.composeCancel}
|
|
>
|
|
Cancel
|
|
</button>
|
|
</div>
|
|
</form>
|
|
);
|
|
}
|