1
- import CircularProgress from "@material-ui/core/CircularProgress"
2
1
import MenuItem from "@material-ui/core/MenuItem"
3
2
import Select from "@material-ui/core/Select"
4
3
import { makeStyles } from "@material-ui/core/styles"
@@ -8,10 +7,7 @@ import TableCell from "@material-ui/core/TableCell"
8
7
import TableContainer from "@material-ui/core/TableContainer"
9
8
import TableHead from "@material-ui/core/TableHead"
10
9
import TableRow from "@material-ui/core/TableRow"
11
- import TextField from "@material-ui/core/TextField"
12
10
import PersonAdd from "@material-ui/icons/PersonAdd"
13
- import Autocomplete from "@material-ui/lab/Autocomplete"
14
- import { useMachine } from "@xstate/react"
15
11
import { TemplateRole , TemplateUser , User } from "api/typesGenerated"
16
12
import { AvatarData } from "components/AvatarData/AvatarData"
17
13
import { ChooseOne , Cond } from "components/Conditionals/ChooseOne"
@@ -21,25 +17,17 @@ import { LoadingButton } from "components/LoadingButton/LoadingButton"
21
17
import { Stack } from "components/Stack/Stack"
22
18
import { TableLoader } from "components/TableLoader/TableLoader"
23
19
import { TableRowMenu } from "components/TableRowMenu/TableRowMenu"
24
- import debounce from "just-debounce-it"
25
- import { ChangeEvent , FC , useState } from "react"
26
- import { searchUserMachine } from "xServices/users/searchUserXService"
20
+ import { UserAutocomplete } from "components/UserAutocomplete/UserAutocomplete"
21
+ import { FC , useState } from "react"
27
22
28
23
const AddTemplateUser : React . FC < {
29
24
isLoading : boolean
30
25
onSubmit : ( user : User , role : TemplateRole , reset : ( ) => void ) => void
31
26
} > = ( { isLoading, onSubmit } ) => {
32
27
const styles = useStyles ( )
33
- const [ isAutocompleteOpen , setIsAutocompleteOpen ] = useState ( false )
34
- const [ searchState , sendSearch ] = useMachine ( searchUserMachine )
35
- const { searchResults } = searchState . context
36
28
const [ selectedUser , setSelectedUser ] = useState < User | null > ( null )
37
29
const [ selectedRole , setSelectedRole ] = useState < TemplateRole > ( "read" )
38
30
39
- const handleFilterChange = debounce ( ( event : ChangeEvent < HTMLInputElement > ) => {
40
- sendSearch ( "SEARCH" , { query : event . target . value } )
41
- } , 1000 )
42
-
43
31
const resetValues = ( ) => {
44
32
setSelectedUser ( null )
45
33
setSelectedRole ( "read" )
@@ -56,60 +44,11 @@ const AddTemplateUser: React.FC<{
56
44
} }
57
45
>
58
46
< Stack direction = "row" alignItems = "center" spacing = { 1 } >
59
- < Autocomplete
47
+ < UserAutocomplete
60
48
value = { selectedUser }
61
- disabled = { isLoading }
62
- id = "asynchronous-demo"
63
- style = { { width : 300 } }
64
- open = { isAutocompleteOpen }
65
- onOpen = { ( ) => {
66
- setIsAutocompleteOpen ( true )
67
- } }
68
- onClose = { ( ) => {
69
- setIsAutocompleteOpen ( false )
70
- } }
71
- onChange = { ( event , newValue ) => {
49
+ onChange = { ( newValue ) => {
72
50
setSelectedUser ( newValue )
73
51
} }
74
- getOptionSelected = { ( option : User , value : User ) => option . username === value . username }
75
- getOptionLabel = { ( option ) => option . email }
76
- renderOption = { ( option : User ) => (
77
- < AvatarData
78
- title = { option . username }
79
- subtitle = { option . email }
80
- highlightTitle
81
- avatar = {
82
- option . avatar_url ? (
83
- < img
84
- className = { styles . avatar }
85
- alt = { `${ option . username } 's Avatar` }
86
- src = { option . avatar_url }
87
- />
88
- ) : null
89
- }
90
- />
91
- ) }
92
- options = { searchResults }
93
- loading = { searchState . matches ( "searching" ) }
94
- className = { styles . autocomplete }
95
- renderInput = { ( params ) => (
96
- < TextField
97
- { ...params }
98
- margin = "none"
99
- variant = "outlined"
100
- placeholder = "User email or username"
101
- InputProps = { {
102
- ...params . InputProps ,
103
- onChange : handleFilterChange ,
104
- endAdornment : (
105
- < >
106
- { searchState . matches ( "searching" ) ? < CircularProgress size = { 16 } /> : null }
107
- { params . InputProps . endAdornment }
108
- </ >
109
- ) ,
110
- } }
111
- />
112
- ) }
113
52
/>
114
53
115
54
< Select
@@ -273,19 +212,6 @@ export const TemplatePermissionsPageView: FC<
273
212
274
213
export const useStyles = makeStyles ( ( theme ) => {
275
214
return {
276
- autocomplete : {
277
- "& .MuiInputBase-root" : {
278
- width : 300 ,
279
- // Match button small height
280
- height : 36 ,
281
- } ,
282
-
283
- "& input" : {
284
- fontSize : 14 ,
285
- padding : `${ theme . spacing ( 0 , 0.5 , 0 , 0.5 ) } !important` ,
286
- } ,
287
- } ,
288
-
289
215
select : {
290
216
// Match button small height
291
217
height : 36 ,
0 commit comments