"use client"; import { useState } from "react"; import { useRouter } from "next/navigation"; import type { SeafarerDocType } from "@prisma/client"; import { AdminDialog } from "@/components/ui/admin-dialog"; import { verifyDocument, verifyBankEpf, verifyPpe, verifyNextOfKin, recordEpfoCheck } from "./actions"; import { verifyAppraisal } from "../appraisals/actions"; import type { PpeItem } from "@prisma/client"; const label = (s: string) => s.replace(/_/g, " ").toLowerCase().replace(/\b\w/g, (m) => m.toUpperCase()); const fmt = (iso: string | null) => (iso ? new Date(iso).toLocaleDateString() : "—"); const isExpired = (iso: string | null) => Boolean(iso && new Date(iso) < new Date()); type Doc = { id: string; crewName: string; location: string; docType: SeafarerDocType; number: string | null; expiryDate: string | null; submitted: string }; type Bank = { crewMemberId: string; crewName: string; accountName: string | null; accountNumber: string | null; ifsc: string | null; bankName: string | null }; type Epf = { crewMemberId: string; crewName: string; uan: string | null; aadhaarLast4: string | null; pfNumber: string | null }; type Appr = { id: string; crewName: string; rank: string; period: string; comments: string | null }; type Ppe = { id: string; crewName: string; item: PpeItem; size: string | null }; type Nok = { id: string; crewName: string; name: string; relationship: string | null }; function Actions({ onVerify, onReject }: { onVerify: () => Promise<{ ok: true } | { error: string }>; onReject: (reason: string) => Promise<{ ok: true } | { error: string }> }) { const router = useRouter(); const [pending, setPending] = useState(false); const [error, setError] = useState(""); const [open, setOpen] = useState(false); const [reason, setReason] = useState(""); async function verify() { setPending(true); setError(""); const res = await onVerify(); setPending(false); if ("error" in res) setError(res.error); else router.refresh(); } async function reject(e: React.FormEvent) { e.preventDefault(); setPending(true); setError(""); const res = await onReject(reason); setPending(false); if ("error" in res) setError(res.error); else { setOpen(false); router.refresh(); } } return (
{error &&

{error}

} setOpen(false)}>