Skip to content

Commit

Permalink
Merge pull request #705 from ita-social-projects/#704-AuthorizationRe…
Browse files Browse the repository at this point in the history
…placeErrorComponentWithToastMessages

#704 [Authorization] Replace error component with toast messages
  • Loading branch information
Lvyshnevska authored Jul 26, 2024
2 parents 5a1dcb1 + 6ca86d7 commit 62d45db
Show file tree
Hide file tree
Showing 5 changed files with 9 additions and 93 deletions.
33 changes: 0 additions & 33 deletions FrontEnd/src/components/authorization/AlertMessage.jsx

This file was deleted.

41 changes: 0 additions & 41 deletions FrontEnd/src/components/authorization/AlertMessage.module.css

This file was deleted.

6 changes: 1 addition & 5 deletions FrontEnd/src/components/authorization/AuthorizationPage.jsx
Original file line number Diff line number Diff line change
@@ -1,18 +1,14 @@
import { useState } from 'react';
import Login from '../authorization/Login';
import AlertMessage from '../authorization/AlertMessage';
import classes from './AuthorizationPage.module.css';
import dots_decor from './dots_decor.svg';

const AuthorizationPage = () => {
const [errorText, setErrorText] = useState('');

return (
<div className={classes['auth-page']}>
{errorText && <AlertMessage errorMessage={errorText} setErrorMessage={setErrorText} />}
<img className={classes['frame-img-left']} src={dots_decor} alt="frame" />
<img className={classes['frame-img-right']} src={dots_decor} alt="frame" />
<Login setErrorMessage={setErrorText} />
<Login />
</div>
);
};
Expand Down
4 changes: 2 additions & 2 deletions FrontEnd/src/components/authorization/Login.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ import LoginPage from './LoginPage';
import SignUpInvitation from './SignUpInvitation';
import classes from './Login.module.css';

const Login = (props) => {
const Login = () => {
return <div className={classes.login}>
<LoginPage setErrorMessage={props.setErrorMessage} />
<LoginPage />
<SignUpInvitation />
</div>;
};
Expand Down
18 changes: 6 additions & 12 deletions FrontEnd/src/components/authorization/LoginPage.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { useState, useEffect } from 'react';
import { useNavigate, Link } from 'react-router-dom';
import axios from 'axios';
import { useStopwatch } from 'react-timer-hook';
import { toast } from 'react-toastify';

import validator from 'validator';
import EyeVisible from './EyeVisible';
Expand All @@ -11,7 +12,7 @@ import classes from './LoginPage.module.css';
import { useAuth } from '../../hooks/';
import checkIfStaff from '../adminPage/checkIfStaff';

const LoginContent = (props) => {
const LoginContent = () => {
const { login } = useAuth();
const navigate = useNavigate();
const [showPassword, setShowPassword] = useState(false);
Expand Down Expand Up @@ -42,19 +43,13 @@ const LoginContent = (props) => {
mode: 'all',
});

const { setErrorMessage } = props;

useEffect(() => {
let errorMessage = '';

if (errors.email?.message && errors.password?.message) {
if (errors.email.message === errors.password.message) {
errorMessage = errors.email.message;
} else {
errorMessage = `${errors.email?.message || ''}\n${
errors.password?.message || ''
}`;
}
errorMessage = errors.email.message === errors.password.message
? errors.email.message
: `${errors.email?.message || ''}\n${errors.password?.message || ''}`;
} else if (errors.email?.message) {
errorMessage = errors.email.message;
} else if (errors.password?.message) {
Expand All @@ -65,13 +60,12 @@ const LoginContent = (props) => {
errorMessage = errors.rateError.message;
}

setErrorMessage(errorMessage);
errorMessage && toast.error(errorMessage);
}, [
errors.email?.message,
errors.password?.message,
errors.unspecifiedError?.message,
errors.rateError?.message,
setErrorMessage,
]);

useEffect(() => {
Expand Down

0 comments on commit 62d45db

Please sign in to comment.