import React, { Component } from 'react';
import { Redirect } from 'react-router';
import ErrorBox from './error-box';
class MyAccountPage extends Component {
constructor(props) {
super(props);
this.state = {
error: undefined
};
this.handleSubmit = this.handleSubmit.bind(this);
}
handleSubmit(event) {
event.preventDefault();
this.setState({error: undefined});
fetch('/logout', {
method: 'POST'
}).then(
res => res.json()
).then(function(res){
if (res.error) {
this.setState({error: res.error})
} else {
this.props.logout();
}
}.bind(this)).catch(
(err) => this.setState({error: err})
);
}
render() {
if (this.props && this.props.user) {
return (
Welcome, {this.props.user.username}
);
} else {
return (
)
}
}
}
export default MyAccountPage;