LoginForm.tsx 992 B

12345678910111213141516171819202122232425262728293031323334353637
  1. import { FormEvent } from 'react'
  2. import { useUserLoginMutation, CurrentUserDocument } from '../../graphql'
  3. import { useFormHandler, TextInput } from '../form/forms'
  4. const initialValues = {
  5. email: 'tomislav.cvetic@u-blox.com',
  6. password: '1234'
  7. }
  8. const LoginForm = () => {
  9. const [login, { loading, error }] = useUserLoginMutation()
  10. const { inputProps, values } = useFormHandler(initialValues)
  11. return (
  12. <form onSubmit={async (event: FormEvent) => {
  13. event.preventDefault()
  14. try {
  15. const data = await login({
  16. variables: values,
  17. refetchQueries: [{ query: CurrentUserDocument }]
  18. })
  19. console.log('LoginForm', data)
  20. } catch (error) {
  21. console.log('LoginForm', error)
  22. }
  23. }}>
  24. <TextInput label='Email' {...inputProps('email')} />
  25. <TextInput label='Password' {...inputProps('password')} />
  26. <button type='submit' disabled={loading}>Login!</button>
  27. </form>
  28. )
  29. }
  30. export default LoginForm