blob: d7f71cf6c37c348f9f054c32ab013de743db8768 [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
16 this.controller = new AbortController()
17 }
18
19 componentDidMount() {
20 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;