diff options
| author | Wes Bos <wesbos@gmail.com> | 2018-05-16 13:53:07 -0400 |
|---|---|---|
| committer | Wes Bos <wesbos@gmail.com> | 2018-05-16 13:53:07 -0400 |
| commit | fceade857ecccad6884fe03a973215bd9df1a1e7 (patch) | |
| tree | 1af26e1116ac4ca54afa35ba932b1d35ec328861 /frontend/components/Signin.js | |
| parent | 7ec0943b5d48eb268d03cfa6321c7d83a0d02883 (diff) | |
simplyfyyyy
Diffstat (limited to 'frontend/components/Signin.js')
| -rw-r--r-- | frontend/components/Signin.js | 83 |
1 files changed, 40 insertions, 43 deletions
diff --git a/frontend/components/Signin.js b/frontend/components/Signin.js index 7a4db8c..23a5835 100644 --- a/frontend/components/Signin.js +++ b/frontend/components/Signin.js @@ -9,14 +9,6 @@ class Signin extends Component { email: `wesbos@gmail.com`, password: 'abc123', }; - - loginUser = async (e, signin, client) => { - e.preventDefault(); - const res = await signin(); - // TODO instead of refetching, can we just use the data returned? - client.query({ query: CURRENT_USER_QUERY, fetchPolicy: 'network-only' }); - }; - saveToState = e => { const { name, value } = e.target; this.setState({ [name]: value }); @@ -24,44 +16,49 @@ class Signin extends Component { render() { return ( - <ApolloConsumer> - {client => ( - <Mutation mutation={SIGNIN_MUTATION} variables={this.state}> - {(signin, { loading, error }) => ( - <Form onSubmit={e => this.loginUser(e, signin, client)}> - <Error error={error} /> - <fieldset disabled={loading} aria-busy={loading}> - <label htmlFor="email"> - Email - <input - value={this.state.email} - onChange={this.saveToState} - name="email" - type="text" - placeholder="email" - /> - </label> + <Mutation + mutation={SIGNIN_MUTATION} + variables={this.state} + refetchQueries={[{ query: CURRENT_USER_QUERY }]} + > + {(signin, { loading, error }) => ( + <Form + onSubmit={e => { + e.preventDefault(); + signin(); + }} + > + <Error error={error} /> + <fieldset disabled={loading} aria-busy={loading}> + <label htmlFor="email"> + Email + <input + value={this.state.email} + onChange={this.saveToState} + name="email" + type="text" + placeholder="email" + /> + </label> - <label htmlFor="password"> - Password - <input - type="password" - name="password" - id="password" - className="password" - placeholder="password" - value={this.state.password} - onChange={this.saveToState} - /> - </label> + <label htmlFor="password"> + Password + <input + type="password" + name="password" + id="password" + className="password" + placeholder="password" + value={this.state.password} + onChange={this.saveToState} + /> + </label> - <button type="submit">Sign In!</button> - </fieldset> - </Form> - )} - </Mutation> + <button type="submit">Sign In!</button> + </fieldset> + </Form> )} - </ApolloConsumer> + </Mutation> ); } } |
