"use client"; import { useState } from "react"; import { useRouter } from "next/navigation"; import { AdminDialog } from "@/components/ui/admin-dialog"; import { cancelRequisition } from "../actions"; const INPUT = "w-full rounded-lg border border-neutral-300 px-3 py-2 text-sm focus:border-primary-500 focus:outline-none focus:ring-2 focus:ring-primary-500/20"; export function WithdrawRequisitionButton({ id }: { id: string }) { const router = useRouter(); const [open, setOpen] = useState(false); const [pending, setPending] = useState(false); const [error, setError] = useState(""); const [reason, setReason] = useState(""); async function handleSubmit(e: React.FormEvent) { e.preventDefault(); setPending(true); setError(""); const result = await cancelRequisition(id, reason); setPending(false); if ("error" in result) { setError(result.error); } else { setOpen(false); router.refresh(); } } return ( <> setOpen(true)} className="rounded-lg border border-danger-300 px-4 py-2 text-sm font-medium text-danger-700 hover:bg-danger-50" > Withdraw setOpen(false)}> Withdrawing closes this requisition. A reason is required and is recorded on the audit trail. Reason * setReason(e.target.value)} required /> {error && {error}} setOpen(false)} className="rounded-lg border border-neutral-300 px-4 py-2 text-sm font-medium text-neutral-700 hover:bg-neutral-50"> Cancel {pending ? "Withdrawing…" : "Withdraw requisition"} > ); }
Withdrawing closes this requisition. A reason is required and is recorded on the audit trail.
{error}