import type { PropsWithChildren } from "react"; import { useState } from "react"; import classNames from "@calcom/lib/classNames"; import { useBookerUrl } from "@calcom/lib/hooks/useBookerUrl"; import type { RouterOutputs } from "@calcom/trpc"; import { Avatar, TextField } from "@calcom/ui"; type TeamInviteFromOrgProps = PropsWithChildren<{ selectedEmails?: string | string[]; handleOnChecked: (usersEmail: string) => void; orgMembers?: RouterOutputs["viewer"]["organizations"]["getMembers"]; }>; const keysToCheck = ["name", "email", "username"] as const; // array of keys to check export default function TeamInviteFromOrg({ handleOnChecked, selectedEmails, orgMembers, }: TeamInviteFromOrgProps) { const [searchQuery, setSearchQuery] = useState(""); const filteredMembers = orgMembers?.filter((member) => { if (!searchQuery) { return true; // return all members if searchQuery is empty } const { user } = member ?? {}; // destructuring with default value in case member is undefined return keysToCheck.some((key) => user?.[key]?.toLowerCase().includes(searchQuery.toLowerCase())); }); return (
setSearchQuery(e.target.value)} />

<> {filteredMembers && filteredMembers.map((member) => { const isSelected = Array.isArray(selectedEmails) ? selectedEmails.includes(member.user.email) : selectedEmails === member.user.email; return ( handleOnChecked(member.user.email)} /> ); })}
); } function UserToInviteItem({ member, isSelected, onChange, }: { member: RouterOutputs["viewer"]["organizations"]["getMembers"][number]; isSelected: boolean; onChange: () => void; }) { const bookerUrl = useBookerUrl(); return (
onChange()} // We handle this on click on the div also - for a11y we handle it with label and checkbox below className={classNames( "flex cursor-pointer items-center rounded-md px-2 py-1", isSelected ? "bg-emphasis" : "hover:bg-subtle " )}>
{ onChange(); }} />
); }