Display the list of administrators

This commit is contained in:
Pierre HUBERT 2021-05-15 09:37:32 +02:00
parent f38b4d663b
commit b4dc4cd45b
4 changed files with 103 additions and 1 deletions

View File

@ -90,6 +90,13 @@ export class AccountHelper {
}); });
} }
/**
* Get the entire list of administrators
*/
static async GetAdminsList(): Promise<AdminAccount[]> {
return await serverRequest("accounts/list");
}
/** /**
* Attempt to refresh current account information * Attempt to refresh current account information
*/ */

View File

@ -5,7 +5,6 @@
*/ */
import { Grid } from "@material-ui/core"; import { Grid } from "@material-ui/core";
import { version } from "process";
import React from "react"; import React from "react";
import { useParams } from "react-router-dom"; import { useParams } from "react-router-dom";
import { AccountHelper, AdminAccount } from "../../helpers/AccountHelper"; import { AccountHelper, AdminAccount } from "../../helpers/AccountHelper";

View File

@ -0,0 +1,83 @@
/**
* Accounts list route
*
* @author Pierre Hubert
*/
import {
TableContainer,
Paper,
Table,
TableHead,
TableRow,
TableCell,
TableBody,
} from "@material-ui/core";
import React from "react";
import { AccountHelper, AdminAccount } from "../../helpers/AccountHelper";
import { AsyncWidget } from "../widgets/AsyncWidget";
import { TimestampWidget } from "../widgets/TimestampWidget";
export class AccountsListRoute extends React.Component<
{},
{ version: number; list: AdminAccount[] }
> {
constructor(p: any) {
super(p);
this.state = {
version: 1,
list: [],
};
this.load = this.load.bind(this);
this.build = this.build.bind(this);
}
async load() {
const list = await AccountHelper.GetAdminsList();
this.setState({ list: list });
}
render() {
return (
<AsyncWidget
errorMessage="Failed to load the list of adminstrators!"
onBuild={this.build}
key={this.state.version}
load={this.load}
/>
);
}
build() {
return (
<TableContainer component={Paper}>
<Table>
<TableHead>
<TableRow>
<TableCell align="right">ID</TableCell>
<TableCell align="right">Name</TableCell>
<TableCell align="right">Email address</TableCell>
<TableCell align="right">
Account creation
</TableCell>
</TableRow>
</TableHead>
<TableBody>
{this.state.list.map((row) => (
<TableRow key={row.id}>
<TableCell align="right">{row.id}</TableCell>
<TableCell align="right">{row.name}</TableCell>
<TableCell align="right">{row.email}</TableCell>
<TableCell align="right">
<TimestampWidget time={row.time_create} />
</TableCell>
</TableRow>
))}
</TableBody>
</Table>
</TableContainer>
);
}
}

View File

@ -6,6 +6,7 @@
import { import {
AppBar, AppBar,
Divider,
IconButton, IconButton,
List, List,
ListItem, ListItem,
@ -17,6 +18,7 @@ import {
Typography, Typography,
} from "@material-ui/core"; } from "@material-ui/core";
import { Home, Person } from "@material-ui/icons"; import { Home, Person } from "@material-ui/icons";
import GroupIcon from "@material-ui/icons/Group";
import CloseSharpIcon from "@material-ui/icons/CloseSharp"; import CloseSharpIcon from "@material-ui/icons/CloseSharp";
import React from "react"; import React from "react";
import { import {
@ -30,6 +32,7 @@ import { AccountHelper } from "../../helpers/AccountHelper";
import { AccountSettingsRoute } from "./AccountSettingsRoute"; import { AccountSettingsRoute } from "./AccountSettingsRoute";
import { HomeRoute } from "./HomeRoute"; import { HomeRoute } from "./HomeRoute";
import { NotFoundRoute } from "./NotFoundRoute"; import { NotFoundRoute } from "./NotFoundRoute";
import { AccountsListRoute } from "./AccountsListRoute";
const useStyles = makeStyles((theme) => ({ const useStyles = makeStyles((theme) => ({
root: { root: {
@ -85,6 +88,12 @@ function Menu() {
<div> <div>
<List component="nav" aria-label="main mailbox folders"> <List component="nav" aria-label="main mailbox folders">
<MainMenuItem title="Home" icon={<Home />} uri="/" /> <MainMenuItem title="Home" icon={<Home />} uri="/" />
<MainMenuItem
title="Administrators"
icon={<GroupIcon />}
uri="/accounts"
/>
<Divider />
<MainMenuItem <MainMenuItem
title="My account" title="My account"
icon={<Person />} icon={<Person />}
@ -187,6 +196,10 @@ export function MainRoute() {
<HomeRoute></HomeRoute> <HomeRoute></HomeRoute>
</Route> </Route>
<Route exact path="/accounts">
<AccountsListRoute />
</Route>
<Route path="/accounts/:id"> <Route path="/accounts/:id">
<AccountSettingsRoute></AccountSettingsRoute> <AccountSettingsRoute></AccountSettingsRoute>
</Route> </Route>