import React, { useState, useEffect } from "react"; import { useRouter } from "next/router"; import useSWR, { mutate } from "swr"; // component import { Dialog, Transition } from "@headlessui/react"; // services import cyclesService from "services/cycles.service"; // hooks import useToast from "hooks/use-toast"; import useIssuesView from "hooks/use-issues-view"; //icons import { MagnifyingGlassIcon, XMarkIcon } from "@heroicons/react/24/outline"; import { ContrastIcon, ExclamationIcon, TransferIcon } from "components/icons"; // fetch-key import { CYCLE_ISSUES_WITH_PARAMS, INCOMPLETE_CYCLES_LIST } from "constants/fetch-keys"; // types import { ICycle } from "types"; //helper import { getDateRangeStatus } from "helpers/date-time.helper"; 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 { params } = useIssuesView(); const { setToastAlert } = useToast(); const transferIssue = async (payload: any) => { await cyclesService .transferIssues(workspaceSlug as string, projectId as string, cycleId as string, payload) .then((res) => { mutate(CYCLE_ISSUES_WITH_PARAMS(cycleId as string, params)); 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 ? INCOMPLETE_CYCLES_LIST(projectId as string) : null, workspaceSlug && projectId ? () => cyclesService.getCyclesWithParams( workspaceSlug as string, projectId as string, "incomplete" ) : 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) => ( )) ) : (
You don’t have any current cycle. Please create one to transfer the issues.
) ) : (

Loading...

)}
); };