import React, { Component } from 'react'; import { Redirect, Link } from 'react-router-dom'; import ErrorBox from './error-box'; import InfoBox from './info-box'; import SupporterLogos from './supporter-logos'; class SignUp extends Component { constructor(props) { super(props); this.state = { username: '', email: '', confirm_email: '', password: '', show_password: '', 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 = target.name; this.setState({ [name]: value }); } handleSubmit(event) { event.preventDefault(); this.setState({error: undefined}) fetch('/users', { method: 'POST', body: JSON.stringify(this.state), headers:{ 'Content-Type': 'application/json' }, credentials: 'same-origin' }).then( res => res.json() ).then(function(res){ if (res.error) { this.setState({error: res.error}) } else { fetch('/users/me', { credentials: 'same-origin' }).then( (res) => res.json() ).then( (user) => this.props.login(user) ).catch( (err) => this.setState({error: err}) ) } }.bind(this)).catch( (err) => this.setState({error: err}) ); } render() { if (this.props.user) { return } return (

Sign up

Create an account to start colouring in.

Do you already have an account?
Log in

) } } export default SignUp;