@@ -79,6 +79,7 @@ const UserEdit = (props: any) => {
79
79
const [ formUser , setFormUser ] = useState ( { } as FormUser ) ;
80
80
const [ form ] = Form . useForm ( ) ;
81
81
const [ isAdmin , setIsAdmin ] = useState ( false ) ;
82
+ const [ isOwner , setIsOwner ] = useState ( false ) ;
82
83
83
84
const [ confirmModal , confirmModalContextHolder ] = Modal . useModal ( ) ;
84
85
@@ -94,15 +95,21 @@ const UserEdit = (props: any) => {
94
95
} ;
95
96
96
97
const createUserToSave = ( values : any ) : UserToSave => {
97
- const autoGroups =
98
- groups
99
- ?. filter ( ( g ) => values . autoGroupsNames . includes ( g . id ) )
100
- . map ( ( g ) => g . id || "" ) || [ ] ;
98
+ let autoGroups :string [ ] = [ ]
99
+ if ( values . autoGroupsNames ) {
100
+ autoGroups =
101
+ groups
102
+ ?. filter ( ( g ) => values . autoGroupsNames . includes ( g . id ) )
103
+ . map ( ( g ) => g . id || "" ) || [ ] ;
104
+ }
101
105
// find groups that do not yet exist (newly added by the user)
102
106
const allGroupsNames : string [ ] = groups ?. map ( ( g ) => g . id || "" ) ;
103
- const groupsToCreate = values . autoGroupsNames . filter (
104
- ( s : string ) => ! allGroupsNames . includes ( s )
105
- ) ;
107
+ let groupsToCreate :string [ ] = [ ]
108
+ if ( values . autoGroupsNames ) {
109
+ groupsToCreate = values . autoGroupsNames . filter (
110
+ ( s : string ) => ! allGroupsNames . includes ( s )
111
+ ) ;
112
+ }
106
113
let userID = user ? user . id : "" ;
107
114
let isServiceUser = user ? user ?. is_service_user : false ;
108
115
return {
@@ -120,7 +127,8 @@ const UserEdit = (props: any) => {
120
127
if ( users ) {
121
128
let currentUser = users . find ( ( user ) => user ?. is_current ) ;
122
129
if ( currentUser ) {
123
- setIsAdmin ( currentUser . role === "admin" ) ;
130
+ setIsAdmin ( currentUser . role === "admin" || currentUser . role === "owner" ) ;
131
+ setIsOwner ( currentUser . role === "owner" ) ;
124
132
}
125
133
}
126
134
} , [ users ] ) ;
@@ -403,14 +411,19 @@ const UserEdit = (props: any) => {
403
411
>
404
412
< Select
405
413
style = { { width : "100%" } }
406
- disabled = { user ?. is_current }
414
+ disabled = { user ?. is_current || user ?. role === "owner" }
407
415
>
408
416
< Option value = "admin" >
409
417
< Text type = { "secondary" } > admin</ Text >
410
418
</ Option >
411
419
< Option value = "user" >
412
420
< Text type = { "secondary" } > user</ Text >
413
421
</ Option >
422
+ { ! user ?. is_service_user && isOwner && (
423
+ < Option value = "owner" >
424
+ < Text type = { "secondary" } > owner</ Text >
425
+ </ Option >
426
+ ) }
414
427
</ Select >
415
428
</ Form . Item >
416
429
</ Col >
@@ -473,7 +486,7 @@ const UserEdit = (props: any) => {
473
486
label = "Block user"
474
487
style = { { marginRight : "50px" , fontWeight : "500" } }
475
488
>
476
- < Switch />
489
+ < Switch disabled = { user ?. role == "owner" } />
477
490
</ Form . Item >
478
491
</ Col >
479
492
) }
0 commit comments