import { FC, Fragment } from "react"; import { observer } from "mobx-react-lite"; import { useRouter } from "next/router"; import { Controller, useForm } from "react-hook-form"; // headless ui import { Dialog, Transition } from "@headlessui/react"; // icons import { AlertTriangleIcon } from "lucide-react"; // ui import { Button, Input, TOAST_TYPE, setToast } from "@plane/ui"; // constants import { PROJECT_MEMBER_LEAVE } from "constants/event-tracker"; // hooks import { useEventTracker, useUser } from "hooks/store"; // types import { IProject } from "@plane/types"; type FormData = { projectName: string; confirmLeave: string; }; const defaultValues: FormData = { projectName: "", confirmLeave: "", }; export interface ILeaveProjectModal { project: IProject; isOpen: boolean; onClose: () => void; } export const LeaveProjectModal: FC = observer((props) => { const { project, isOpen, onClose } = props; // router const router = useRouter(); const { workspaceSlug } = router.query; // store hooks const { captureEvent } = useEventTracker(); const { membership: { leaveProject }, } = useUser(); const { control, formState: { errors, isSubmitting }, handleSubmit, reset, } = useForm({ defaultValues }); const handleClose = () => { reset({ ...defaultValues }); onClose(); }; const onSubmit = async (data: any) => { if (!workspaceSlug) return; if (data) { if (data.projectName === project?.name) { if (data.confirmLeave === "Leave Project") { return leaveProject(workspaceSlug.toString(), project.id) .then(() => { handleClose(); router.push(`/${workspaceSlug}/projects`); captureEvent(PROJECT_MEMBER_LEAVE, { state: "SUCCESS", element: "Project settings members page", }); }) .catch(() => { setToast({ type: TOAST_TYPE.ERROR, title: "Error!", message: "Something went wrong please try again later.", }); captureEvent(PROJECT_MEMBER_LEAVE, { state: "FAILED", element: "Project settings members page", }); }); } else { setToast({ type: TOAST_TYPE.ERROR, title: "Error!", message: "Please confirm leaving the project by typing the 'Leave Project'.", }); } } else { setToast({ type: TOAST_TYPE.ERROR, title: "Error!", message: "Please enter the project name as shown in the description.", }); } } else { setToast({ type: TOAST_TYPE.ERROR, title: "Error!", message: "Please fill all fields.", }); } }; return (

Leave Project

Are you sure you want to leave the project - {` "${project?.name}" `}? All of the issues associated with you will become inaccessible.

Enter the project name {project?.name}{" "} to continue:

( )} />

To confirm, type Leave Project below:

( )} />
); });