import React, { Component } from 'react'; import { graphql, compose } from 'react-apollo'; import { SIGNIN_MUTATION, CURRENT_USER_QUERY } from '../queries'; import Form from './styles/Form'; class Signin extends Component { state = { email: `wesbos@gmail.com`, password: 'abc123', errors: [], }; loginUser = async e => { e.preventDefault(); // pull the values from state const { email, password } = this.state; this.setState({ loading: true, errors: [] }); const res = await this.props.signin({ // pass in those variables from state variables: { name, email, password }, }); if (res.errors) { this.setState({ errors: res.errors }); return; } localStorage.setItem('token', res.data.signin.token); // TODO refetch current user query this.props.currentUser.refetch(); this.setState({ loading: false }); }; saveToState = e => { const { name, value } = e.target; this.setState({ [name]: value }); }; render() { return (
{err.message}
) : null}