mirror of
https://github.com/bitbaum/vitareba.git
synced 2026-12-04 04:57:22 +01:00
* 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>
115 lines
3.6 KiB
TypeScript
115 lines
3.6 KiB
TypeScript
"use client";
|
|
|
|
import { useRef, useState } from "react";
|
|
import styles from "@/app/(admin)/admin.module.css";
|
|
import {
|
|
DOCUMENT_MAX_FILE_SIZE_MB,
|
|
DOCUMENT_TITLE_MAX_LENGTH,
|
|
SAVED_FEEDBACK_MS,
|
|
} from "@/lib/config/portal";
|
|
|
|
export function DocumentAddForm({ patientId }: { patientId: string }) {
|
|
const [title, setTitle] = useState("");
|
|
const [file, setFile] = useState<File | null>(null);
|
|
const [uploading, setUploading] = useState(false);
|
|
const [progress, setProgress] = useState<"idle" | "uploading" | "done" | "error">("idle");
|
|
const [errorMsg, setErrorMsg] = useState("");
|
|
const fileRef = useRef<HTMLInputElement>(null);
|
|
|
|
async function handleSubmit(e: React.FormEvent) {
|
|
e.preventDefault();
|
|
if (!file || !title.trim()) return;
|
|
|
|
setUploading(true);
|
|
setProgress("uploading");
|
|
setErrorMsg("");
|
|
|
|
try {
|
|
const formData = new FormData();
|
|
formData.set("file", file);
|
|
formData.set("title", title.trim());
|
|
formData.set("patientId", patientId);
|
|
|
|
const res = await fetch("/api/documents/upload", { method: "POST", body: formData });
|
|
const data = await res.json();
|
|
|
|
if (!data.success) {
|
|
setProgress("error");
|
|
setErrorMsg(data.error ?? "Upload failed.");
|
|
return;
|
|
}
|
|
|
|
setTitle("");
|
|
setFile(null);
|
|
if (fileRef.current) fileRef.current.value = "";
|
|
setProgress("done");
|
|
setTimeout(() => setProgress("idle"), SAVED_FEEDBACK_MS);
|
|
} catch {
|
|
setProgress("error");
|
|
setErrorMsg("Upload failed. Please try again.");
|
|
} finally {
|
|
setUploading(false);
|
|
}
|
|
}
|
|
|
|
return (
|
|
<form onSubmit={handleSubmit} className={styles.docForm}>
|
|
<p className={styles.docFormHeading}>Add document</p>
|
|
<div className={styles.formGrid2}>
|
|
<div className={styles.formField}>
|
|
<label className={styles.formLabel} htmlFor="doc-title">
|
|
Title
|
|
</label>
|
|
<input
|
|
id="doc-title"
|
|
className={styles.formInput}
|
|
value={title}
|
|
onChange={(e) => setTitle(e.target.value)}
|
|
placeholder="Lab results, Assessment report…"
|
|
maxLength={DOCUMENT_TITLE_MAX_LENGTH}
|
|
required
|
|
/>
|
|
</div>
|
|
<div className={styles.formField}>
|
|
<label className={styles.formLabel} htmlFor="doc-file">
|
|
File (max {DOCUMENT_MAX_FILE_SIZE_MB} MB)
|
|
</label>
|
|
<input
|
|
id="doc-file"
|
|
ref={fileRef}
|
|
className={styles.docFileInput}
|
|
type="file"
|
|
accept=".pdf,.png,.jpg,.jpeg,.webp,.doc,.docx,.xlsx,.csv"
|
|
onChange={(e) => {
|
|
const selected = e.target.files?.[0] ?? null;
|
|
if (selected && selected.size > DOCUMENT_MAX_FILE_SIZE_MB * 1024 * 1024) {
|
|
setProgress("error");
|
|
setErrorMsg(`File exceeds the ${DOCUMENT_MAX_FILE_SIZE_MB} MB limit.`);
|
|
e.target.value = "";
|
|
setFile(null);
|
|
} else {
|
|
setProgress("idle");
|
|
setErrorMsg("");
|
|
setFile(selected);
|
|
}
|
|
}}
|
|
required
|
|
/>
|
|
</div>
|
|
</div>
|
|
{progress === "error" && <p className={styles.assignError}>{errorMsg}</p>}
|
|
<button
|
|
type="submit"
|
|
className={styles.assignSubmit}
|
|
disabled={uploading || !file || !title.trim()}
|
|
>
|
|
{progress === "uploading"
|
|
? "Uploading…"
|
|
: progress === "done"
|
|
? "Uploaded ✓"
|
|
: "Upload document"}
|
|
</button>
|
|
</form>
|
|
);
|
|
}
|