1
- import React from 'react' ;
2
- import { Title , SimpleGrid , Container } from '@mantine/core' ;
1
+ import React , { useState } from 'react' ;
2
+ import { Title , SimpleGrid , Container , Select , Group , Stack , Text } from '@mantine/core' ;
3
3
import { AuthGuard } from '@ui/components/AuthGuard' ;
4
4
import { useApi } from '@ui/util/api' ;
5
5
import { AppRoles } from '@common/roles' ;
6
6
import UserInvitePanel from './UserInvitePanel' ;
7
7
import GroupMemberManagement from './GroupMemberManagement' ;
8
- import {
9
- EntraActionResponse ,
10
- GroupMemberGetResponse ,
11
- GroupModificationPatchRequest ,
12
- } from '@common/types/iam' ;
8
+ import { EntraActionResponse , GroupMemberGetResponse } from '@common/types/iam' ;
13
9
import { transformCommaSeperatedName } from '@common/utils' ;
14
- import { getRunEnvironmentConfig } from '@ui/config' ;
10
+ import { getRunEnvironmentConfig , KnownGroups } from '@ui/config' ;
11
+
12
+ const userGroupMappings : KnownGroups = {
13
+ Exec : 'Executive Council' ,
14
+ CommChairs : 'Committee Chairs' ,
15
+ StripeLinkCreators : 'Stripe Link Creators' ,
16
+ } ;
15
17
16
18
export const ManageIamPage = ( ) => {
17
19
const api = useApi ( 'core' ) ;
18
- const groupId = getRunEnvironmentConfig ( ) . KnownGroupMappings . Exec ;
20
+ const groupMappings = getRunEnvironmentConfig ( ) . KnownGroupMappings ;
21
+ const groupOptions = Object . entries ( groupMappings ) . map ( ( [ key , value ] ) => ( {
22
+ label : userGroupMappings [ key as keyof KnownGroups ] || key ,
23
+ value : `${ key } _${ value } ` , // to ensure that the same group for multiple roles still renders
24
+ } ) ) ;
25
+
26
+ const [ selectedGroup , setSelectedGroup ] = useState ( groupOptions [ 0 ] ?. value || '' ) ;
19
27
20
28
const handleInviteSubmit = async ( emailList : string [ ] ) => {
21
29
try {
22
30
const response = await api . post ( '/api/v1/iam/inviteUsers' , {
23
31
emails : emailList ,
24
32
} ) ;
25
- return response . data ;
33
+ return response . data as EntraActionResponse ;
26
34
} catch ( error : any ) {
27
35
console . error ( 'Failed to invite users:' , error ) ;
28
36
return {
@@ -35,32 +43,36 @@ export const ManageIamPage = () => {
35
43
}
36
44
} ;
37
45
38
- const getExecMembers = async ( ) => {
46
+ const getGroupMembers = async ( selectedGroup : string ) => {
39
47
try {
40
- const response = await api . get ( `/api/v1/iam/groups/${ groupId } ` ) ;
41
- const responseMapped = response . data
42
- . map ( ( x : any ) => ( {
48
+ const response = await api . get ( `/api/v1/iam/groups/${ selectedGroup . split ( '_' ) [ 1 ] } ` ) ;
49
+ const data = response . data as GroupMemberGetResponse ;
50
+ const responseMapped = data
51
+ . map ( ( x ) => ( {
43
52
...x ,
44
53
name : transformCommaSeperatedName ( x . name ) ,
45
54
} ) )
46
- . sort ( ( x : any , y : any ) => ( x . name > y . name ? 1 : x . name < y . name ? - 1 : 0 ) ) ;
47
- return responseMapped as GroupMemberGetResponse ;
48
- } catch ( error : any ) {
55
+ . sort ( ( a , b ) => ( a . name > b . name ? 1 : a . name < b . name ? - 1 : 0 ) ) ;
56
+ return responseMapped ;
57
+ } catch ( error ) {
49
58
console . error ( 'Failed to get users:' , error ) ;
50
59
return [ ] ;
51
60
}
52
61
} ;
53
62
54
- const updateExecMembers = async ( toAdd : string [ ] , toRemove : string [ ] ) => {
55
- const allMembers = toAdd . concat ( toRemove ) ;
63
+ const updateGroupMembers = async ( toAdd : string [ ] , toRemove : string [ ] ) => {
64
+ const allMembers = [ ... toAdd , ... toRemove ] ;
56
65
try {
57
- const response = await api . patch ( `/api/v1/iam/groups/${ groupId } ` , {
66
+ const response = await api . patch ( `/api/v1/iam/groups/${ selectedGroup . split ( '_' ) [ 1 ] } ` , {
58
67
remove : toRemove ,
59
68
add : toAdd ,
60
- } as GroupModificationPatchRequest ) ;
61
- return response . data as EntraActionResponse ;
62
- } catch ( error : any ) {
63
- console . error ( 'Failed to get users:' , error ) ;
69
+ } ) ;
70
+ return response . data ;
71
+ } catch ( error ) {
72
+ if ( ! ( error instanceof Error ) ) {
73
+ throw error ;
74
+ }
75
+ console . error ( 'Failed to modify group members:' , error ) ;
64
76
return {
65
77
success : [ ] ,
66
78
failure : allMembers . map ( ( email ) => ( {
@@ -82,9 +94,26 @@ export const ManageIamPage = () => {
82
94
resourceDef = { { service : 'core' , validRoles : [ AppRoles . IAM_ADMIN ] } }
83
95
isAppShell = { false }
84
96
>
85
- < GroupMemberManagement fetchMembers = { getExecMembers } updateMembers = { updateExecMembers } />
97
+ < Stack >
98
+ < Text fw = { 500 } mb = { 4 } size = "lg" >
99
+ Group Management
100
+ </ Text >
101
+ < Select
102
+ label = "Select Group"
103
+ data = { groupOptions }
104
+ value = { selectedGroup }
105
+ clearable = { false }
106
+ onChange = { ( value ) => value && setSelectedGroup ( value ) }
107
+ placeholder = "Choose a group to manage"
108
+ />
109
+ < GroupMemberManagement
110
+ fetchMembers = { ( ) => {
111
+ return getGroupMembers ( selectedGroup ) ;
112
+ } }
113
+ updateMembers = { updateGroupMembers }
114
+ />
115
+ </ Stack >
86
116
</ AuthGuard >
87
- { /* For future panels, make sure to add an auth guard if not every IAM role can see it. */ }
88
117
</ SimpleGrid >
89
118
</ AuthGuard >
90
119
) ;
0 commit comments