import React, { Component } from 'react'; import { graphql, compose } from 'react-apollo'; import { SIGNUP_MUTATION, CURRENT_USER_QUERY } from '../queries'; import Form from './styles/Form'; class Signup extends Component { state = { email: `wesbos+${Date.now()}@gmail.com`, name: 'Wes Bos', password: 'abc123', error: undefined, }; createUser = async e => { e.preventDefault(); // pull the values from state const { email, name, password } = this.state; // create a mutation // TODO: handle any errors // turn loading on this.setState({ loading: true }); console.log({ name, email, password }); try { const res = await this.props.signup({ // pass in those variables from state variables: { name, email, password }, }); localStorage.setItem('token', res.data.signup.token); // TODO refetch current user query this.props.currentUser.refetch(); } catch (error) { this.setState({ error }); console.dir(error); } this.setState({ loading: false }); }; saveToState = e => { const { name, value } = e.target; this.setState({ [name]: value }); }; render() { return (
{this.state.error.message}
: null}