"use client"; import React, { useState } from "react"; import { observer } from "mobx-react"; import { useParams } from "next/navigation"; import { AlertCircle, Search, X } from "lucide-react"; import { Dialog, Transition } from "@headlessui/react"; import { CycleIcon, TransferIcon } from "@plane/propel/icons"; import { TOAST_TYPE, setToast } from "@plane/propel/toast"; import { EIssuesStoreType } from "@plane/types"; import { useCycle } from "@/hooks/store/use-cycle"; import { useIssues } from "@/hooks/store/use-issues"; //icons // constants type Props = { isOpen: boolean; handleClose: () => void; cycleId: string; }; export const TransferIssuesModal: React.FC = observer((props) => { const { isOpen, handleClose, cycleId } = props; // states const [query, setQuery] = useState(""); // store hooks const { currentProjectIncompleteCycleIds, getCycleById, fetchActiveCycleProgress } = useCycle(); const { issues: { transferIssuesFromCycle }, } = useIssues(EIssuesStoreType.CYCLE); const { workspaceSlug, projectId } = useParams(); const transferIssue = async (payload: { new_cycle_id: string }) => { if (!workspaceSlug || !projectId || !cycleId) return; await transferIssuesFromCycle(workspaceSlug.toString(), projectId.toString(), cycleId.toString(), payload) .then(async () => { setToast({ type: TOAST_TYPE.SUCCESS, title: "Success!", message: "Work items have been transferred successfully", }); await getCycleDetails(payload.new_cycle_id); }) .catch(() => { setToast({ type: TOAST_TYPE.ERROR, title: "Error!", message: "Unable to transfer work items. Please try again.", }); }); }; /**To update issue counts in target cycle and current cycle */ const getCycleDetails = async (newCycleId: string) => { const cyclesFetch = [ fetchActiveCycleProgress(workspaceSlug.toString(), projectId.toString(), cycleId), fetchActiveCycleProgress(workspaceSlug.toString(), projectId.toString(), newCycleId), ]; await Promise.all(cyclesFetch).catch((error) => { setToast({ type: TOAST_TYPE.ERROR, title: "Error", message: error.error || "Unable to fetch cycle details", }); }); }; const filteredOptions = currentProjectIncompleteCycleIds?.filter((optionId) => { const cycleDetails = getCycleById(optionId); return cycleDetails?.name?.toLowerCase().includes(query?.toLowerCase()); }); // useEffect(() => { // const handleKeyDown = (e: KeyboardEvent) => { // if (e.key === "Escape") { // handleClose(); // } // }; // }, [handleClose]); return (

Transfer work items

setQuery(e.target.value)} value={query} />
{filteredOptions ? ( filteredOptions.length > 0 ? ( filteredOptions.map((optionId) => { const cycleDetails = getCycleById(optionId); if (!cycleDetails) return; return ( ); }) ) : (
You don’t have any current cycle. Please create one to transfer the work items.
) ) : (

Loading...

)}
); });