"use client"; import { useState } from "react"; import { useRouter } from "next/navigation"; import { AdminDialog } from "@/components/ui/admin-dialog"; import { raiseRequisition, convertReliefToRequisition } from "./actions"; import { REASON_OPTIONS, REASON_LABEL } from "./requisition-ui"; 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"; type Opt = { id: string; name: string }; type RankOpt = { id: string; code: string; name: string }; // A single "Vessel / site" picker — values are encoded "v:" / "s:" so // one control covers both cost axes (spec §9 modal). Returns "" when unset. function LocationSelect({ value, onChange, vessels, sites, }: { value: string; onChange: (v: string) => void; vessels: Opt[]; sites: Opt[]; }) { return ( ); } function applyLocation(fd: FormData, location: string) { if (location.startsWith("v:")) fd.set("vesselId", location.slice(2)); else if (location.startsWith("s:")) fd.set("siteId", location.slice(2)); } // ── Raise requisition (MPO / Manager) ────────────────────────────────────────── export function RaiseRequisitionButton({ ranks, vessels, sites, }: { ranks: RankOpt[]; vessels: Opt[]; sites: Opt[]; }) { const router = useRouter(); const [open, setOpen] = useState(false); const [pending, setPending] = useState(false); const [error, setError] = useState(""); const [rankId, setRankId] = useState(""); const [location, setLocation] = useState(""); const [reason, setReason] = useState(REASON_OPTIONS[0]); const [neededBy, setNeededBy] = useState(""); const [notes, setNotes] = useState(""); function reset() { setRankId(""); setLocation(""); setReason(REASON_OPTIONS[0]); setNeededBy(""); setNotes(""); setError(""); } async function handleSubmit(e: React.FormEvent) { e.preventDefault(); setPending(true); setError(""); const fd = new FormData(); fd.set("rankId", rankId); applyLocation(fd, location); fd.set("reason", reason); if (neededBy) fd.set("neededBy", neededBy); if (notes) fd.set("notes", notes); const result = await raiseRequisition(fd); setPending(false); if ("error" in result) { setError(result.error); } else { setOpen(false); reset(); router.refresh(); } } return ( <> setOpen(false)}>
setNeededBy(e.target.value)} />
setNotes(e.target.value)} placeholder="Optional" />
{error &&

{error}

}
); } // ── Convert a relief request into a requisition (MPO / Manager) ───────────────── export function ConvertReliefButton({ reliefRequestId, label, }: { reliefRequestId: string; label: string; }) { const router = useRouter(); const [open, setOpen] = useState(false); const [pending, setPending] = useState(false); const [error, setError] = useState(""); const [reason, setReason] = useState("REPLACEMENT"); const [neededBy, setNeededBy] = useState(""); const [notes, setNotes] = useState(""); async function handleSubmit(e: React.FormEvent) { e.preventDefault(); setPending(true); setError(""); const fd = new FormData(); fd.set("reliefRequestId", reliefRequestId); fd.set("reason", reason); if (neededBy) fd.set("neededBy", neededBy); if (notes) fd.set("notes", notes); const result = await convertReliefToRequisition(fd); setPending(false); if ("error" in result) { setError(result.error); } else { setOpen(false); router.refresh(); } } return ( <> setOpen(false)}>

Convert the relief request {label} into an open requisition so sourcing can begin.

setNeededBy(e.target.value)} />
setNotes(e.target.value)} placeholder="Optional" />
{error &&

{error}

}
); }