import React, { Component, FormEvent } from 'react'; import { Link, Redirect } from 'react-router-dom'; import { apiDelete, apiPost } from '../apiHelpers'; import ConfirmationModal from '../components/confirmation-modal'; import ErrorBox from '../components/error-box'; import { User } from '../models/user'; interface MyAccountPageProps { user: User; updateUser: (user: User) => void; logout: () => void; } interface MyAccountPageState { showDeleteConfirm: boolean; error: string; } class MyAccountPage extends Component { constructor(props) { super(props); this.state = { error: undefined, showDeleteConfirm: false }; this.handleLogout = this.handleLogout.bind(this); this.handleGenerateKey = this.handleGenerateKey.bind(this); } handleLogout(event) { event.preventDefault(); this.setState({error: undefined}); apiPost('/api/logout') .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}); apiPost('/api/api/key') .then(res => { if (res.error) { this.setState({error: res.error}); } else { this.props.updateUser(res); } }).catch( (err) => this.setState({error: err}) ); } confirmDelete(event: FormEvent) { event.preventDefault(); this.setState({ showDeleteConfirm: true }); } hideConfirmDelete() { this.setState({ showDeleteConfirm: false }); } async handleDelete() { this.setState({ error: undefined }); try { const data = await apiDelete('/api/users/me'); if(data.error) { this.setState({ error: data.error }); } else { this.props.logout(); } } catch (err) { this.setState({ error: err }); } finally { this.hideConfirmDelete(); } } 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.

For reference, here are the privacy policy, contributor agreement and data accuracy agreement.

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()}


Technical 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 : '-'}

Open Source Code

Colouring London site code is developed at colouring-london on Github

Account actions

this.confirmDelete(e)} className="form-group mb-3" >
this.handleDelete()} onCancel={() => this.hideConfirmDelete()} />
); } else { return ( ); } } } export default MyAccountPage;