import React, { useState } from "react"; import { useRouter } from "next/router"; import { Dialog, Transition } from "@headlessui/react"; import { observer } from "mobx-react-lite"; import { AlertTriangle } from "lucide-react"; // hooks import { useApplication, useProjectState } from "hooks/store"; import useToast from "hooks/use-toast"; // ui import { Button } from "@plane/ui"; // types import type { IState } from "@plane/types"; type Props = { isOpen: boolean; onClose: () => void; data: IState | null; }; export const DeleteStateModal: React.FC = observer((props) => { const { isOpen, onClose, data } = props; // states const [isDeleteLoading, setIsDeleteLoading] = useState(false); // router const router = useRouter(); const { workspaceSlug } = router.query; // store hooks const { eventTracker: { postHogEventTracker }, } = useApplication(); const { deleteState } = useProjectState(); // toast alert const { setToastAlert } = useToast(); const handleClose = () => { onClose(); setIsDeleteLoading(false); }; const handleDeletion = async () => { if (!workspaceSlug || !data) return; setIsDeleteLoading(true); await deleteState(workspaceSlug.toString(), data.project, data.id) .then(() => { postHogEventTracker("STATE_DELETE", { state: "SUCCESS", }); handleClose(); }) .catch((err) => { if (err.status === 400) setToastAlert({ type: "error", title: "Error!", message: "This state contains some issues within it, please move them to some other state to delete this state.", }); else setToastAlert({ type: "error", title: "Error!", message: "State could not be deleted. Please try again.", }); postHogEventTracker("STATE_DELETE", { state: "FAILED", }); }) .finally(() => { setIsDeleteLoading(false); }); }; return (
Delete State

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

); });