diff --git a/src/ui/routes/AccountSettingsRoute.tsx b/src/ui/routes/AccountSettingsRoute.tsx
index c9299e4..8b5d4d8 100644
--- a/src/ui/routes/AccountSettingsRoute.tsx
+++ b/src/ui/routes/AccountSettingsRoute.tsx
@@ -6,6 +6,8 @@
import React from "react";
import { useParams } from "react-router-dom";
+import { AccountHelper, AdminAccount } from "../../helpers/AccountHelper";
+import { AsyncWidget } from "../widgets/AsyncWidget";
export function AccountSettingsRoute() {
let params: any = useParams();
@@ -17,7 +19,9 @@ interface SettingsRouteProps {
id: number;
}
-interface SettingsRouteState {}
+interface SettingsRouteState {
+ account: AdminAccount;
+}
class AccountSettingsRouteInner extends React.Component<
SettingsRouteProps,
@@ -26,10 +30,28 @@ class AccountSettingsRouteInner extends React.Component<
constructor(props: any) {
super(props);
- this.state = {};
+ 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
"hello {this.props.id}
;
+ return (
+
+ );
+ }
+
+ build() {
+ return {this.state.account.email}
;
}
}
diff --git a/src/ui/widgets/AsyncWidget.tsx b/src/ui/widgets/AsyncWidget.tsx
index 43411a9..9a6f251 100644
--- a/src/ui/widgets/AsyncWidget.tsx
+++ b/src/ui/widgets/AsyncWidget.tsx
@@ -1,6 +1,6 @@
/**
* Asynchronous loading widget
- *
+ *
* @author Pierre Hubert
*/
@@ -9,73 +9,85 @@ import React, { ReactNode } from "react";
import { CenterCircularProgress } from "./CenterCircularProgress";
enum Status {
- LOADING,
- ERROR,
- SUCCESS
+ LOADING,
+ ERROR,
+ SUCCESS,
}
export interface AsyncWidgetProperties {
- load: () => Promise,
- errorMessage: string,
- onBuild: () => ReactNode
+ key?: number;
+ load: () => Promise;
+ errorMessage: string;
+ onBuild: () => ReactNode;
}
interface AsyncWidgetState {
- status: Status,
+ status: Status;
+ key?: number;
}
-export class AsyncWidget extends React.Component {
+export class AsyncWidget extends React.Component<
+ AsyncWidgetProperties,
+ AsyncWidgetState
+> {
+ constructor(props: any) {
+ super(props);
- constructor(props: any) {
- super(props);
+ this.state = {
+ status: Status.LOADING,
+ key: this.props.key,
+ };
- this.state = {
- status: Status.LOADING
- }
+ this.reload = this.reload.bind(this);
+ }
- this.reload = this.reload.bind(this);
- }
+ async reload() {
+ try {
+ this.setState({ status: Status.LOADING });
- async reload() {
- try {
- this.setState({status: Status.LOADING});
+ await this.props.load();
- await this.props.load();
+ this.setState({ status: Status.SUCCESS });
+ } catch (e) {
+ console.error(e);
+ this.setState({ status: Status.ERROR });
+ }
+ }
- this.setState({status: Status.SUCCESS});
- } catch(e) {
- console.error(e);
- this.setState({status: Status.ERROR});
- }
- }
+ componentDidMount() {
+ this.reload();
+ }
- componentDidMount() {
- this.reload()
- }
+ componentDidUpdate() {
+ if (this.state.key != this.props.key) {
+ this.setState({ key: this.props.key });
+ this.reload();
+ }
+ }
- render() {
+ render() {
+ if (this.state.status === Status.ERROR)
+ return (
+
+
+
+ {this.props.errorMessage}
+
+
+
+
+
+ );
- if (this.state.status === Status.ERROR)
- return (
-
-
- {this.props.errorMessage}
-
-
-
-
-
-
-
);
+ if (this.state.status === Status.SUCCESS) return this.props.onBuild();
- if(this.state.status === Status.SUCCESS)
- return this.props.onBuild();
-
- return ()
- }
-}
\ No newline at end of file
+ return ;
+ }
+}