Files
vitareba/components/admin/InlineMessageCompose.tsx
GandClaude Opus 5 3e059f0818 chore: add a formatter (#83)
* chore: add a formatter, matching the style this repo already writes

singleQuote=false was chosen by counting this repo's own
imports, not by fleet decree. The fleet is genuinely split and the two repos
that already had a .prettierrc disagreed with each other, so there was no
standard to restore. Quote style does not cross repo boundaries; having a
gate does.

Markdown is ignored for now — prettier rewraps prose, which would bury the
real diff.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>

* style: format with prettier (304 files)

Mechanical. No behaviour change. This SHA is listed in
.git-blame-ignore-revs so `git blame` skips it.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>

* chore: teach git blame to skip the reformat

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>

* style: format the two files the reformat pass missed

prettier --check flagged app/shared.module.css and lib/domain/clinicians.test.ts
on a branch whose whole point was that everything had been formatted. Re-running
the same command with the same version fixes both, so the rollout's write step
did not finish what it reported.

The rollout now runs --check straight after --write and refuses to open a PR
unless it comes back clean, so a partial reformat fails at the source instead of
in CI.

---------

Co-authored-by: Claude Opus 5 <noreply@anthropic.com>
2026-08-29 10:48:01 +00:00

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";
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}
/>
<textarea
aria-label="Message body"
value={body}
onChange={(e) => setBody(e.target.value)}
maxLength={MESSAGE_BODY_MAX_LENGTH}
placeholder="Write a message…"
rows={3}
className={styles.composeTextarea}
/>
{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>
);
}