import { useEffect } from "react"; import dynamic from "next/dynamic"; // react-hook-form import { Controller, useForm } from "react-hook-form"; // ui import { Input, Loader, PrimaryButton, SecondaryButton } from "components/ui"; // types import { IPage } from "types"; type Props = { handleFormSubmit: (values: IPage) => Promise; handleClose: () => void; status: boolean; data?: IPage | null; }; // rich-text-editor const RemirrorRichTextEditor = dynamic(() => import("components/rich-text-editor"), { ssr: false, loading: () => ( ), }); const defaultValues = { name: "", description: "", }; export const PageForm: React.FC = ({ handleFormSubmit, handleClose, status, data }) => { const { register, formState: { errors, isSubmitting }, handleSubmit, reset, control, setValue, } = useForm({ defaultValues, }); const handleCreateUpdatePage = async (formData: IPage) => { await handleFormSubmit(formData); reset({ ...defaultValues, }); }; useEffect(() => { reset({ ...defaultValues, ...data, }); }, [data, reset]); return (

{status ? "Update" : "Create"} Page

{/*
( setValue("description", jsonValue)} onHTMLChange={(htmlValue) => setValue("description_html", htmlValue)} placeholder="Description" /> )} />
*/}
Cancel {status ? isSubmitting ? "Updating Page..." : "Update Page" : isSubmitting ? "Creating Page..." : "Create Page"}
); };