import React, { useContext } from "react"; // swr import useSWR from "swr"; // react hook form import { Controller } from "react-hook-form"; // headless ui import { Listbox, Transition } from "@headlessui/react"; // service import projectServices from "lib/services/project.service"; // hooks import useUser from "lib/hooks/useUser"; // fetch keys import { PROJECT_MEMBERS } from "constants/fetch-keys"; // icons import { CheckIcon } from "@heroicons/react/20/solid"; // types import type { Control } from "react-hook-form"; import type { IIssue, WorkspaceMember } from "types"; import { UserIcon } from "@heroicons/react/24/outline"; type Props = { control: Control; }; const SelectAssignee: React.FC = ({ control }) => { const { activeWorkspace, activeProject } = useUser(); const { data: people } = useSWR( activeWorkspace && activeProject ? PROJECT_MEMBERS(activeProject.id) : null, activeWorkspace && activeProject ? () => projectServices.projectMembers(activeWorkspace.slug, activeProject.id) : null ); return ( ( { const valueCopy = [...(value ?? [])]; if (valueCopy.some((i) => i === data)) onChange(valueCopy.filter((i) => i !== data)); else onChange([...valueCopy, data]); }} > {({ open }) => ( <>
{value && value.length > 0 ? value .map( (id) => people ?.find((i) => i.member.id === id) ?.member.email.substring(0, 4) + "..." ) .join(", ") : "Assignees"}
{people?.map((person) => ( `${ active ? "text-white bg-theme" : "text-gray-900" } cursor-pointer select-none relative p-2 rounded-md` } value={person.member.id} > {({ selected, active }) => ( <> i === person.member.id) ? "font-semibold" : "font-normal" } block truncate`} > {person.member.email} {selected ? ( i === person.member.id) ? "text-white" : "text-indigo-600" }`} > ) : null} )} ))}
)}
)} >
); }; export default SelectAssignee;