aboutsummaryrefslogtreecommitdiff
path: root/vnext/src/ui/Login.js
diff options
context:
space:
mode:
authorGravatar Vitaly Takmazov2022-10-28 00:23:40 +0300
committerGravatar Vitaly Takmazov2023-01-13 10:37:58 +0300
commit9bd48005fda1d94a526e36bec256b56add65b28d (patch)
tree2bffeb7e3ec8b2e8ac6886cffae544771958e333 /vnext/src/ui/Login.js
parent40d411e516efee5531404725b45ab89d97172ce8 (diff)
use `react-hook-form` and fix tests
Diffstat (limited to 'vnext/src/ui/Login.js')
-rw-r--r--vnext/src/ui/Login.js26
1 files changed, 9 insertions, 17 deletions
diff --git a/vnext/src/ui/Login.js b/vnext/src/ui/Login.js
index 774664c0..fc3922c8 100644
--- a/vnext/src/ui/Login.js
+++ b/vnext/src/ui/Login.js
@@ -3,8 +3,7 @@ import { useLocation, useHistory } from 'react-router-dom';
import Icon from './Icon';
import Button from './Button';
-import Input from './Input';
-import { useFormState } from 'react-use-form-state';
+import { useForm } from 'react-hook-form';
import { me, facebookLink, vkLink, appleLink } from '../api';
@@ -33,14 +32,11 @@ function Login({ visitor, onAuth }) {
}
}, [history, location.state, visitor]);
- const [formState, { text, password }] = useFormState();
+ const { register, handleSubmit, formState: { errors }, } = useForm();
- /**
- * @param {React.SyntheticEvent} event
- */
- let onSubmit = (event) => {
- event.preventDefault();
- me(formState.values.username, formState.values.password)
+ /** @type { import('react-hook-form').SubmitHandler<import('react-hook-form').FieldValues> } */
+ let onSubmit = (values) => {
+ me(values.username, values.password)
.then(response => {
onAuth(response);
}
@@ -63,14 +59,10 @@ function Login({ visitor, onAuth }) {
<a href={appleLink()}><img src="https://appleid.cdn-apple.com/appleid/button" /></a>
</div>
<p>Already registered?</p>
- <form onSubmit={onSubmit}>
- <Input name="username"
- placeholder="Username..."
- value={formState.values.username} {...text('username')} /><br />
- <Input name="password"
- placeholder="Password..."
- value={formState.values.password} {...password('password')} /><br />
- <Button onClick={onSubmit}>OK</Button>
+ <form onSubmit={handleSubmit(onSubmit)}>
+ <input placeholder="Username..." {...register('username')} /><br />
+ <input placeholder="Password..." type="password" {...register('password')} /><br />
+ <Button onClick={handleSubmit(onSubmit)}>OK</Button>
</form>
</div>
</div>