import React, { Component } from 'react'; import { Redirect, Link } from 'react-router-dom'; class SignUp extends Component { constructor(props) { super(props); this.state = { username: '', email: '', confirm_email: '', password: '', show_password: '', confirm_conditions: false }; 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(); fetch('/users', { method: 'POST', body: JSON.stringify(this.state), headers:{ 'Content-Type': 'application/json' } }).then( res => res.json() ).then(function(res){ if (res.error) { console.error(res.error); // tell user } else { console.log(res); // redirect back fetch('/users/me').then(function(user){ this.props.login(user); }).catch(function(err){ console.error(err); }) } }).catch( err => console.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;