import React, { useEffect, useRef, useState } from "react"; // headless ui import { Dialog, Transition } from "@headlessui/react"; // services import projectService from "lib/services/project.service"; // hooks import useUser from "lib/hooks/useUser"; import useToast from "lib/hooks/useToast"; // icons import { ExclamationTriangleIcon } from "@heroicons/react/24/outline"; // ui import { Button } from "ui"; // types import type { IProject } from "types"; type Props = { isOpen: boolean; setIsOpen: React.Dispatch>; data?: IProject; }; const ConfirmProjectDeletion: React.FC = ({ isOpen, setIsOpen, data }) => { const [isDeleteLoading, setIsDeleteLoading] = useState(false); const { activeWorkspace, mutateProjects } = useUser(); const { setToastAlert } = useToast(); const cancelButtonRef = useRef(null); const handleClose = () => { setIsOpen(false); setIsDeleteLoading(false); }; const handleDeletion = async () => { setIsDeleteLoading(true); if (!data || !activeWorkspace) return; await projectService .deleteProject(activeWorkspace.slug, data.id) .then(() => { handleClose(); mutateProjects((prevData) => (prevData ?? []).filter((item) => item.id !== data.id), false); setToastAlert({ title: "Success", type: "success", message: "Project deleted successfully", }); }) .catch((error) => { console.log(error); setIsDeleteLoading(false); }); }; useEffect(() => { data && setIsOpen(true); }, [data, setIsOpen]); return (
Delete Project

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

); }; export default ConfirmProjectDeletion;