import { useEffect } from "react"; import { useForm } from "react-hook-form"; // ui import { Input, PrimaryButton, SecondaryButton, TextArea } from "components/ui"; // components import { FilterList } from "components/core"; // types import { IView } from "types"; // components import { SelectFilters } from "components/views"; type Props = { handleFormSubmit: (values: IView) => Promise; handleClose: () => void; status: boolean; data?: IView | null; }; const defaultValues: Partial = { name: "", description: "", }; export const ViewForm: React.FC = ({ handleFormSubmit, handleClose, status, data }) => { const { register, formState: { errors, isSubmitting }, handleSubmit, reset, watch, setValue, } = useForm({ defaultValues, }); const filters = watch("query"); const handleCreateUpdateView = async (formData: IView) => { await handleFormSubmit(formData); reset({ ...defaultValues, }); }; useEffect(() => { reset({ ...defaultValues, ...data, }); }, [data, reset]); useEffect(() => { if (status && data) { setValue("query", data.query_data); } }, [data, status, setValue]); return (

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