summaryrefslogtreecommitdiffstats
path: root/frontend/components/ResetRequest.js
blob: 4ed902e1d27a653ebf3f6a7e346729c506e801bc (plain)
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
import React from 'react';
import { Mutation } from 'react-apollo';
import { REQUEST_RESET_MUTATION } from '../queries';
import Form from './styles/Form';
import Error from './ErrorMessage';
import Dump from './Dump';

class ResetRequest extends React.Component {
  state = {
    email: '',
  };

  render() {
    return (
      <Mutation mutation={REQUEST_RESET_MUTATION} variables={this.state}>
        {(resetMutation, { loading, error, called, data }) => (
          <Form
            onSubmit={async e => {
              e.preventDefault();
              const res = await resetMutation();
              console.log(res);
            }}
          >
            <Error error={error} />
            {!error && called && !loading && <p>Success! Check Your Email!</p>}
            <fieldset disabled={loading} aria-busy={loading}>
              <label htmlFor="email">
                Email
                <input
                  value={this.state.email}
                  onChange={e => this.setState({ email: e.target.value })}
                  name="email"
                  type="text"
                  placeholder="email"
                />
              </label>

              <button type="submit">Request Reset!</button>
            </fieldset>
          </Form>
        )}
      </Mutation>
    );
  }
}

export default ResetRequest;