// react import React, { useState } from "react"; // react-hook-form import { SubmitHandler, useForm, UseFormWatch } from "react-hook-form"; // hooks import useUser from "lib/hooks/useUser"; import useToast from "lib/hooks/useToast"; // headless ui import { Combobox, Dialog, Transition } from "@headlessui/react"; // ui import { Button } from "ui"; // icons import { FolderIcon, MagnifyingGlassIcon, UserGroupIcon, XMarkIcon, } from "@heroicons/react/24/outline"; // types import { IIssue } from "types"; // constants import { classNames } from "constants/common"; type FormInput = { issue_ids: string[]; }; type Props = { submitChanges: (formData: Partial) => void; issuesList: IIssue[]; watch: UseFormWatch; }; const SelectBlocked: React.FC = ({ submitChanges, issuesList, watch }) => { const [query, setQuery] = useState(""); const [isBlockedModalOpen, setIsBlockedModalOpen] = useState(false); const { activeProject, issues } = useUser(); const { setToastAlert } = useToast(); const { register, handleSubmit, reset, watch: watchIssues } = useForm(); const handleClose = () => { setIsBlockedModalOpen(false); reset(); }; const onSubmit: SubmitHandler = (data) => { if (!data.issue_ids || data.issue_ids.length === 0) { setToastAlert({ title: "Error", type: "error", message: "Please select atleast one issue", }); return; } const newBlocked = [...watch("blocked_list"), ...data.issue_ids]; submitChanges({ blocked_list: newBlocked }); handleClose(); }; return (

Blocked issues

{watch("blocked_list") && watch("blocked_list").length > 0 ? watch("blocked_list").map((issue) => ( { const updatedBlockers = watch("blocked_list").filter((i) => i !== issue); submitChanges({ blocked_list: updatedBlockers, }); }} > {`${activeProject?.identifier}-${ issues?.results.find((i) => i.id === issue)?.sequence_id }`} )) : null}
setQuery("")} appear >
{issuesList.length > 0 && ( <>
  • {query === "" && (

    Select blocked issues

    )}
      {issuesList.map((issue) => { if (!watch("blocked_list").includes(issue.id)) { return ( classNames( "flex items-center justify-between cursor-pointer select-none rounded-md px-3 py-2", active ? "bg-gray-900 bg-opacity-5 text-gray-900" : "" ) } > {({ active }) => ( <>
      {activeProject?.identifier}-{issue.sequence_id} {issue.name}
      )}
      ); } })}
  • )}
    {query !== "" && issuesList.length === 0 && (
    )}
    ); }; export default SelectBlocked;