"use client"; import { useActionState } from "react"; import { useTranslations } from "next-intl"; import { AlertCircle, CheckCircle2 } from "lucide-react"; import type { ActionState } from "@/server/api/action-state"; import { buttonCls } from "@/components/work-orders/action-form"; import { cn } from "@/lib/utils"; type Action = (prev: ActionState, fd: FormData) => Promise; /** Form bound to an emergency review server action; errors are translated codes (emergency.review.errors.*). */ export function ReviewForm({ action, children, submitLabel, successText, variant = "default", className, }: { action: Action; children?: React.ReactNode; submitLabel: string; successText?: string; variant?: "primary" | "default" | "outline" | "danger"; className?: string; }) { const [state, formAction, pending] = useActionState(action, { status: "idle" } as ActionState); const t = useTranslations("emergency.review"); let errorText = ""; if (state.status === "error") { const reasonKey = state.reason ? `errors.${state.reason}` : ""; errorText = reasonKey && t.has(reasonKey) ? t(reasonKey) : t.has(`errors.${state.code}`) ? t(`errors.${state.code}`) : t("errors.generic"); } return (
{children} {state.status === "error" && (

{errorText}

)} {state.status === "ok" && successText && (

{successText}

)}
); }