/** * Copyright (c) 2023-present Plane Software, Inc. and contributors * SPDX-License-Identifier: AGPL-3.0-only * See the LICENSE file for details. */ import { observer } from "mobx-react"; import { useParams } from "next/navigation"; import { Controller, useForm } from "react-hook-form"; import { WarningTriangleOutline } from "@makeplane/propel/icons"; // Plane imports import { Field } from "@makeplane/propel/components/field"; import { Input, InputGroup } from "@makeplane/propel/components/input"; import { Button } from "@plane/propel/button"; import { TOAST_TYPE, setToast } from "@plane/propel/toast"; import type { IProject } from "@plane/types"; import { EModalPosition, EModalWidth, ModalCore } from "@plane/ui"; // hooks import { useUserPermissions } from "@/hooks/store/user"; import { useAppRouter } from "@/hooks/use-app-router"; type FormData = { projectName: string; confirmLeave: string; }; const defaultValues: FormData = { projectName: "", confirmLeave: "", }; export interface ILeaveProjectModal { project: IProject; isOpen: boolean; onClose: () => void; } export const LeaveProjectModal = observer(function LeaveProjectModal(props: ILeaveProjectModal) { const { project, isOpen, onClose } = props; // router const router = useAppRouter(); const { workspaceSlug } = useParams(); // store hooks const { leaveProject } = useUserPermissions(); 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") { router.push(`/${workspaceSlug}/projects`); return leaveProject(workspaceSlug.toString(), project.id) .then(() => { handleClose(); }) .catch((_err) => { setToast({ type: TOAST_TYPE.ERROR, title: "Error!", message: "Something went wrong please try again later.", }); }); } 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 work items associated with you will become inaccessible.

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

( )} />

To confirm, type Leave Project below:

( )} />
); });