Skip to content
Snippets Groups Projects

is_authenticated, hide password and move styles

Merged Defendi Alberto requested to merge hide_password into master
3 files
+ 34
24
Compare changes
  • Side-by-side
  • Inline
Files
3
import React, { FC } from 'react';
import axios from 'axios';
import { SubmitHandler, useForm } from 'react-hook-form';
import { createStyles, makeStyles, Theme } from '@material-ui/core/styles';
import { Button } from '@material-ui/core';
import { InputField } from 'components/AuthUser/SignInForm/InputField/InputField';
import { useHistory } from 'react-router-dom';
import { AuthRoutes } from 'components/api/routes';
const useStyles = makeStyles((theme: Theme) =>
createStyles({
root: {
'& > *': {
margin: theme.spacing(0),
},
},
form: {
width: '100%', // Fix IE 11 issue.
marginTop: theme.spacing(1),
},
submit: {
margin: theme.spacing(3, 0, 2),
},
}),
);
import { useStyles } from './useStyles';
export const SignInForm: FC = () => {
const history = useHistory();
@@ -37,7 +20,7 @@ export const SignInForm: FC = () => {
password: '',
};
const { control, errors, handleSubmit } = useForm<FormData>({
const { control, errors, setError, handleSubmit } = useForm<FormData>({
defaultValues,
});
@@ -55,8 +38,19 @@ export const SignInForm: FC = () => {
},
},
)
.then(() => {
history.replace(AuthRoutes.dashboard);
.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);
}
});
};
Loading