import React, { useEffect, useRef, useState } from "react"; // next import { useRouter } from "next/router"; // swr import { mutate } from "swr"; // headless ui import { Dialog, Transition } from "@headlessui/react"; import { ExclamationTriangleIcon } from "@heroicons/react/24/outline"; // services import cycleService from "services/cycles.service"; // ui import { Button } from "components/ui"; // icons // types import type { ICycle } from "types"; type TConfirmCycleDeletionProps = { isOpen: boolean; setIsOpen: React.Dispatch>; data?: ICycle; }; // fetch-keys import { CYCLE_LIST } from "constants/fetch-keys"; const ConfirmCycleDeletion: React.FC = (props) => { const { isOpen, setIsOpen, data } = props; const cancelButtonRef = useRef(null); const [isDeleteLoading, setIsDeleteLoading] = useState(false); const router = useRouter(); const { workspaceSlug } = router.query; useEffect(() => { data && setIsOpen(true); }, [data, setIsOpen]); const handleClose = () => { setIsOpen(false); setIsDeleteLoading(false); }; const handleDeletion = async () => { setIsDeleteLoading(true); if (!data || !workspaceSlug) return; await cycleService .deleteCycle(workspaceSlug as string, data.project, data.id) .then(() => { mutate( CYCLE_LIST(data.project), (prevData) => prevData?.filter((cycle) => cycle.id !== data?.id), false ); handleClose(); }) .catch((error) => { console.log(error); setIsDeleteLoading(false); }); }; return (
Delete Cycle

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

); }; export default ConfirmCycleDeletion;