/**
* Account settings route
*
* @author Pierre Hubert
*/
import {
Button,
Divider,
Grid,
Paper,
TextField,
Typography,
} from "@material-ui/core";
import React from "react";
import { useParams } from "react-router-dom";
import { AccountHelper, AdminAccount } from "../../helpers/AccountHelper";
import { AsyncWidget } from "../widgets/AsyncWidget";
import { matAlert, snackbar } from "../widgets/DialogsProvider";
export function AccountSettingsRoute() {
let params: any = useParams();
return ;
}
interface SettingsRouteProps {
id: number;
}
interface SettingsRouteState {
account: AdminAccount;
}
class AccountSettingsRouteInner extends React.Component<
SettingsRouteProps,
SettingsRouteState
> {
constructor(props: any) {
super(props);
this.load = this.load.bind(this);
this.build = this.build.bind(this);
}
async load() {
const account = await AccountHelper.getAdminInfo(this.props.id);
this.setState({ account: account });
}
render() {
return (
);
}
build() {
return (
);
}
}
class GeneralSettings extends React.Component<
{ admin: AdminAccount },
{ newName: string; newEmail: string }
> {
constructor(p: any) {
super(p);
this.state = {
newName: this.props.admin.name,
newEmail: this.props.admin.email,
};
this.changedName = this.changedName.bind(this);
this.changedEmail = this.changedEmail.bind(this);
this.handleSubmit = this.handleSubmit.bind(this);
}
changedName(e: React.ChangeEvent) {
this.setState({ newName: e.target.value });
}
changedEmail(e: React.ChangeEvent) {
this.setState({ newEmail: e.target.value });
}
get isValid(): boolean {
return this.state.newEmail.length > 2 && this.state.newName.length > 2;
}
async handleSubmit() {
try {
if (!this.isValid) return;
await AccountHelper.UpdateGeneralSettings({
id: this.props.admin.id,
name: this.state.newName,
email: this.state.newEmail,
});
snackbar("Successfully updated admin settings!");
} catch (e) {
console.error(e);
matAlert("Failed to update admin settings!");
}
}
render() {
return (
);
}
}
function SettingsSection(p: { title: string; children?: React.ReactNode }) {
return (
General settings
{p.children}
);
}