1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
|
import React, { Component } from 'react';
import { graphql, compose } from 'react-apollo';
import { REQUEST_RESET_MUTATION } from '../queries';
class ResetRequest extends Component {
state = {
email: `wesbos@gmail.com`,
password: 'abc123',
errors: [],
};
requestReset = async e => {
e.preventDefault();
console.log(this.state.email);
const res = await this.props.requestReset({
variables: {
email: this.state.email,
},
});
if (res.errors) {
this.setState({ errors: res.errors });
}
console.log(res);
// // 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 (
<div>
{this.state.loading ? 'LOADING...' : 'Ready!'}
{this.state.errors ? this.state.errors.map(err => <p>{err.message}</p>) : null}
<h2>Request a Reset</h2>
<form onSubmit={this.requestReset}>
<label htmlFor="email">
Email
<input value={this.state.email} onChange={this.saveToState} name="email" type="text" placeholder="email" />
</label>
<button type="submit">Request Reset!</button>
</form>
</div>
);
}
}
// When we submit this mutation, we need to update our store - we have a few ways to do that:
// One - we can go nucular and run refetchQueries() which will just go get everything - this is easy, but at the cost of efficiency.
const requestResetEnhancer = graphql(REQUEST_RESET_MUTATION, { name: 'requestReset' });
export default compose(requestResetEnhancer)(ResetRequest);
|