import { FC, Fragment } from "react"; import { useRouter } from "next/router"; import useSWR from "swr"; // headless ui import { Listbox, Transition } from "@headlessui/react"; // icons import { ClipboardDocumentListIcon } from "@heroicons/react/24/outline"; // services import projectService from "services/project.service"; // fetch-keys import { PROJECTS_LIST } from "constants/fetch-keys"; export interface IssueProjectSelectProps { value: string; onChange: (value: string) => void; setActiveProject: React.Dispatch>; } export const IssueProjectSelect: FC = ({ value, onChange, setActiveProject, }) => { const router = useRouter(); const { workspaceSlug } = router.query; // Fetching Projects List const { data: projects } = useSWR( workspaceSlug ? PROJECTS_LIST(workspaceSlug as string) : null, () => (workspaceSlug ? projectService.getProjects(workspaceSlug as string) : null) ); return ( <> { onChange(val); setActiveProject(val); }} > {({ open }) => ( <>
{projects?.find((i) => i.id === value)?.identifier ?? "Project"}
{projects ? ( projects.length > 0 ? ( projects.map((project) => ( `${active ? "bg-indigo-50" : ""} ${ selected ? "bg-indigo-50 font-medium" : "" } cursor-pointer select-none p-2 text-gray-900` } value={project.id} > {({ selected }) => ( <> {project.name} )} )) ) : (

No projects found!

) ) : (
Loading...
)}
)}
); };