|
@@ -1,10 +1,26 @@
|
|
|
import { Formik, Form } from 'formik'
|
|
|
-import * as Yup from 'yup'
|
|
|
import { Mutation } from 'react-apollo'
|
|
|
import { adopt } from 'react-adopt'
|
|
|
|
|
|
-import { TextInput } from '../lib/forms'
|
|
|
-import { USER_SIGNUP, CURRENT_USER } from '../lib/graphql'
|
|
|
+import { useFormValidation } from '../../lib/forms'
|
|
|
+import { USER_SIGNUP, CURRENT_USER } from './graphql'
|
|
|
+import { signupValidation } from './validation'
|
|
|
+
|
|
|
+const initialValues = {
|
|
|
+ name: 'Tomi',
|
|
|
+ email: 'tomi@cvetic.ch',
|
|
|
+ password: '1234',
|
|
|
+ passwordAgain: '1234'
|
|
|
+}
|
|
|
+
|
|
|
+async function onSubmit(values, mutation) {
|
|
|
+ try {
|
|
|
+ const user = await mutation({ variables: values })
|
|
|
+ console.log(user)
|
|
|
+ } catch (error) {
|
|
|
+ console.log(error)
|
|
|
+ }
|
|
|
+}
|
|
|
|
|
|
const SignupAdoption = adopt({
|
|
|
mutation: ({ render }) => (
|
|
@@ -16,32 +32,9 @@ const SignupAdoption = adopt({
|
|
|
),
|
|
|
form: ({ mutation, render }) => (
|
|
|
<Formik
|
|
|
- initialValues={{
|
|
|
- name: 'Tomi',
|
|
|
- email: 'tomi@cvetic.ch',
|
|
|
- password: '1234',
|
|
|
- passwordAgain: '1234'
|
|
|
- }}
|
|
|
- validationSchema={Yup.object({
|
|
|
- name: Yup.string()
|
|
|
- .required('Required')
|
|
|
- .max(40, 'Must be 40 characters or less'),
|
|
|
- email: Yup.string()
|
|
|
- .email('Invalid email address')
|
|
|
- .required('Required'),
|
|
|
- password: Yup.string()
|
|
|
- .min(4, 'Must have at least 8 characters'),
|
|
|
- passwordAgain: Yup.string()
|
|
|
- .oneOf([Yup.ref('password'), null], 'Passwords must match')
|
|
|
- })}
|
|
|
- onSubmit={async values => {
|
|
|
- try {
|
|
|
- const user = await mutation({ variables: values })
|
|
|
- console.log(user)
|
|
|
- } catch (error) {
|
|
|
- console.log(error)
|
|
|
- }
|
|
|
- }}
|
|
|
+ initialValues={initialValues}
|
|
|
+ validationSchema={validationSchema}
|
|
|
+ onSubmit={values => onSubmit(values, mutation)}
|
|
|
>
|
|
|
{render}
|
|
|
</Formik>
|
|
@@ -50,7 +43,7 @@ const SignupAdoption = adopt({
|
|
|
|
|
|
const SignupForm = props => (
|
|
|
<SignupAdoption>
|
|
|
- {({ form, mutation }) => (
|
|
|
+ {({ form, mutation: { signup, data, error, loading } }) => (
|
|
|
<Form>
|
|
|
<TextInput
|
|
|
label='Name'
|
|
@@ -76,7 +69,8 @@ const SignupForm = props => (
|
|
|
type='password'
|
|
|
placeholder='1234'
|
|
|
/>
|
|
|
- <button type='submit'>Sign Up!</button>
|
|
|
+ <button type='reset' disabled={loading}>Sign Up!</button>
|
|
|
+ <button type='submit' disabled={loading}>Sign Up!</button>
|
|
|
|
|
|
<style jsx>
|
|
|
{`
|