add error

This commit is contained in:
2025-12-11 12:14:17 -03:00
parent 2edc7a353f
commit f728b23d3a
5 changed files with 97 additions and 33 deletions

View File

@@ -1,8 +1,7 @@
import { useRequest, useToggle } from 'ahooks'
import { debounce } from 'lodash'
import { CheckIcon, UserIcon } from 'lucide-react'
import { initials, cn } from '@repo/ui/lib/utils'
import { formatCPF } from '@brazilian-utils/brazilian-utils'
import { Avatar, AvatarFallback } from '@repo/ui/components/ui/avatar'
import { Abbr } from '@repo/ui/components/abbr'
import {
@@ -10,7 +9,7 @@ import {
InputGroupAddon,
InputGroupInput
} from '@repo/ui/components/ui/input-group'
import { initials, cn } from '@repo/ui/lib/utils'
import {
Popover,
PopoverContent,
@@ -31,19 +30,25 @@ interface AsyncComboboxProps {
title: string
onChange: (props: any) => void
onSearch: (search: string) => Promise<any[]>
error?: any
}
export function AsyncCombobox({
title,
value,
onSearch,
onChange
onChange,
error
}: AsyncComboboxProps) {
const [open, { set }] = useToggle()
const {
data = [],
loading,
runAsync
} = useRequest(onSearch, { manual: true, defaultParams: [''] })
} = useRequest(onSearch, {
manual: true,
debounceWait: 300,
defaultParams: ['']
})
return (
<Popover open={open} onOpenChange={set}>
@@ -55,6 +60,7 @@ export function AsyncCombobox({
placeholder={title}
className="cursor-pointer"
autoComplete="off"
aria-invalid={!!error}
/>
<InputGroupAddon>
<UserIcon />
@@ -73,11 +79,12 @@ export function AsyncCombobox({
<CommandInput
placeholder={title}
autoComplete="off"
onValueChange={debounce(runAsync, 300)}
onValueChange={runAsync}
/>
<CommandList>
<CommandEmpty>Nenhum resultado encontrado.</CommandEmpty>
<CommandGroup>
{data.map(({ id, name, email, cpf }) => (
<CommandItem