"use client"; import { useState } from "react"; import { useRouter } from "next/navigation"; import { discardDraftPo } from "@/app/(portal)/po/[id]/actions"; export function DiscardDraftButton({ poId }: { poId: string }) { const router = useRouter(); const [pending, setPending] = useState(false); const [error, setError] = useState(""); async function handleDiscard() { if (!confirm("Permanently discard this draft? This cannot be undone.")) return; setPending(true); const result = await discardDraftPo(poId); if ("error" in result) { setError(result.error); setPending(false); } else { router.push("/my-orders"); } } return ( {error && ( {error} )} ); }