11import { Button } from '@mui/material' ;
22import Autocomplete from '@mui/material/Autocomplete' ;
33import CircularProgress from '@mui/material/CircularProgress' ;
4- import React , { useState } from 'react' ;
4+ import React , { useState } from 'react' ;
5+ import { useDebounce } from 'use-debounce' ;
56import { Avatar , Box , Chip , Grid , TextField , Typography } from '../../base' ;
67import { PersonIcon } from '../../icons/Person' ;
78import { useTheme } from '../../theme' ;
8- import { useDebounce } from 'use-debounce' ;
99
1010interface User {
1111 id : string ;
@@ -22,7 +22,8 @@ interface UserSearchFieldProps {
2222 usersData : User [ ] ;
2323 disabled ?: boolean ;
2424 shareWithNewUsers : ( newUsers : User [ ] ) => Promise < { error : string } > ;
25- useGetAllUsersQuery : any
25+ /* eslint-disable @typescript-eslint/no-explicit-any */
26+ useGetAllUsersQuery : any ;
2627}
2728
2829const UserShareSearch : React . FC < UserSearchFieldProps > = ( {
@@ -36,22 +37,23 @@ const UserShareSearch: React.FC<UserSearchFieldProps> = ({
3637 const [ usersToShareWith , setUsersToShareWith ] = useState < User [ ] > ( [ ] ) ;
3738 const [ isSharing , setIsSharing ] = useState ( false ) ;
3839 const theme = useTheme ( ) ;
39- const [ debouncedInput ] = useDebounce ( inputValue , 300 )
40-
41- const { data :usersMatchingSearch , isLoading :searchUserLoading } = useGetAllUsersQuery ( {
42- search :debouncedInput ,
43- page :0 ,
44- pagesize :10 ,
45- } , { skip : debouncedInput . trim ( ) . length == 0 } )
46-
40+ const [ debouncedInput ] = useDebounce ( inputValue , 300 ) ;
41+
42+ const { data : usersMatchingSearch , isLoading : searchUserLoading } = useGetAllUsersQuery (
43+ {
44+ search : debouncedInput ,
45+ page : 0 ,
46+ pagesize : 10
47+ } ,
48+ { skip : debouncedInput . trim ( ) . length == 0 }
49+ ) ;
4750
48- const suggestions = usersMatchingSearch ?. data ?? [ ] as User [ ]
51+ const suggestions = usersMatchingSearch ?. data ?? ( [ ] as User [ ] ) ;
4952
5053 // const open = inputValue.trim().length > 0 && suggestions?.length > 0
5154
52-
5355 const handleShareWithNewUsers = async ( ) => {
54- console . log ( " users to share with" , usersToShareWith )
56+ console . log ( ' users to share with' , usersToShareWith ) ;
5557 try {
5658 setIsSharing ( true ) ;
5759 const result = await shareWithNewUsers ( usersToShareWith ) ;
@@ -85,11 +87,9 @@ const UserShareSearch: React.FC<UserSearchFieldProps> = ({
8587 } ;
8688
8789 const filteredOptions = suggestions . filter (
88- ( option ) => ! usersToShareWith . concat ( usersData ) . find ( ( u ) => u . email === option . email )
90+ ( option : User ) => ! usersToShareWith . concat ( usersData ) . find ( ( u ) => u . email === option . email )
8991 ) ;
9092
91-
92-
9393 const isShareDisabled = disabled || isSharing || usersToShareWith . length === 0 ;
9494
9595 const UserChip = ( { avatarObj, ...props } : { avatarObj : User } ) => (
@@ -130,7 +130,13 @@ const UserShareSearch: React.FC<UserSearchFieldProps> = ({
130130 loading = { searchUserLoading }
131131 value = { usersToShareWith }
132132 getOptionLabel = { ( user ) => user . email }
133- noOptionsText = { searchUserLoading ? 'Loading...' : ( inputValue == "" ? "Search using name or email" :'No users found' ) }
133+ noOptionsText = {
134+ searchUserLoading
135+ ? 'Loading...'
136+ : inputValue == ''
137+ ? 'Search using name or email'
138+ : 'No users found'
139+ }
134140 onChange = { handleAdd }
135141 onInputChange = { handleInputChange }
136142 isOptionEqualToValue = { ( option , value ) => option . email === value . email }
0 commit comments