From b0d25a9ad3cc1df2fcc11ddb84e4603b94520b09 Mon Sep 17 00:00:00 2001 From: Wes Bos Date: Mon, 10 Sep 2018 14:29:32 -0400 Subject: almost done --- stepped-solutions/64/frontend/components/Signup.js | 87 ++++++++++++++++++++++ stepped-solutions/64/frontend/components/User.js | 41 ++++++++++ 2 files changed, 128 insertions(+) create mode 100755 stepped-solutions/64/frontend/components/Signup.js create mode 100755 stepped-solutions/64/frontend/components/User.js (limited to 'stepped-solutions/64/frontend/components') diff --git a/stepped-solutions/64/frontend/components/Signup.js b/stepped-solutions/64/frontend/components/Signup.js new file mode 100755 index 0000000..e2f1a3f --- /dev/null +++ b/stepped-solutions/64/frontend/components/Signup.js @@ -0,0 +1,87 @@ +import React, { Component } from 'react'; +import { Mutation } from 'react-apollo'; +import gql from 'graphql-tag'; +import Form from './styles/Form'; +import Error from './ErrorMessage'; +import { CURRENT_USER_QUERY } from './User'; + +const SIGNUP_MUTATION = gql` + mutation SIGNUP_MUTATION($email: String!, $name: String!, $password: String!) { + signup(email: $email, name: $name, password: $password) { + id + email + name + } + } +`; + +class Signup extends Component { + state = { + name: '', + email: '', + password: '', + }; + saveToState = e => { + this.setState({ [e.target.name]: e.target.value }); + }; + render() { + return ( + + {(signup, { error, loading }) => ( +
{ + e.preventDefault(); + await signup(); + this.setState({ name: '', email: '', password: '' }); + }} + > +
+

Sign Up for An Account

+ + + + + + +
+
+ )} +
+ ); + } +} + +export default Signup; +export { SIGNUP_MUTATION }; diff --git a/stepped-solutions/64/frontend/components/User.js b/stepped-solutions/64/frontend/components/User.js new file mode 100755 index 0000000..6f8a4fb --- /dev/null +++ b/stepped-solutions/64/frontend/components/User.js @@ -0,0 +1,41 @@ +import { Query } from 'react-apollo'; +import gql from 'graphql-tag'; +import PropTypes from 'prop-types'; + +const CURRENT_USER_QUERY = gql` + query { + me { + id + email + name + permissions + orders { + id + } + cart { + id + quantity + item { + id + price + image + title + description + } + } + } + } +`; + +const User = props => ( + + {payload => props.children(payload)} + +); + +User.propTypes = { + children: PropTypes.func.isRequired, +}; + +export default User; +export { CURRENT_USER_QUERY }; -- cgit v1.3