1
1
import { Button } from '@mui/material' ;
2
2
import Autocomplete from '@mui/material/Autocomplete' ;
3
3
import CircularProgress from '@mui/material/CircularProgress' ;
4
- import React , { useState } from 'react' ;
4
+ import React , { useState } from 'react' ;
5
+ import { useDebounce } from 'use-debounce' ;
5
6
import { Avatar , Box , Chip , Grid , TextField , Typography } from '../../base' ;
6
7
import { PersonIcon } from '../../icons/Person' ;
7
8
import { useTheme } from '../../theme' ;
8
- import { useDebounce } from 'use-debounce' ;
9
9
10
10
interface User {
11
11
id : string ;
@@ -22,7 +22,8 @@ interface UserSearchFieldProps {
22
22
usersData : User [ ] ;
23
23
disabled ?: boolean ;
24
24
shareWithNewUsers : ( newUsers : User [ ] ) => Promise < { error : string } > ;
25
- useGetAllUsersQuery : any
25
+ /* eslint-disable @typescript-eslint/no-explicit-any */
26
+ useGetAllUsersQuery : any ;
26
27
}
27
28
28
29
const UserShareSearch : React . FC < UserSearchFieldProps > = ( {
@@ -36,22 +37,23 @@ const UserShareSearch: React.FC<UserSearchFieldProps> = ({
36
37
const [ usersToShareWith , setUsersToShareWith ] = useState < User [ ] > ( [ ] ) ;
37
38
const [ isSharing , setIsSharing ] = useState ( false ) ;
38
39
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
+ ) ;
47
50
48
- const suggestions = usersMatchingSearch ?. data ?? [ ] as User [ ]
51
+ const suggestions = usersMatchingSearch ?. data ?? ( [ ] as User [ ] ) ;
49
52
50
53
// const open = inputValue.trim().length > 0 && suggestions?.length > 0
51
54
52
-
53
55
const handleShareWithNewUsers = async ( ) => {
54
- console . log ( " users to share with" , usersToShareWith )
56
+ console . log ( ' users to share with' , usersToShareWith ) ;
55
57
try {
56
58
setIsSharing ( true ) ;
57
59
const result = await shareWithNewUsers ( usersToShareWith ) ;
@@ -85,11 +87,9 @@ const UserShareSearch: React.FC<UserSearchFieldProps> = ({
85
87
} ;
86
88
87
89
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 )
89
91
) ;
90
92
91
-
92
-
93
93
const isShareDisabled = disabled || isSharing || usersToShareWith . length === 0 ;
94
94
95
95
const UserChip = ( { avatarObj, ...props } : { avatarObj : User } ) => (
@@ -130,7 +130,13 @@ const UserShareSearch: React.FC<UserSearchFieldProps> = ({
130
130
loading = { searchUserLoading }
131
131
value = { usersToShareWith }
132
132
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
+ }
134
140
onChange = { handleAdd }
135
141
onInputChange = { handleInputChange }
136
142
isOptionEqualToValue = { ( option , value ) => option . email === value . email }
0 commit comments