"use client"; import { FC, Fragment } from "react"; import { observer } from "mobx-react"; import { useParams, useRouter } from "next/navigation"; import { Controller, useForm } from "react-hook-form"; // headless ui import { AlertTriangleIcon } from "lucide-react"; import { Dialog, Transition } from "@headlessui/react"; // icons import { IProject } from "@plane/types"; // 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 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 } = useParams(); // 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:

( )} />
); });