-
Notifications
You must be signed in to change notification settings - Fork 5
/
Users.tsx
85 lines (77 loc) · 2.64 KB
/
Users.tsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
import { ROLES } from 'api/src/lib/constants'
import Button from 'react-bootstrap/Button'
import Table from 'react-bootstrap/Table'
import { useAuth } from 'web/src/auth'
import { Link, routes } from '@redwoodjs/router'
import { timeTag, truncate, formatEnum } from 'src/lib/formatters'
const UsersList = ({ usersByOrganization, updateUser, usersUpdating }) => {
const { hasRole } = useAuth()
const currentUserIsUSDRAdmin = hasRole(ROLES.USDR_ADMIN)
return (
<Table striped bordered>
<thead>
<tr>
<th>Email</th>
<th>Name</th>
<th>Role</th>
<th>Agency</th>
<th>Created at</th>
<th>Actions</th>
</tr>
</thead>
<tbody>
{usersByOrganization.map((user) => {
// Labels
const userName = user.isActive
? user.name
: user.name + ' (Deactivated)'
const deactivateTitle = user.isActive
? 'Deactivate user ' + user.name
: 'Reactivate user ' + user.name
const deactivateLabel = user.isActive ? 'Deactivate' : 'Reactivate'
// Actions
const hasEditAccess =
currentUserIsUSDRAdmin || user.role !== ROLES.USDR_ADMIN
const hasDeactivateAccess =
currentUserIsUSDRAdmin || user.role !== ROLES.USDR_ADMIN
return (
<tr key={user.id}>
<td>{truncate(user.email)}</td>
<td>{truncate(userName)}</td>
<td>{formatEnum(user.role)}</td>
<td>{truncate(user.agency?.name)}</td>
<td>{timeTag(user.createdAt)}</td>
<td>
<div className="d-grid gap-2 d-xxl-block">
{hasEditAccess && (
<Link
to={routes.editUser({ id: user.id })}
className="btn btn-secondary btn-sm me-xxl-2"
title={'Edit user ' + user.id}
>
Edit
</Link>
)}
{hasDeactivateAccess && (
<Button
size="sm"
variant="outline-secondary"
title={deactivateTitle}
onClick={() =>
updateUser({ ...user, isActive: !user.isActive })
}
disabled={usersUpdating.has(user.id)}
>
{deactivateLabel}
</Button>
)}
</div>
</td>
</tr>
)
})}
</tbody>
</Table>
)
}
export default UsersList