import React, { useState } from "react"; import { useRouter } from "next/router"; import useSWR from "swr"; // services import stateService from "services/state.service"; // headless ui import { Squares2X2Icon, PlusIcon, MagnifyingGlassIcon, CheckIcon, } from "@heroicons/react/24/outline"; // icons import { Combobox, Transition } from "@headlessui/react"; // helpers import { getStatesList } from "helpers/state.helper"; // fetch keys import { STATE_LIST } from "constants/fetch-keys"; type Props = { setIsOpen: React.Dispatch>; value: string; onChange: (value: string) => void; projectId: string; }; export const IssueStateSelect: React.FC = ({ setIsOpen, value, onChange, projectId }) => { // states const [query, setQuery] = useState(""); const router = useRouter(); const { workspaceSlug } = router.query; const { data: stateGroups } = useSWR( workspaceSlug && projectId ? STATE_LIST(projectId) : null, workspaceSlug && projectId ? () => stateService.getStates(workspaceSlug as string, projectId) : null ); const states = getStatesList(stateGroups ?? {}); const options = states?.map((state) => ({ value: state.id, display: state.name, color: state.color, })); const filteredOptions = query === "" ? options : options?.filter((option) => option.display.toLowerCase().includes(query.toLowerCase())); return ( onChange(val)} className="relative flex-shrink-0" > {({ open }: any) => ( <> `flex items-center text-xs cursor-pointer border rounded-md shadow-sm duration-300 ${ open ? "outline-none border-[#3F76FF] bg-[rgba(63,118,255,0.05)] ring-1 ring-[#3F76FF] " : "hover:bg-[rgba(63,118,255,0.05)] focus:bg-[rgba(63,118,255,0.05)]" }` } > {value && value !== "" ? ( option.value === value)?.color, }} /> {options?.find((option) => option.value === value)?.display} ) : ( {options?.find((option) => option.value === value)?.display || "State"} )}
setQuery(event.target.value)} placeholder="Search States" displayValue={(assigned: any) => assigned?.name} />
{filteredOptions ? ( filteredOptions.length > 0 ? ( filteredOptions.map((option) => ( `${ active ? "bg-[#E9ECEF]" : "" } group flex min-w-[14rem] cursor-pointer select-none items-center gap-2 truncate rounded px-1 py-1.5 text-[#495057]` } value={option.value} > {({ selected, active }) => states && (
{option.display}
) }
)) ) : (

No states found

) ) : (

Loading...

)}
)}
); };