/** * Copyright (c) 2023-present Plane Software, Inc. and contributors * SPDX-License-Identifier: AGPL-3.0-only * See the LICENSE file for details. */ 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 { useProject } from "@/hooks/store/use-project"; import { useAppRouter } from "@/hooks/use-app-router"; type DeleteProjectModal = { isOpen: boolean; project: IProject; onClose: () => void; }; const defaultValues = { projectName: "", confirmDelete: "", }; export function DeleteProjectModal(props: DeleteProjectModal) { const { isOpen, project, onClose } = props; // store hooks const { deleteProject } = useProject(); // router const router = useAppRouter(); 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; try { await deleteProject(workspaceSlug.toString(), project.id); if (projectId && projectId.toString() === project.id) router.push(`/${workspaceSlug}/projects`); handleClose(); setToast({ type: TOAST_TYPE.SUCCESS, title: "Success!", message: "Project deleted successfully.", }); } catch (_error) { 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:

( )} />
); }