blob: 56d06a80dc3043e74718052ca9d44e71031f314e [file] [log] [blame]
simon26e79f72022-10-05 22:16:08 -04001/*
2 * Copyright (C) 2022 Savoir-faire Linux Inc.
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU Affero General Public License as
6 * published by the Free Software Foundation; either version 3 of the
7 * License, or (at your option) any later version.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU Affero General Public License for more details.
13 *
14 * You should have received a copy of the GNU Affero General Public
15 * License along with this program. If not, see
16 * <https://www.gnu.org/licenses/>.
17 */
simond47ef9e2022-09-28 22:24:28 -040018import CircularProgress from '@mui/material/CircularProgress';
simon07b4eb02022-09-29 17:50:26 -040019import Container from '@mui/material/Container';
simon20076982022-10-11 15:04:13 -040020import { Account } from 'jami-web-common';
simon80b7b3b2022-09-28 17:50:10 -040021import { useEffect, useState } from 'react';
simonfe1de722022-10-02 00:21:43 -040022import { useParams } from 'react-router-dom';
simon07b4eb02022-09-29 17:50:26 -040023
simon07b4eb02022-09-29 17:50:26 -040024import authManager from '../AuthManager';
25import AccountPreferences from '../components/AccountPreferences';
26import Header from '../components/Header';
Adrien Béraud4e287b92021-04-24 16:15:56 -040027
simonfe1de722022-10-02 00:21:43 -040028type ServerOverviewProps = {
29 accountId?: string;
30};
31
32const ServerOverview = (props: ServerOverviewProps) => {
33 const [account, setAccount] = useState<Account | null>(null);
34 const params = useParams();
35 const accountId = props.accountId || params.accountId;
Adrien Béraud4e287b92021-04-24 16:15:56 -040036
Adrien Béraudab519ff2022-05-03 15:34:48 -040037 useEffect(() => {
simond47ef9e2022-09-28 22:24:28 -040038 const controller = new AbortController();
39 authManager
40 .fetch(`/api/serverConfig`, { signal: controller.signal })
41 .then((res) => res.json())
42 .then((result) => {
43 console.log(result);
simon80b7b3b2022-09-28 17:50:10 -040044 setAccount(Account.from(result));
simond47ef9e2022-09-28 22:24:28 -040045 })
46 .catch((e) => console.log(e));
47 // return () => controller.abort() // crash on React18
48 }, [accountId]);
Adrien Béraudab519ff2022-05-03 15:34:48 -040049
Adrien Béraud4e287b92021-04-24 16:15:56 -040050 return (
simond47ef9e2022-09-28 22:24:28 -040051 <Container maxWidth="sm" className="app">
Adrien Béraud4e287b92021-04-24 16:15:56 -040052 <Header />
simonfe1de722022-10-02 00:21:43 -040053 {account != null ? <AccountPreferences account={account} /> : <CircularProgress />}
Adrien Béraud4e287b92021-04-24 16:15:56 -040054 </Container>
simond47ef9e2022-09-28 22:24:28 -040055 );
56};
Adrien Béraud4e287b92021-04-24 16:15:56 -040057
simond47ef9e2022-09-28 22:24:28 -040058export default ServerOverview;