import React from "react"; import Image from "next/image"; import { useRouter } from "next/router"; import useSWR from "swr"; import { Control, Controller } from "react-hook-form"; // services import workspaceService from "lib/services/workspace.service"; // headless ui import { Listbox, Transition } from "@headlessui/react"; // ui import { Spinner } from "ui"; // icons import { UserGroupIcon, UserIcon } from "@heroicons/react/24/outline"; import User from "public/user.png"; // types import { IModule } from "types"; // constants import { classNames } from "constants/common"; import { WORKSPACE_MEMBERS } from "constants/fetch-keys"; type Props = { control: Control, any>; submitChanges: (formData: Partial) => void; }; const SelectLead: React.FC = ({ control, submitChanges }) => { const router = useRouter(); const { workspaceSlug } = router.query; const { data: people } = useSWR( workspaceSlug ? WORKSPACE_MEMBERS(workspaceSlug as string) : null, workspaceSlug ? () => workspaceService.workspaceMembers(workspaceSlug as string) : null ); return (

Lead

( { submitChanges({ lead: value }); }} className="flex-shrink-0" > {({ open }) => { const person = people?.find((p) => p.member.id === value)?.member; return (
{person && person.avatar && person.avatar !== "" ? (
{person.first_name}
) : (
{person?.first_name && person.first_name !== "" ? person.first_name.charAt(0) : person?.email.charAt(0)}
)} {person?.first_name && person.first_name !== "" ? person?.first_name + " " + person?.last_name : person?.email}
{people ? ( people.length > 0 ? ( people.map((option) => ( `${ active || selected ? "bg-indigo-50" : "" } flex cursor-pointer select-none items-center gap-2 truncate p-2 text-gray-900` } value={option.member.id} > {option.member.avatar && option.member.avatar !== "" ? (
avatar
) : (
{option.member.first_name && option.member.first_name !== "" ? option.member.first_name.charAt(0) : option.member.email.charAt(0)}
)} {option.member.first_name && option.member.first_name !== "" ? option.member.first_name : option.member.email}
)) ) : (
No members found
) ) : ( )}
); }}
)} />
); }; export default SelectLead;