import React from "react"; import { useRouter } from "next/router"; import { Controller, useForm } from "react-hook-form"; import { Dialog, Transition } from "@headlessui/react"; import { AlertTriangle } from "lucide-react"; // hooks import { Button, Input, TOAST_TYPE, setToast } from "@plane/ui"; import { useEventTracker, useProject } from "hooks/store"; // ui // types import type { IProject } from "@plane/types"; import { PROJECT_DELETED } from "constants/event-tracker"; // constants type DeleteProjectModal = { isOpen: boolean; project: IProject; onClose: () => void; }; const defaultValues = { projectName: "", confirmDelete: "", }; export const DeleteProjectModal: React.FC = (props) => { const { isOpen, project, onClose } = props; // store hooks const { captureProjectEvent } = useEventTracker(); const { deleteProject } = useProject(); // router const router = useRouter(); const { workspaceSlug, projectId } = router.query; // 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 deleteProject(workspaceSlug.toString(), project.id) .then(() => { if (projectId && projectId.toString() === project.id) router.push(`/${workspaceSlug}/projects`); handleClose(); captureProjectEvent({ eventName: PROJECT_DELETED, payload: { ...project, state: "SUCCESS", element: "Project general settings" }, }); setToast({ type: TOAST_TYPE.SUCCESS, title: "Success!", message: "Project deleted successfully.", }); }) .catch(() => { captureProjectEvent({ eventName: PROJECT_DELETED, payload: { ...project, state: "FAILED", element: "Project general settings" }, }); setToast({ type: TOAST_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:

( )} />
); };