|
@@ -1,25 +1,41 @@
|
|
|
-import { useUserLoginMutation, CurrentUserDocument } from "../../gql";
|
|
|
-import { TextInput } from "../../form";
|
|
|
-
|
|
|
-const initialValues = {
|
|
|
- email: "tomislav.cvetic@u-blox.com",
|
|
|
- password: "1234"
|
|
|
-};
|
|
|
+import { TextInput, useForm } from '../../form'
|
|
|
+import { useContext } from 'react'
|
|
|
+import { UserContext } from '../hooks'
|
|
|
|
|
|
const LoginForm = () => {
|
|
|
- const [login, { loading, error, data }] = useUserLoginMutation();
|
|
|
- console.log("LoginForm", loading, error, data);
|
|
|
+ const { values, onChange } = useForm({ email: '', password: '' })
|
|
|
+ const { login } = useContext(UserContext)
|
|
|
+
|
|
|
+ if (!login) return <p>Loading context.</p>
|
|
|
+ const [userLogin, { error, loading }] = login
|
|
|
|
|
|
return (
|
|
|
- <form>
|
|
|
- <TextInput label="Email" name="email" type="text" placeholder="Email" />
|
|
|
- <TextInput label="Password" name="password" type="password" />
|
|
|
- <button type="submit" disabled={loading}>
|
|
|
+ <form
|
|
|
+ onSubmit={async ev => {
|
|
|
+ ev.preventDefault()
|
|
|
+ const result = await userLogin({ variables: values })
|
|
|
+ console.log('login', result)
|
|
|
+ }}
|
|
|
+ >
|
|
|
+ <TextInput
|
|
|
+ label='Email'
|
|
|
+ name='email'
|
|
|
+ value={values.email}
|
|
|
+ onChange={onChange}
|
|
|
+ />
|
|
|
+ <TextInput
|
|
|
+ label='Password'
|
|
|
+ name='password'
|
|
|
+ type='password'
|
|
|
+ value={values.password}
|
|
|
+ onChange={onChange}
|
|
|
+ />
|
|
|
+ <button type='submit' disabled={loading}>
|
|
|
Login!
|
|
|
</button>
|
|
|
- {error && <div className="error">{error.message}</div>}
|
|
|
+ {error && <div className='error'>{error.message}</div>}
|
|
|
</form>
|
|
|
- );
|
|
|
-};
|
|
|
+ )
|
|
|
+}
|
|
|
|
|
|
-export default LoginForm;
|
|
|
+export default LoginForm
|