1
1
import Box from "@material-ui/core/Box"
2
+ import { makeStyles } from "@material-ui/core/styles"
2
3
import Table from "@material-ui/core/Table"
3
4
import TableBody from "@material-ui/core/TableBody"
4
5
import TableCell from "@material-ui/core/TableCell"
5
6
import TableHead from "@material-ui/core/TableHead"
6
7
import TableRow from "@material-ui/core/TableRow"
7
8
import { FC } from "react"
8
9
import * as TypesGen from "../../api/typesGenerated"
10
+ import { combineClasses } from "../../util/combineClasses"
9
11
import { AvatarData } from "../AvatarData/AvatarData"
10
12
import { EmptyState } from "../EmptyState/EmptyState"
11
13
import { RoleSelect } from "../RoleSelect/RoleSelect"
@@ -45,6 +47,8 @@ export const UsersTable: FC<UsersTableProps> = ({
45
47
canEditUsers,
46
48
isLoading,
47
49
} ) => {
50
+ const styles = useStyles ( )
51
+
48
52
return (
49
53
< Table >
50
54
< TableHead >
@@ -60,55 +64,73 @@ export const UsersTable: FC<UsersTableProps> = ({
60
64
{ isLoading && < TableLoader /> }
61
65
{ ! isLoading &&
62
66
users &&
63
- users . map ( ( u ) => (
64
- < TableRow key = { u . id } >
65
- < TableCell >
66
- < AvatarData title = { u . username } subtitle = { u . email } />
67
- </ TableCell >
68
- < TableCell > { u . status } </ TableCell >
69
- < TableCell >
70
- { canEditUsers ? (
71
- < RoleSelect
72
- roles = { roles ?? [ ] }
73
- selectedRoles = { u . roles }
74
- loading = { isUpdatingUserRoles }
75
- onChange = { ( roles ) => onUpdateUserRoles ( u , roles ) }
76
- />
77
- ) : (
78
- < > { u . roles . map ( ( r ) => r . display_name ) . join ( ", " ) } </ >
79
- ) }
80
- </ TableCell >
81
- { canEditUsers && (
67
+ users . map ( ( user ) => {
68
+ // When the user has no role, it is because they are a member
69
+ const fallbackRoles : TypesGen . Role [ ] = [
70
+ {
71
+ name : "member" ,
72
+ display_name : "Member" ,
73
+ } ,
74
+ ]
75
+ const userRoles = user . roles . length === 0 ? fallbackRoles : user . roles
76
+
77
+ return (
78
+ < TableRow key = { user . id } >
79
+ < TableCell >
80
+ < AvatarData title = { user . username } subtitle = { user . email } />
81
+ </ TableCell >
82
+ < TableCell
83
+ className = { combineClasses ( [
84
+ styles . status ,
85
+ user . status === "suspended" ? styles . suspended : undefined ,
86
+ ] ) }
87
+ >
88
+ { user . status }
89
+ </ TableCell >
82
90
< TableCell >
83
- < TableRowMenu
84
- data = { u }
85
- menuItems = {
86
- // Return either suspend or activate depending on status
87
- ( u . status === "active"
88
- ? [
89
- {
90
- label : Language . suspendMenuItem ,
91
- onClick : onSuspendUser ,
92
- } ,
93
- ]
94
- : [
95
- // TODO: Uncomment this and add activate user functionality.
96
- // {
97
- // label: Language.activateMenuItem,
98
- // // eslint-disable-next-line @typescript-eslint/no-empty-function
99
- // onClick: function () {},
100
- // },
101
- ]
102
- ) . concat ( {
103
- label : Language . resetPasswordMenuItem ,
104
- onClick : onResetUserPassword ,
105
- } )
106
- }
107
- />
91
+ { canEditUsers ? (
92
+ < RoleSelect
93
+ roles = { roles ?? [ ] }
94
+ selectedRoles = { userRoles }
95
+ loading = { isUpdatingUserRoles }
96
+ onChange = { ( roles ) => onUpdateUserRoles ( user , roles ) }
97
+ />
98
+ ) : (
99
+ < > { userRoles . map ( ( role ) => role . display_name ) . join ( ", " ) } </ >
100
+ ) }
108
101
</ TableCell >
109
- ) }
110
- </ TableRow >
111
- ) ) }
102
+ { canEditUsers && (
103
+ < TableCell >
104
+ < TableRowMenu
105
+ data = { user }
106
+ menuItems = {
107
+ // Return either suspend or activate depending on status
108
+ ( user . status === "active"
109
+ ? [
110
+ {
111
+ label : Language . suspendMenuItem ,
112
+ onClick : onSuspendUser ,
113
+ } ,
114
+ ]
115
+ : [
116
+ // TODO: Uncomment this and add activate user functionality.
117
+ // {
118
+ // label: Language.activateMenuItem,
119
+ // // eslint-disable-next-line @typescript-eslint/no-empty-function
120
+ // onClick: function () {},
121
+ // },
122
+ ]
123
+ ) . concat ( {
124
+ label : Language . resetPasswordMenuItem ,
125
+ onClick : onResetUserPassword ,
126
+ } )
127
+ }
128
+ />
129
+ </ TableCell >
130
+ ) }
131
+ </ TableRow >
132
+ )
133
+ } ) }
112
134
113
135
{ users && users . length === 0 && (
114
136
< TableRow >
@@ -123,3 +145,12 @@ export const UsersTable: FC<UsersTableProps> = ({
123
145
</ Table >
124
146
)
125
147
}
148
+
149
+ const useStyles = makeStyles ( ( theme ) => ( {
150
+ status : {
151
+ textTransform : "capitalize" ,
152
+ } ,
153
+ suspended : {
154
+ color : theme . palette . text . secondary ,
155
+ } ,
156
+ } ) )
0 commit comments