summaryrefslogtreecommitdiffstats
path: root/frontend/components/Signin.js
diff options
context:
space:
mode:
Diffstat (limited to 'frontend/components/Signin.js')
-rw-r--r--frontend/components/Signin.js83
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>
);
}
}