import { useEffect } from "react"; import { useRouter } from "next/router"; import useSWR from "swr"; 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"; // constant import { STATE_LIST } from "constants/fetch-keys"; // services import stateService from "services/state.service"; // components import { SelectFilters } from "components/views"; type Props = { handleFormSubmit: (values: IView) => Promise; handleClose: () => void; status: boolean; data?: IView; preLoadedData?: Partial | null; }; const defaultValues: Partial = { name: "", description: "", }; export const ViewForm: React.FC = ({ handleFormSubmit, handleClose, status, data, preLoadedData, }) => { const { register, formState: { errors, isSubmitting }, handleSubmit, reset, watch, setValue, } = useForm({ defaultValues, }); const handleCreateUpdateView = async (formData: IView) => { await handleFormSubmit(formData); reset({ ...defaultValues, }); }; useEffect(() => { reset({ ...defaultValues, ...data, }); }, [data, reset]); useEffect(() => { reset({ ...defaultValues, ...preLoadedData, }); }, [preLoadedData, reset]); const filters = watch("query"); return (

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