Skip to content
Snippets Groups Projects
Verified Commit c5bafc5a authored by Defendi Alberto's avatar Defendi Alberto
Browse files

Fix validation

parent d32a6a45
No related branches found
No related tags found
2 merge requests!18Api login,!13Basic form api and implement cookie entrypoint
Pipeline #11651 failed
import React, { FC } from 'react'; import React, { FC } from 'react';
import axios from 'axios';
import { useForm, Controller, appendErrors } from 'react-hook-form'; import { useForm, Controller, appendErrors } from 'react-hook-form';
import { useIntl } from 'react-intl'; import { useIntl } from 'react-intl';
import { createStyles, makeStyles, Theme } from '@material-ui/core/styles'; import { createStyles, makeStyles, Theme } from '@material-ui/core/styles';
...@@ -40,7 +41,17 @@ export const SignInForm: FC = () => { ...@@ -40,7 +41,17 @@ export const SignInForm: FC = () => {
}); });
const onSubmit: any = (values: FormData) => { const onSubmit: any = (values: FormData) => {
alert(JSON.stringify(values)); axios
.post('/api/web/login', {
values,
token: sessionStorage.getItem('CSRF_TOKEN'),
})
.then((response) => {
console.log(response);
})
.catch((error) => {
console.log(error);
});
}; };
const intl = useIntl(); const intl = useIntl();
const classes = useStyles(); const classes = useStyles();
...@@ -55,6 +66,14 @@ export const SignInForm: FC = () => { ...@@ -55,6 +66,14 @@ export const SignInForm: FC = () => {
name="email" name="email"
control={control} control={control}
defaultValues defaultValues
rules={{
validate: (value) =>
/^[A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,}$/i.test(value),
required: {
value: true,
message: intl.formatMessage({ id: 'email' }),
},
}}
render={({ onChange, value }) => ( render={({ onChange, value }) => (
<InputField <InputField
id="email" id="email"
...@@ -70,6 +89,11 @@ export const SignInForm: FC = () => { ...@@ -70,6 +89,11 @@ export const SignInForm: FC = () => {
<Controller <Controller
name="password" name="password"
control={control} control={control}
rules={{
minLength: 8,
maxLength: 60,
required: { value: true, message: 'You must enter your name' },
}}
render={({ onChange, value }) => ( render={({ onChange, value }) => (
<InputField <InputField
id="password" id="password"
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment