import type { Serialized } from '@rocket.chat/core-typings'; import { PaginatedSelectFiltered } from '@rocket.chat/fuselage'; import { useDebouncedValue } from '@rocket.chat/fuselage-hooks'; import type { ILivechatContactWithManagerData } from '@rocket.chat/rest-typings'; import type { ComponentProps, ReactNode, SyntheticEvent } from 'react'; import { memo, useState } from 'react'; import { useTranslation } from 'react-i18next'; import { useContactsList } from './useContactsList'; type OptionProps = { role: 'option'; title?: string; index: number; label: string; value: string; selected: boolean; focus: boolean; onMouseDown(event: SyntheticEvent): void; }; export type AutoCompleteContactProps = Omit< ComponentProps, 'filter' | 'setFilter' | 'options' | 'endReached' | 'renderItem' | 'value' | 'onChange' > & { value: string; onChange: (value: string) => void; renderItem?: (props: OptionProps, contact: Serialized) => ReactNode; }; const AutoCompleteContact = ({ value, placeholder, disabled, renderItem, onChange, ...props }: AutoCompleteContactProps) => { const { t } = useTranslation(); const [contactsFilter, setContactFilter] = useState(''); const debouncedContactFilter = useDebouncedValue(contactsFilter, 500); const { data: contactsItems = [], fetchNextPage, isPending, } = useContactsList({ filter: debouncedContactFilter, }); return ( void} options={contactsItems} onChange={onChange} endReached={() => fetchNextPage()} renderItem={renderItem ? (props: OptionProps) => renderItem(props, contactsItems[props.index]) : undefined} /> ); }; export default memo(AutoCompleteContact);