import React, { useState, useEffect } from "react"; import { useRouter } from "next/router"; import useSWR from "swr"; // component import { Dialog, Transition } from "@headlessui/react"; // services import cyclesService from "services/cycles.service"; // hooks import useToast from "hooks/use-toast"; //icons import { MagnifyingGlassIcon, XMarkIcon } from "@heroicons/react/24/outline"; import { ContrastIcon, CyclesIcon } from "components/icons"; // fetch-key import { CYCLE_INCOMPLETE_LIST } from "constants/fetch-keys"; // types import { ICycle } from "types"; type Props = { isOpen: boolean; handleClose: () => void; }; export const TransferIssuesModal: React.FC = ({ isOpen, handleClose }) => { const [query, setQuery] = useState(""); const router = useRouter(); const { workspaceSlug, projectId, cycleId } = router.query; const { setToastAlert } = useToast(); const transferIssue = async (payload: any) => { await cyclesService .transferIssues(workspaceSlug as string, projectId as string, cycleId as string, payload) .then((res) => { setToastAlert({ type: "success", title: "Issues transfered successfully", message: "Issues have been transferred successfully", }); }) .catch((err) => { setToastAlert({ type: "error", title: "Error!", message: "Issues cannot be transfer. Please try again.", }); }); }; const { data: incompleteCycles } = useSWR( workspaceSlug && projectId ? CYCLE_INCOMPLETE_LIST(projectId as string) : null, workspaceSlug && projectId ? () => cyclesService.getIncompleteCycles(workspaceSlug as string, projectId as string) : null ); const filteredOptions = query === "" ? incompleteCycles : incompleteCycles?.filter((option) => option.name.toLowerCase().includes(query.toLowerCase()) ); useEffect(() => { const handleKeyDown = (e: KeyboardEvent) => { if (e.key === "Escape") { handleClose(); } }; }, [handleClose]); return (

Transfer Issues

setQuery(e.target.value)} value={query} />
{filteredOptions ? ( filteredOptions.length > 0 ? ( filteredOptions.map((option: ICycle) => ( )) ) : (

No matching results

) ) : (

Loading...

)}
); };