import { useRequest, useToggle } from 'ahooks' import { CheckIcon, UserIcon, XIcon } from 'lucide-react' import { formatCPF } from '@brazilian-utils/brazilian-utils' import { Avatar, AvatarFallback } from '@repo/ui/components/ui/avatar' import { Abbr } from '@repo/ui/components/abbr' import { InputGroup, InputGroupAddon, InputGroupInput } from '@repo/ui/components/ui/input-group' import { initials, cn } from '@repo/ui/lib/utils' import { Popover, PopoverContent, PopoverTrigger } from '@repo/ui/components/ui/popover' import { Command, CommandEmpty, CommandGroup, CommandInput, CommandItem, CommandList } from '@repo/ui/components/ui/command' import { Spinner } from '@repo/ui/components/ui/spinner' import { Button } from '@repo/ui/components/ui/button' interface AsyncComboboxProps { value: any title: string onChange: (props: any) => void onSearch: (search: string) => Promise error?: any } export function AsyncCombobox({ title, value, onSearch, onChange, error }: AsyncComboboxProps) { const [open, { set }] = useToggle() const { data = [], loading, runAsync } = useRequest(onSearch, { manual: true, debounceWait: 300, defaultParams: [''] }) return ( {value && ( )} {loading && ( )} Nenhum resultado encontrado. {data.map(({ id, name, email, cpf }) => ( { onChange?.({ id, name, email, cpf }) set(false) }} >
{initials(name)}
  • {name}
  • {email}
  • {cpf && (
  • {formatCPF(cpf)}
  • )}
))}
) }