blob: f69334da47f36eb8e58ccd884cf1dd21d6010a27 [file] [log] [blame]
Michelle Sepkap Simeb3dd3122022-11-03 02:12:39 -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 */
18import { CircularProgress, Container } from '@mui/material';
19import { Account } from 'jami-web-common';
20import { useEffect, useState } from 'react';
21import { useParams } from 'react-router';
22
23import authManager from '../AuthManager';
24import AccountPreferences from '../components/AccountPreferences';
25import Header from '../components/Header';
simon416d0792022-11-03 02:46:18 -040026import { setAccountId } from '../redux/appSlice';
Michelle Sepkap Simeb3dd3122022-11-03 02:12:39 -040027import { useAppDispatch } from '../redux/hooks';
28
29type AccountSettingsProps = {
30 accountId?: string;
31 account?: Account;
32};
33
34const DeprecatedAccountSettings = (props: AccountSettingsProps) => {
35 console.log('ACCOUNT SETTINGS', props.account);
36 const params = useParams();
37 const accountId = props.accountId || params.accountId;
38
39 if (accountId == null) {
40 throw new Error('Missing accountId');
41 }
42
43 const dispatch = useAppDispatch();
44
45 const [localAccount, setLocalAccount] = useState<Account | null>(null);
46
47 useEffect(() => {
48 dispatch(setAccountId(accountId));
49
50 const controller = new AbortController();
51 authManager
52 .fetch(`/api/accounts/${accountId}`, { signal: controller.signal })
53 .then((res) => res.json())
54 .then((result) => {
55 console.log(result);
56 const account = Account.from(result);
57 account.setDevices(result.devices);
Michelle Sepkap Simeb3dd3122022-11-03 02:12:39 -040058 setLocalAccount(account);
59 })
60 .catch((e) => console.log(e));
61 // return () => controller.abort() // crash on React18
62 }, [accountId, dispatch]);
63
64 return (
65 <Container maxWidth="sm">
66 <Header />
67 {localAccount != null ? <AccountPreferences account={localAccount} /> : <CircularProgress />}
68 </Container>
69 );
70};
71
72export default DeprecatedAccountSettings;