blob: 8ac85df473a98ec7b1d47d1b27b99a88700721cf [file] [log] [blame]
simond47ef9e2022-09-28 22:24:28 -04001import Header from '../components/Header';
2import AccountPreferences from '../components/AccountPreferences';
3import Container from '@mui/material/Container';
4import CircularProgress from '@mui/material/CircularProgress';
5import authManager from '../AuthManager';
6import Account from '../../../model/Account';
Adrien Béraud4e287b92021-04-24 16:15:56 -04007
8const ServerOverview = (props) => {
simond47ef9e2022-09-28 22:24:28 -04009 this.accountId = props.accountId || props.match.params.accountId;
Adrien Béraud4e287b92021-04-24 16:15:56 -040010
Adrien Béraudab519ff2022-05-03 15:34:48 -040011 useEffect(() => {
simond47ef9e2022-09-28 22:24:28 -040012 const controller = new AbortController();
13 authManager
14 .fetch(`/api/serverConfig`, { signal: controller.signal })
15 .then((res) => res.json())
16 .then((result) => {
17 console.log(result);
18 setState({ loaded: true, account: Account.from(result) });
19 })
20 .catch((e) => console.log(e));
21 // return () => controller.abort() // crash on React18
22 }, [accountId]);
Adrien Béraudab519ff2022-05-03 15:34:48 -040023
Adrien Béraud4e287b92021-04-24 16:15:56 -040024 return (
simond47ef9e2022-09-28 22:24:28 -040025 <Container maxWidth="sm" className="app">
Adrien Béraud4e287b92021-04-24 16:15:56 -040026 <Header />
27 {this.state.loaded ? <AccountPreferences account={this.state.account} /> : <CircularProgress />}
28 </Container>
simond47ef9e2022-09-28 22:24:28 -040029 );
30};
Adrien Béraud4e287b92021-04-24 16:15:56 -040031
simond47ef9e2022-09-28 22:24:28 -040032export default ServerOverview;