blob: 12fa43ad13fbf26f7b50798b5f9dea6bd3744243 [file] [log] [blame]
Adrien Béraud6ecaa402021-04-06 17:37:25 -04001import React from 'react';
2import Header from '../components/Header'
3import AccountPreferences from '../components/AccountPreferences'
4import Container from '@material-ui/core/Container';
5import CircularProgress from '@material-ui/core/CircularProgress';
6import authManager from '../AuthManager'
7import Account from '../../../model/Account'
8
9class AccountSettings extends React.Component {
10
11 constructor(props) {
12 super(props)
13 this.accountId = props.accountId || props.match.params.accountId
14 this.state = { loaded: false, account: props.account }
15 this.req = undefined
Adrien Béraud6ecaa402021-04-06 17:37:25 -040016 }
17
18 componentDidMount() {
Adrien Béraud35e7d7c2021-04-13 03:28:39 -040019 this.controller = new AbortController()
Adrien Béraud6ecaa402021-04-06 17:37:25 -040020 if (this.req === undefined) {
21 this.req = authManager.fetch(`/api/accounts/${this.accountId}`, {signal: this.controller.signal})
22 .then(res => res.json())
23 .then(result => {
24 console.log(result)
25 this.setState({loaded: true, account: Account.from(result)})
26 })
27 }
28 }
29
30 componentWillUnmount() {
31 this.controller.abort()
32 this.req = undefined
33 }
34
35 render() {
36 return (
37 <Container maxWidth="sm" className="app" >
38 <Header />
39 {this.state.loaded ? <AccountPreferences account={this.state.account} /> : <CircularProgress />}
40 </Container>
41 )
42 }
43}
44
45export default AccountSettings;