"use client"; import React, { useEffect, useState } from "react"; import { observer } from "mobx-react"; import { useParams } from "next/navigation"; import { SubmitHandler, useForm } from "react-hook-form"; import { Search } from "lucide-react"; import { Combobox, Dialog, Transition } from "@headlessui/react"; //plane import { ISearchIssueResponse, IUser } from "@plane/types"; import { Button, Loader, TOAST_TYPE, setToast } from "@plane/ui"; //components import { EmptyState } from "@/components/empty-state"; //constants import { EmptyStateType } from "@/constants/empty-state"; import { EIssuesStoreType } from "@/constants/issue"; //hooks import { useIssues, useProject } from "@/hooks/store"; import useDebounce from "@/hooks/use-debounce"; // services import { ProjectService } from "@/services/project"; // ui // icons // components import { BulkDeleteIssuesModalItem } from "./bulk-delete-issues-modal-item"; type FormInput = { delete_issue_ids: string[]; }; type Props = { isOpen: boolean; onClose: () => void; user: IUser | undefined; }; const projectService = new ProjectService(); export const BulkDeleteIssuesModal: React.FC = observer((props) => { const { isOpen, onClose } = props; // router params const { workspaceSlug, projectId } = useParams(); // hooks const { getProjectById } = useProject(); const { issues: { removeBulkIssues }, } = useIssues(EIssuesStoreType.PROJECT); // states const [query, setQuery] = useState(""); const [issues, setIssues] = useState([]); const [isSearching, setIsSearching] = useState(false); const debouncedSearchTerm: string = useDebounce(query, 500); useEffect(() => { if (!isOpen || !workspaceSlug || !projectId) return; setIsSearching(true); projectService .projectIssuesSearch(workspaceSlug.toString(), projectId.toString(), { search: debouncedSearchTerm, workspace_search: false, }) .then((res: ISearchIssueResponse[]) => setIssues(res)) .finally(() => setIsSearching(false)); }, [debouncedSearchTerm, isOpen, projectId, workspaceSlug]); const { handleSubmit, watch, reset, setValue, formState: { isSubmitting }, } = useForm({ defaultValues: { delete_issue_ids: [], }, }); const handleClose = () => { setQuery(""); reset(); onClose(); }; const handleDelete: SubmitHandler = async (data) => { if (!workspaceSlug || !projectId) return; if (!data.delete_issue_ids || data.delete_issue_ids.length === 0) { setToast({ type: TOAST_TYPE.ERROR, title: "Error!", message: "Please select at least one issue.", }); return; } if (!Array.isArray(data.delete_issue_ids)) data.delete_issue_ids = [data.delete_issue_ids]; await removeBulkIssues(workspaceSlug as string, projectId as string, data.delete_issue_ids) .then(() => { setToast({ type: TOAST_TYPE.SUCCESS, title: "Success!", message: "Issues deleted successfully!", }); handleClose(); }) .catch(() => setToast({ type: TOAST_TYPE.ERROR, title: "Error!", message: "Something went wrong. Please try again.", }) ); }; const projectDetails = getProjectById(projectId as string); const issueList = issues.length > 0 ? (
  • {query === "" && (

    Select issues to delete

    )}
      {issues.map((issue) => ( ))}
  • ) : (
    ); return ( setQuery("")} appear>
    { const selectedIssues = watch("delete_issue_ids"); if (selectedIssues.includes(val)) setValue( "delete_issue_ids", selectedIssues.filter((i) => i !== val) ); else setValue("delete_issue_ids", [...selectedIssues, val]); }} >
    {isSearching ? ( ) : ( <>{issueList} )}
    {issues.length > 0 && (
    )}
    ); });