mirror of
https://gitlab.com/comunic/comunicconsole
synced 2024-11-23 13:59:23 +00:00
Can create admin accounts
This commit is contained in:
parent
c5b78f518b
commit
54c9b84945
@ -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
|
||||
*/
|
||||
|
@ -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>
|
||||
) : (
|
||||
|
Loading…
Reference in New Issue
Block a user