Can create admin accounts

This commit is contained in:
Pierre HUBERT 2021-05-15 10:05:56 +02:00
parent c5b78f518b
commit 54c9b84945
2 changed files with 37 additions and 1 deletions

View File

@ -97,6 +97,16 @@ export class AccountHelper {
return await serverRequest("accounts/list");
}
/**
* Create a new administrator
*/
static async CreateAdmin(name: string, email: string) {
await serverRequest("accounts/create", {
name: name,
mail: email,
});
}
/**
* Attempt to refresh current account information
*/

View File

@ -21,6 +21,7 @@ import { Link } from "react-router-dom";
import { AccountHelper, AdminAccount } from "../../helpers/AccountHelper";
import { canManageAdmins } from "../../utils/AccountUtils";
import { AsyncWidget } from "../widgets/AsyncWidget";
import { input, matAlert, snackbar } from "../widgets/DialogsProvider";
import { PageTitle } from "../widgets/PageTitle";
import { TimestampWidget } from "../widgets/TimestampWidget";
@ -37,6 +38,7 @@ export class AccountsListRoute extends React.Component<
};
this.load = this.load.bind(this);
this.createAccount = this.createAccount.bind(this);
this.build = this.build.bind(this);
}
@ -56,6 +58,30 @@ export class AccountsListRoute extends React.Component<
);
}
async createAccount() {
try {
const name = await input({
label: "Administrator name",
minLength: 5,
title: "New administrator",
});
const email = await input({
label: "Administrator email",
minLength: 5,
title: "New administrator",
});
await AccountHelper.CreateAdmin(name, email);
snackbar("Account successfully created!");
this.setState({ version: this.state.version + 1 });
} catch (e) {
console.error(e);
matAlert("Failed to create admin account!");
}
}
build() {
return (
<div>
@ -63,7 +89,7 @@ export class AccountsListRoute extends React.Component<
name="Administrators list"
actions={
canManageAdmins() ? (
<IconButton>
<IconButton onClick={this.createAccount}>
<AddIcon />
</IconButton>
) : (