From 19c9683e2126c68cb9d231293162c756d69c51fb Mon Sep 17 00:00:00 2001 From: Wes Bos Date: Thu, 8 Feb 2018 10:41:16 -0500 Subject: WIP --- frontend/components/RequestReset.js | 71 +++++++++++++++++++++++++++++++++++++ 1 file changed, 71 insertions(+) create mode 100644 frontend/components/RequestReset.js (limited to 'frontend/components/RequestReset.js') diff --git a/frontend/components/RequestReset.js b/frontend/components/RequestReset.js new file mode 100644 index 0000000..de16751 --- /dev/null +++ b/frontend/components/RequestReset.js @@ -0,0 +1,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 ( +
+ {this.state.loading ? 'LOADING...' : 'Ready!'} + + {this.state.errors ? this.state.errors.map(err =>

{err.message}

) : null} +

Request a Reset

+
+ + + +
+
+ ); + } +} + +// 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); -- cgit v1.3