import { FC, Fragment } from "react"; import { observer } from "mobx-react-lite"; import { Dialog, Transition } from "@headlessui/react"; // hooks import { useMobxStore } from "lib/mobx/store-provider"; import useToast from "hooks/use-toast"; // components import { ProjectViewForm } from "components/views"; // types import { IProjectView } from "types"; type Props = { data?: IProjectView | null; isOpen: boolean; onClose: () => void; preLoadedData?: Partial | null; workspaceSlug: string; projectId: string; }; export const CreateUpdateProjectViewModal: FC = observer((props) => { const { data, isOpen, onClose, preLoadedData, workspaceSlug, projectId } = props; // store const { projectViews: projectViewsStore } = useMobxStore(); // hooks const { setToastAlert } = useToast(); const handleClose = () => { onClose(); }; const createView = async (payload: IProjectView) => { await projectViewsStore .createView(workspaceSlug, projectId, payload) .then(() => handleClose()) .catch(() => setToastAlert({ type: "error", title: "Error!", message: "Something went wrong. Please try again.", }) ); }; const updateView = async (payload: IProjectView) => { await projectViewsStore .updateView(workspaceSlug, projectId, data?.id as string, payload) .then(() => handleClose()) .catch(() => setToastAlert({ type: "error", title: "Error!", message: "Something went wrong. Please try again.", }) ); }; const handleFormSubmit = async (formData: IProjectView) => { if (!data) await createView(formData); else await updateView(formData); }; return (
); });