import React, { useEffect, useRef, useState } from "react"; // swr import { mutate } from "swr"; // headless ui import { Dialog, Transition } from "@headlessui/react"; // services import stateServices from "lib/services/state.service"; // fetch api import { STATE_LIST } from "constants/fetch-keys"; // hooks import useUser from "lib/hooks/useUser"; // icons import { ExclamationTriangleIcon } from "@heroicons/react/24/outline"; // ui import { Button } from "ui"; // types import type { IState } from "types"; type Props = { isOpen: boolean; onClose: () => void; data: IState | null; }; const ConfirmStateDeletion: React.FC = ({ isOpen, onClose, data }) => { const [isDeleteLoading, setIsDeleteLoading] = useState(false); const { activeWorkspace } = useUser(); const cancelButtonRef = useRef(null); const handleClose = () => { onClose(); setIsDeleteLoading(false); }; const handleDeletion = async () => { setIsDeleteLoading(true); if (!data || !activeWorkspace) return; await stateServices .deleteState(activeWorkspace.slug, data.project, data.id) .then(() => { mutate( STATE_LIST(data.project), (prevData) => prevData?.filter((state) => state.id !== data?.id), false ); handleClose(); }) .catch((error) => { console.log(error); 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.

); }; export default ConfirmStateDeletion;