// react import React, { useState } from "react"; // next import { useRouter } from "next/router"; // swr import useSWR, { mutate } from "swr"; // react hook form import { SubmitHandler, useForm } from "react-hook-form"; // services import issuesServices from "lib/services/issues.service"; import projectService from "lib/services/project.service"; // hooks import useToast from "lib/hooks/useToast"; // headless ui import { Combobox, Dialog, Transition } from "@headlessui/react"; // ui import { Button } from "ui"; // icons import { FolderIcon, MagnifyingGlassIcon } from "@heroicons/react/24/outline"; // types import { IIssue, IssueResponse } from "types"; // fetch keys import { PROJECT_ISSUES_LIST, PROJECT_DETAILS } from "constants/fetch-keys"; // common import { classNames } from "constants/common"; import { LayerDiagonalIcon } from "ui/icons"; type FormInput = { issue_ids: string[]; cycleId: string; }; type Props = { isOpen: boolean; setIsOpen: React.Dispatch>; }; const BulkDeleteIssuesModal: React.FC = ({ isOpen, setIsOpen }) => { const [query, setQuery] = useState(""); const router = useRouter(); const { query: { workspaceSlug, projectId }, } = router; const { data: issues } = useSWR( workspaceSlug && projectId ? PROJECT_ISSUES_LIST(workspaceSlug as string, projectId as string) : null, workspaceSlug && projectId ? () => issuesServices.getIssues(workspaceSlug as string, projectId as string) : null ); const { data: projectDetails } = useSWR( workspaceSlug && projectId ? PROJECT_DETAILS(projectId as string) : null, workspaceSlug && projectId ? () => projectService.getProject(workspaceSlug as string, projectId as string) : null ); const { setToastAlert } = useToast(); const { register, handleSubmit, reset } = useForm(); const filteredIssues: IIssue[] = query === "" ? issues?.results ?? [] : issues?.results.filter((issue) => issue.name.toLowerCase().includes(query.toLowerCase())) ?? []; const handleClose = () => { setIsOpen(false); setQuery(""); reset(); }; const handleDelete: SubmitHandler = async (data) => { if (!data.issue_ids || data.issue_ids.length === 0) { setToastAlert({ title: "Error", type: "error", message: "Please select atleast one issue", }); return; } if (!Array.isArray(data.issue_ids)) data.issue_ids = [data.issue_ids]; if (workspaceSlug && projectId) { await issuesServices .bulkDeleteIssues(workspaceSlug as string, projectId as string, data) .then((res) => { setToastAlert({ title: "Success", type: "success", message: res.message, }); mutate( PROJECT_ISSUES_LIST(workspaceSlug as string, projectId as string), (prevData) => { return { ...(prevData as IssueResponse), count: (prevData?.results ?? []).filter( (p) => !data.issue_ids.some((id) => p.id === id) ).length, results: (prevData?.results ?? []).filter( (p) => !data.issue_ids.some((id) => p.id === id) ), }; }, false ); }) .catch((e) => { console.log(e); }); } }; return ( <> setQuery("")} appear>
{filteredIssues.length > 0 ? (
  • {query === "" && (

    Select issues to delete

    )}
      {filteredIssues.map((issue) => ( classNames( "flex cursor-pointer select-none items-center justify-between rounded-md px-3 py-2", active ? "bg-gray-900 bg-opacity-5 text-gray-900" : "" ) } >
      {projectDetails?.identifier}-{issue.sequence_id} {issue.name}
      ))}
  • ) : (

    No issues found. Create a new issue with{" "}
                                  Ctrl/Command + I
                                
    .

    )}
    {query !== "" && filteredIssues.length === 0 && (
    )}
    {filteredIssues.length > 0 && (
    )}
    ); }; export default BulkDeleteIssuesModal;