import React from "react"; import { useParams, useRouter } from "next/navigation"; import { Controller, useForm } from "react-hook-form"; import { AlertTriangle } from "lucide-react"; import { Dialog, Transition } from "@headlessui/react"; import type { IProject } from "@plane/types"; // hooks import { Button, Input, TOAST_TYPE, setToast } from "@plane/ui"; import { PROJECT_DELETED } from "@/constants/event-tracker"; import { useEventTracker, useProject } from "@/hooks/store"; // ui // types // 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 } = useParams(); // 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:

( )} />
); };