import React from "react"; import { useRouter } from "next/router"; import { Controller, useForm } from "react-hook-form"; import { Dialog, Transition } from "@headlessui/react"; // hooks import useToast from "hooks/use-toast"; // icons import { ExclamationTriangleIcon } from "@heroicons/react/24/outline"; // ui import { Button, Input } from "@plane/ui"; // types import type { IProject } from "types"; // fetch-keys import { useMobxStore } from "lib/mobx/store-provider"; type DeleteProjectModal = { isOpen: boolean; project: IProject; onClose: () => void; }; const defaultValues = { projectName: "", confirmDelete: "", }; export const DeleteProjectModal: React.FC = (props) => { const { isOpen, project, onClose } = props; // store const { project: projectStore } = useMobxStore(); // router const router = useRouter(); const { workspaceSlug } = router.query; // toast const { setToastAlert } = useToast(); // form info const { control, formState: { errors, isSubmitting }, handleSubmit, reset, watch, } = useForm({ defaultValues }); const canDelete = watch("projectName") === project?.name && watch("confirmDelete") === "delete my project"; const handleClose = () => { const timer = setTimeout(() => { reset(defaultValues); clearTimeout(timer); }, 350); onClose(); }; const onSubmit = async () => { if (!workspaceSlug || !canDelete) return; await projectStore .deleteProject(workspaceSlug.toString(), project.id) .then(() => { handleClose(); }) .catch(() => { setToastAlert({ type: "error", title: "Error!", message: "Something went wrong. Please try again later.", }); }); }; return (

Delete Project

Are you sure you want to delete project{" "} {project?.name}? All of the data related to the project will be permanently removed. This action cannot be undone

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

( )} />

To confirm, type delete my project{" "} below:

( )} />
); };