"use client"; import { useRef } from "react"; import { useRouter } from "next/navigation"; import { Button } from "@/components/ui/button"; import ActEditor from "./editor"; import { saveActAction } from "@/lib/acts/actions"; import { Spinner } from "@/components/ui/spinner"; import { useAction } from "@/hooks/useAction"; import { ActEditorData } from "@/lib/acts/types"; export default function CreateActClient({ actTypes, institutions, regions, positions }: { actTypes: { id: string; name: string; allowedIssuerKind: string }[]; institutions: { id: string; name: string; kind: string; appointedByInstitutionId: string | null }[]; regions: { id: string; name: string }[]; positions: { id: string; name: string; institutionId: string }[]; }) { const router = useRouter(); const { run, isPending } = useAction(saveActAction, { successMessage: "Act saved", onSuccess: () => router.push("/acts"), }); const dataRef = useRef({ actTypeId: "", issuingInstitutionId: "", title: "", preambleText: "", regionId: null, articles: [], }); function handleSave() { const data = dataRef.current; run(data); } return (

Create act

{ dataRef.current = data; }} />
); }