SignupForm.tsx 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. import { SyntheticEvent } from 'react'
  2. import { useMutation } from '@apollo/react-hooks'
  3. import { useFormHandler, TextInput } from '../form/forms'
  4. import { USER_SIGNUP } from './graphql'
  5. import { userValidation } from './validation'
  6. const initialValues = {
  7. name: 'Tomi Cvetic',
  8. email: 'tomislav.cvetic@u-blox.com',
  9. password: '1234',
  10. passwordAgain: '1234'
  11. }
  12. const SignupForm = () => {
  13. const { inputProps, values } = useFormHandler(initialValues)
  14. const [userSignup, { loading, error }] = useMutation(USER_SIGNUP)
  15. return (
  16. <form onSubmit={async (event: SyntheticEvent) => {
  17. event.preventDefault()
  18. try {
  19. const data = await userSignup({ variables: values })
  20. } catch (error) {
  21. console.log(error)
  22. }
  23. }}>
  24. <TextInput label='Name' {...inputProps('name')} />
  25. <TextInput label='Email' {...inputProps('email')} />
  26. <TextInput label='Password' {...inputProps('password')} />
  27. <TextInput label='Repeat password' {...inputProps('passwordAgain')} />
  28. <button type='reset' disabled={loading}>Reset</button>
  29. <button type='submit' disabled={loading}>Sign Up!</button>
  30. <style jsx>
  31. {`
  32. select, input {
  33. color: rgba(0,0,127,1);
  34. }
  35. .error {
  36. font-size: 12px;
  37. color: rgba(127,0,0,1);
  38. width: 400px;
  39. margin-top: 0.25rem;
  40. }
  41. .error:before {
  42. content: "❌ ";
  43. font-size: 10px;
  44. }
  45. label {
  46. color: red;
  47. margin-top: 1rem;
  48. }
  49. `}
  50. </style>
  51. </form>
  52. )
  53. }
  54. export default SignupForm