11import type { IRoom } from '@rocket.chat/core-typings' ;
2- import { AutoComplete , Option , Box } from '@rocket.chat/fuselage' ;
2+ import { Option , Box } from '@rocket.chat/fuselage' ;
3+ import { AutoComplete , type AutoCompleteProps } from '@rocket.chat/fuselage' ;
34import { useDebouncedValue } from '@rocket.chat/fuselage-hooks' ;
45import { RoomAvatar } from '@rocket.chat/ui-avatar' ;
56import { useEndpoint } from '@rocket.chat/ui-contexts' ;
67import { keepPreviousData , useQuery } from '@tanstack/react-query' ;
7- import type { ComponentProps , ReactElement } from 'react' ;
8- import { memo , useMemo , useState } from 'react' ;
8+ import type { ReactElement } from 'react' ;
9+ import { forwardRef , memo , useMemo , useState } from 'react' ;
10+
11+ type LabelType = { name : string ; avatarETag ?: string ; type : IRoom [ 't' ] ; encrypted ?: IRoom [ 'encrypted' ] } ;
912
1013const generateQuery = (
1114 term = '' ,
1215) : {
1316 selector : string ;
1417} => ( { selector : JSON . stringify ( { name : term } ) } ) ;
1518
16- type RoomAutoCompleteProps = Omit < ComponentProps < typeof AutoComplete > , 'filter' > & {
19+ type RoomAutoCompleteProps = Omit < AutoCompleteProps < LabelType > , 'filter' > & {
1720 scope ?: 'admin' | 'regular' ;
1821 renderRoomIcon ?: ( props : { encrypted : IRoom [ 'encrypted' ] ; type : IRoom [ 't' ] } ) => ReactElement | null ;
1922 setSelectedRoom ?: ( room : IRoom | undefined ) => void ;
@@ -32,7 +35,10 @@ const ROOM_AUTOCOMPLETE_PARAMS = {
3235 } ,
3336} as const ;
3437
35- const RoomAutoComplete = ( { value, onChange, scope = 'regular' , renderRoomIcon, setSelectedRoom, ...props } : RoomAutoCompleteProps ) => {
38+ const RoomAutoComplete = forwardRef < HTMLInputElement , RoomAutoCompleteProps > ( function RoomAutoComplete (
39+ { value, onChange, scope = 'regular' , renderRoomIcon, setSelectedRoom, ...props } ,
40+ ref ,
41+ ) {
3642 const [ filter , setFilter ] = useState ( '' ) ;
3743 const filterDebounced = useDebouncedValue ( filter , 300 ) ;
3844 const roomsAutoCompleteEndpoint = useEndpoint ( 'GET' , ROOM_AUTOCOMPLETE_PARAMS [ scope ] . endpoint ) ;
@@ -57,6 +63,7 @@ const RoomAutoComplete = ({ value, onChange, scope = 'regular', renderRoomIcon,
5763 return (
5864 < AutoComplete
5965 { ...props }
66+ ref = { ref }
6067 value = { value }
6168 onChange = { ( val ) => {
6269 onChange ( val ) ;
@@ -76,7 +83,7 @@ const RoomAutoComplete = ({ value, onChange, scope = 'regular', renderRoomIcon,
7683 < Box margin = 'none' mi = { 2 } >
7784 { label ?. name }
7885 </ Box >
79- { renderRoomIcon ?.( { ... label } ) }
86+ { renderRoomIcon ?.( { encrypted : label ?. encrypted , type : label ?. type } ) }
8087 </ >
8188 ) }
8289 renderItem = { ( { value, label, ...props } ) => (
@@ -85,7 +92,7 @@ const RoomAutoComplete = ({ value, onChange, scope = 'regular', renderRoomIcon,
8592 label = {
8693 < >
8794 { label ?. name }
88- { renderRoomIcon ?.( { ... label } ) }
95+ { renderRoomIcon ?.( { encrypted : label ?. encrypted , type : label ?. type } ) }
8996 </ >
9097 }
9198 avatar = { < RoomAvatar size = { AVATAR_SIZE } room = { { _id : value , ...label } } /> }
@@ -94,6 +101,6 @@ const RoomAutoComplete = ({ value, onChange, scope = 'regular', renderRoomIcon,
94101 options = { options }
95102 />
96103 ) ;
97- } ;
104+ } ) ;
98105
99106export default memo ( RoomAutoComplete ) ;
0 commit comments