@@ -6,11 +6,7 @@ import Error from './ErrorMessage';
66import { CURRENT_USER_QUERY } from './User' ;
77
88const SIGNUP_MUTATION = gql `
9- mutation SIGNUP_MUTATION(
10- $email: String!
11- $name: String!
12- $password: String!
13- ) {
9+ mutation SIGNUP_MUTATION($email: String!, $name: String!, $password: String!) {
1410 signup(email: $email, name: $name, password: $password) {
1511 id
1612 email
@@ -19,11 +15,11 @@ const SIGNUP_MUTATION = gql`
1915 }
2016` ;
2117
22- export default class Signup extends Component {
18+ class Signup extends Component {
2319 state = {
2420 name : '' ,
2521 email : '' ,
26- password : ''
22+ password : '' ,
2723 } ;
2824 saveToState = e => {
2925 this . setState ( { [ e . target . name ] : e . target . value } ) ;
@@ -35,61 +31,57 @@ export default class Signup extends Component {
3531 variables = { this . state }
3632 refetchQueries = { [ { query : CURRENT_USER_QUERY } ] }
3733 >
38- { ( signup , { error, loading } ) => {
39- return (
40- // form elements are get by default, change to post
41- < Form
42- method = "post"
43- onSubmit = { async e => {
44- e . preventDefault ( ) ;
45- //capture result and if okay clear form.
46- e . preventDefault ( ) ;
47- const res = await signup ( ) ;
48- this . setState ( { name : '' , email : '' , password : '' } ) ;
49- } }
50- >
51- { /* disable the form and show a loading indicator while things are
52- happening */ }
53- < fieldset disabled = { loading } aria-busy = { loading } >
54- < h2 > Sign Up for an Account </ h2 >
55- < Error error = { error } />
56- < label htmlFor = "email" >
57- Email
58- < input
59- type = "text"
60- type = "email"
61- name = "email"
62- placeholder = "email"
63- value = { this . state . email }
64- onChange = { this . saveToState }
65- />
66- </ label >
67- < label htmlFor = "name" >
68- Name
69- < input
70- type = "text"
71- name = "name"
72- placeholder = "name"
73- value = { this . state . name }
74- onChange = { this . saveToState }
75- />
76- </ label >
77- < label htmlFor = "password" >
78- Password
79- < input
80- type = "password"
81- name = "password"
82- placeholder = "password"
83- value = { this . state . password }
84- onChange = { this . saveToState }
85- />
86- </ label >
87- < button type = "submit" > Sign up</ button >
88- </ fieldset >
89- </ Form >
90- ) ;
91- } }
34+ { ( signup , { error, loading } ) => (
35+ < Form
36+ method = "post"
37+ onSubmit = { async e => {
38+ e . preventDefault ( ) ;
39+ await signup ( ) ;
40+ this . setState ( { name : '' , email : '' , password : '' } ) ;
41+ } }
42+ >
43+ < fieldset disabled = { loading } aria-busy = { loading } >
44+ < h2 > Sign Up for An Account</ h2 >
45+ < Error error = { error } />
46+ < label htmlFor = "email" >
47+ Email
48+ < input
49+ type = "email"
50+ name = "email"
51+ placeholder = "email"
52+ value = { this . state . email }
53+ onChange = { this . saveToState }
54+ />
55+ </ label >
56+ < label htmlFor = "name" >
57+ Name
58+ < input
59+ type = "text"
60+ name = "name"
61+ placeholder = "name"
62+ value = { this . state . name }
63+ onChange = { this . saveToState }
64+ />
65+ </ label >
66+ < label htmlFor = "password" >
67+ Password
68+ < input
69+ type = "password"
70+ name = "password"
71+ placeholder = "password"
72+ value = { this . state . password }
73+ onChange = { this . saveToState }
74+ />
75+ </ label >
76+
77+ < button type = "submit" > Sign Up!</ button >
78+ </ fieldset >
79+ </ Form >
80+ ) }
9281 </ Mutation >
9382 ) ;
9483 }
9584}
85+
86+ export default Signup ;
87+ export { SIGNUP_MUTATION } ;
0 commit comments