import { useEffect, useRef, useState } from "react"; import { AlertCircle, Loader2 } from "lucide-react"; import { Dialog, DialogContent, DialogDescription, DialogFooter, DialogHeader, DialogTitle, } from "../../../components/ui/dialog.tsx"; import { Alert, AlertDescription } from "../../../components/ui/alert.tsx"; import { Button } from "../../../components/ui/button.tsx"; import { Label } from "../../../components/ui/label.tsx"; import { Textarea } from "../../../components/ui/textarea.tsx"; import { relayServerFailure } from "../../../utils/fetchFailureMessage"; import { newOperationId, type HeldLabResult } from "../../../hooks/useHeldLabResults.ts"; // SETTING A LABORATORY RESULT ASIDE: it leaves the list, nothing is filed, and what the laboratory sent is kept. The // reason is required, because the next person to wonder where it went reads it. const REASON_MAX = 500; interface Props { item?: HeldLabResult; onClose: () => void; onDone: () => void; dismiss: (id: string, reason: string, operationId: string) => Promise; } const SetAsideHeldResultDialog = ({ item, onClose, onDone, dismiss }: Props) => { const [reason, setReason] = useState(""); const [busy, setBusy] = useState(false); const [error, setError] = useState(); const operation = useRef(newOperationId()); useEffect(() => { setReason(""); setError(undefined); operation.current = newOperationId(); }, [item]); const said = reason.trim(); const setAside = async () => { if (!item || !said || said.length > REASON_MAX) return; setBusy(true); setError(undefined); try { await dismiss(item.id, said, operation.current); onDone(); } catch (failure) { setError(relayServerFailure(failure, "This was not confirmed as set aside. Try again; a repeat is recognised.")); } finally { setBusy(false); } }; return ( { if (!open) onClose(); }}> Set this laboratory result aside Nothing is filed and it leaves this list. What the laboratory sent is kept.