import { useRouter } from "next/router"; import useSWR from "swr"; import { IGithubRepoCollaborator } from "@plane/types"; // services import { Avatar, CustomSelect, CustomSearchSelect, Input } from "@plane/ui"; import { WORKSPACE_MEMBERS } from "@/constants/fetch-keys"; import { WorkspaceService } from "@/services/workspace.service"; // ui // types import { IUserDetails } from "./root"; // fetch-keys type Props = { collaborator: IGithubRepoCollaborator; index: number; users: IUserDetails[]; setUsers: React.Dispatch>; }; const importOptions = [ { key: "map", label: "Map to existing", }, { key: "invite", label: "Invite by email", }, { key: false, label: "Do not import", }, ]; // services const workspaceService = new WorkspaceService(); export const SingleUserSelect: React.FC = ({ collaborator, index, users, setUsers }) => { const router = useRouter(); const { workspaceSlug } = router.query; const { data: members } = useSWR( workspaceSlug ? WORKSPACE_MEMBERS(workspaceSlug.toString()) : null, workspaceSlug ? () => workspaceService.fetchWorkspaceMembers(workspaceSlug.toString()) : null ); const options = members ?.map((member) => { if (!member?.member) return; return { value: member.member?.display_name, query: member.member?.display_name ?? "", content: (
{member.member?.display_name}
), }; }) .filter((member) => !!member) as | { value: string; query: string; content: JSX.Element; }[] | undefined; return (
{`${collaborator.login}

{collaborator.login}

{importOptions.find((o) => o.key === users[index].import)?.label}
} onChange={(val: any) => { const newUsers = [...users]; newUsers[index].import = val; newUsers[index].email = ""; setUsers(newUsers); }} optionsClassName="w-full" noChevron > {importOptions.map((option) => (
{option.label}
))}
{users[index].import === "invite" && ( { const newUsers = [...users]; newUsers[index].email = e.target.value; setUsers(newUsers); }} placeholder="Enter email of the user" className="w-full py-1 text-xs" /> )} {users[index].import === "map" && members && ( { const newUsers = [...users]; newUsers[index].email = val; setUsers(newUsers); }} optionsClassName="w-full" /> )} ); };