Newer
Older
import { useCookie } from 'hooks/useCookie';
import { AuthRoutes, NonAuthRoutes } from 'api/routes';
import { SubmitHandler, useForm } from 'react-hook-form';
import {
Button,
createMuiTheme,
responsiveFontSizes,
MuiThemeProvider,
Grid,
Typography,
Link,
} from '@material-ui/core';
import { InputField } from 'components/Auth/InputField/InputField';
import { signInFormStyles } from './SignInForm.styles';
import { CredentialsType } from './CredentialsType';
const defaultValues = {
username: '',
password: '',
const { control, errors, setError, handleSubmit } = useForm<CredentialsType>({
const onSubmit: SubmitHandler<CredentialsType> = (
values: CredentialsType,
) => {
{
headers: {
'Content-Type': 'application/json',
},
},
)
.then((response) => {
if (response.data.status === 'fail') {
message: 'Something went wrong with username',
});
setError('password', {
type: 'server',
message: 'Something went wrong with password',
});
} else if (response.data.status === 'role-choice-needed') {
history.replace(`${NonAuthRoutes.auth}${AuthRoutes.choseRole}`);
} else if (response.data.status === 'success') {
history.replace(`${AuthRoutes.dashboard}${AuthRoutes.home}`);
<Grid item container>
<Grid item xs={12} color="primary" className={classes.paddingTop}>
<Typography variant="h1">SIGN IN</Typography>
<form
className={classes.form}
onSubmit={handleSubmit(onSubmit)}
data-testid="Form"
error={!!errors.username}
errorMessage="Insert username"
control={control}
rules={{
minLength: 8,
maxLength: 60,
type="submit"
fullWidth
variant="contained"
color="primary"
className={classes.submit}
>
Sign In
</Button>
<Grid item container>
<Grid item xs={12} color="primary" className={classes.paddingBottom}>
<Typography>
New here?
<Link href={`${NonAuthRoutes.auth}${NonAuthRoutes.signUp}`}>
Create an account.
</Link>
</Typography>