59 lines
1.8 KiB
TypeScript
59 lines
1.8 KiB
TypeScript
"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<ActEditorData>({
|
|
actTypeId: "",
|
|
issuingInstitutionId: "",
|
|
title: "",
|
|
preambleText: "",
|
|
regionId: null,
|
|
articles: [],
|
|
});
|
|
|
|
function handleSave() {
|
|
const data = dataRef.current;
|
|
run(data);
|
|
}
|
|
|
|
return (
|
|
<div className="flex flex-col p-4 md:p-16 gap-6 md:gap-12 mb-4 md:mb-0">
|
|
<div className="flex flex-col gap-4 md:flex-row md:items-center justify-between">
|
|
<h1>Create act</h1>
|
|
<div className="flex flex-row gap-3">
|
|
<Button disabled={isPending} onClick={handleSave}>
|
|
{isPending && <Spinner />}
|
|
Save
|
|
</Button>
|
|
</div>
|
|
</div>
|
|
<ActEditor
|
|
actTypes={actTypes}
|
|
institutions={institutions}
|
|
regions={regions}
|
|
positions={positions}
|
|
onChange={(data) => { dataRef.current = data; }}
|
|
/>
|
|
</div>
|
|
);
|
|
} |