import React, { Component } from 'react'; import { Link, Redirect } from 'react-router-dom'; import PropTypes from 'prop-types'; import ErrorBox from './error-box'; class MyAccountPage extends Component { constructor(props) { super(props); this.state = { error: undefined }; this.handleLogout = this.handleLogout.bind(this); this.handleGenerateKey = this.handleGenerateKey.bind(this); } handleLogout(event) { event.preventDefault(); this.setState({error: undefined}); fetch('/logout', { method: 'POST', credentials: 'same-origin' }).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}) ); } handleGenerateKey(event) { event.preventDefault(); this.setState({error: undefined}); fetch('/api/key', { method: 'POST', credentials: 'same-origin' }).then( res => res.json() ).then(function(res){ if (res.error) { this.setState({error: res.error}) } else { this.props.updateUser(res); } }.bind(this)).catch( (err) => this.setState({error: err}) ); } render() { if (this.props.user && !this.props.user.error) { return (

Welcome, {this.props.user.username}!

Colouring London is under active development, Please discuss suggestions for improvements and report issues or problems.

Start colouring

My Details

Username

{this.props.user.username}

Email Address

{this.props.user.email? this.props.user.email : '-'}

Registered

{this.props.user.registered.toString()}


Techical details

Are you a software developer? If so, you might be interested in these.

API key

{this.props.user.api_key? this.props.user.api_key : '-'}

GitHub

Colouring London Github repository
); } else { return ( ) } } } MyAccountPage.propTypes = { user: PropTypes.shape({ username: PropTypes.string, email: PropTypes.string, registered: PropTypes.string, api_key: PropTypes.string, error: PropTypes.object }), updateUser: PropTypes.func, logout: PropTypes.func } export default MyAccountPage;