-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Display Staff list in Admin - part of unmarc/unmarc_project#6
- Loading branch information
Showing
4 changed files
with
95 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,16 @@ | ||
import React from 'react' | ||
|
||
import { wrapLayout } from '../common/components/Layout' | ||
import StaffList from './StaffList' | ||
|
||
|
||
export default function StaffAdmin() { | ||
return wrapLayout( | ||
<div> | ||
<br /> | ||
<h2>Staff</h2> | ||
<br /> | ||
<StaffList /> | ||
</div> | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
import React from 'react' | ||
import gql from 'graphql-tag' | ||
import { useQuery } from '@apollo/react-hooks' | ||
import Table from 'react-bootstrap/Table' | ||
import Badge from 'react-bootstrap/Badge' | ||
|
||
import { AuthContext } from '../auth' | ||
import UhOhErrorAlert from '../common/components/UhOhErrorAlert' | ||
|
||
|
||
const GET_STAFF = gql` | ||
{ | ||
allStaff { | ||
user { | ||
id | ||
username | ||
name | ||
dateJoined | ||
} | ||
isLibraryAdmin | ||
branches { | ||
name | ||
} | ||
} | ||
} | ||
` | ||
|
||
export default function StaffList() { | ||
const { loading, error, data } = useQuery(GET_STAFF) | ||
const { userInfo } = React.useContext(AuthContext) | ||
|
||
if (loading) return <span>Loading...</span> | ||
if (error) return <UhOhErrorAlert /> | ||
|
||
return ( | ||
<Table> | ||
<thead> | ||
<tr> | ||
<th>Username</th> | ||
<th>Name</th> | ||
<th>Email</th> | ||
<th>Access</th> | ||
<th>Branch</th> | ||
<th>Added on</th> | ||
<th>Actions</th> | ||
</tr> | ||
</thead> | ||
<tbody> | ||
{ | ||
data.allStaff.map(staff => ( | ||
<tr key={ staff.user.id }> | ||
<td> | ||
{ staff.user.username } | ||
{ userInfo.username === staff.user.username && <Badge variant="info">You</Badge> } | ||
</td> | ||
<td> | ||
{ staff.user.name } | ||
</td> | ||
<td> | ||
{ staff.user.email || '-' } | ||
</td> | ||
<td> | ||
{ staff.isLibraryAdmin ? 'Administrator' : 'Staff' } | ||
</td> | ||
<td> | ||
{ staff.branches.map(branch => branch.name).join(', ') } | ||
</td> | ||
<td> | ||
{ new Date(staff.user.dateJoined).toDateString().split(' ').slice(1).join(' ') } | ||
</td> | ||
<td>...</td> | ||
</tr> | ||
)) | ||
} | ||
</tbody> | ||
</Table> | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
import React from 'react' | ||
import Alert from 'react-bootstrap/Alert' | ||
|
||
export default function UhOhErrorAlert() { | ||
return <Alert variant="danger">Uh oh! Something didn't quite go as expected.</Alert> | ||
} |