Newer
Older
import { SubmitHandler, useForm } from 'react-hook-form';
import { Button } from '@material-ui/core';
import { InputField } from 'components/AuthUser/InputField/InputField';
const { control, errors, setError, handleSubmit } = useForm<FormData>({
const onSubmit: SubmitHandler<FormData> = (values: FormData) => {
axios
.post(
'/api/web/login',
{
username: values.email,
password: values.password,
{
headers: {
'Content-Type': 'application/json',
},
},
)
.then((response) => {
if (response.data.status === 'fail') {
setError('email', {
type: 'server',
message: 'Something went wrong with email',
});
setError('password', {
type: 'server',
message: 'Something went wrong with password',
});
} else if (response.data.status === 'success') {
history.replace(AuthRoutes.dashboard);
}
<>
<form
className={classes.form}
onSubmit={handleSubmit(onSubmit)}
data-testid="Form"
validate: (value: string) =>
/^[A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,}$/i.test(value),
required: {
value: true,
error={!!errors.email}
control={control}
rules={{
minLength: 8,
maxLength: 60,
type="submit"
fullWidth
variant="contained"
color="primary"
className={classes.submit}
>
Sign In
</Button>
</form>
</>