import { useState } from "react"; import { AlertCircle, CheckCircle2 } 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 { Input } from "../../../components/ui/input.tsx"; import { Label } from "../../../components/ui/label.tsx"; import { relayServerFailure } from "../../../utils/fetchFailureMessage"; import { useReturnDiagnosticResult } from "../../../hooks/useReturnDiagnosticResult.ts"; interface Props { orderId?: string; test?: string; sender?: string; onClose: () => void; } // The number is typed from the requisition's letterhead; nothing looks it up. const FaxResultDialog = ({ orderId, test, sender, onClose }: Props) => { const { faxResult } = useReturnDiagnosticResult(); const [toNumber, setToNumber] = useState(""); const [busy, setBusy] = useState(false); const [error, setError] = useState(); const [sent, setSent] = useState(false); if (!orderId) return null; const submit = async () => { setBusy(true); setError(undefined); try { await faxResult(orderId, toNumber); setSent(true); } catch (failure) { console.error("Error faxing a result:", failure); setError(relayServerFailure(failure, "The result was not sent.")); } finally { setBusy(false); } }; return ( { if (!open && !busy) onClose(); }}> Fax the result back {test ?? "This result"} {sender ? `, ordered by ${sender}` : ""} {". Use the fax number on their requisition."} {error ? ( {error} ) : null} {sent ? ( Your fax service accepted it for {toNumber}. ) : (
setToNumber(event.target.value)} />
)} {sent ? ( ) : ( )}
); }; export default FaxResultDialog;