import React, { Component } from 'react'; import { Link, Redirect } from 'react-router-dom'; import { apiGet, apiPost } from '../apiHelpers'; import ErrorBox from '../components/error-box'; import InfoBox from '../components/info-box'; import SupporterLogos from '../components/supporter-logos'; import { User } from '../models/user'; interface SignUpProps { login: (user: User) => void; user: User; } interface SignUpState { username: string; email: string; confirm_email: string; show_password: boolean; password: string; confirm_conditions: boolean; error: string; } class SignUp extends Component { constructor(props) { super(props); this.state = { username: '', email: '', confirm_email: '', password: '', show_password: false, confirm_conditions: false, error: undefined }; this.handleChange = this.handleChange.bind(this); this.handleSubmit = this.handleSubmit.bind(this); } handleChange(event) { const target = event.target; const value = target.type === 'checkbox' ? target.checked : target.value; const name: keyof SignUpState = target.name; this.setState({ [name]: value } as Pick); } async handleSubmit(event) { event.preventDefault(); this.setState({error: undefined}); try { const res = await apiPost('/api/users', this.state); if(res.error) { this.setState({ error: res.error }); } else { const user = await apiGet('/api/users/me'); this.props.login(user); } } catch(err) { this.setState({error: err}); } } render() { if (this.props.user) { return ; } return (

Sign up


Please discuss suggestions for improvements and report issues or problems.

Create an account to start colouring in.

Do you already have an account?
Log in

); } } export default SignUp;