generated from goitacademy/react-homework-template
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
171919e
commit 38322a3
Showing
4 changed files
with
29 additions
and
51 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,33 +1,28 @@ | ||
import { LoginForm } from 'components/LoginForm/LoginForm'; | ||
import toast from 'react-hot-toast'; | ||
import { useSelector } from 'react-redux'; | ||
import { selectAuthIsLoading, selectAuthError } from 'redux/auth/selectors'; | ||
import { useState, useEffect } from 'react'; | ||
import { selectAuthError } from 'redux/auth/selectors'; | ||
import { useDispatch } from 'react-redux'; | ||
import { logIn } from 'redux/auth/operations'; | ||
|
||
export default function Login() { | ||
const isLoading = useSelector(selectAuthIsLoading); | ||
const dispatch = useDispatch(); | ||
const status = useSelector(selectAuthError); | ||
const [isRequestPending, setRequestPending] = useState(true); | ||
|
||
useEffect(() => { | ||
setRequestPending(false); | ||
|
||
if ( | ||
status === 'Request failed with status code 400' && | ||
!isRequestPending && | ||
!isLoading | ||
) { | ||
const onRegister = data => { | ||
if (status === 'Request failed with status code 400') { | ||
toast.error( | ||
'You have entered an incorrect email address or password, or you have not yet registered!' | ||
); | ||
} | ||
}, [isRequestPending, status, isLoading]); | ||
dispatch(logIn(data)); | ||
}; | ||
|
||
return ( | ||
<div> | ||
<title>Login</title> | ||
|
||
<LoginForm /> | ||
<LoginForm onData={onRegister} /> | ||
</div> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,33 +1,28 @@ | ||
import { RegisterForm } from 'components/RegisterForm/RegisterForm'; | ||
import toast from 'react-hot-toast'; | ||
import { useSelector } from 'react-redux'; | ||
import { selectAuthIsLoading, selectAuthError } from 'redux/auth/selectors'; | ||
import { useState, useEffect } from 'react'; | ||
import { selectAuthError } from 'redux/auth/selectors'; | ||
import { useDispatch } from 'react-redux'; | ||
import { register } from 'redux/auth/operations'; | ||
|
||
export default function Register() { | ||
const isLoading = useSelector(selectAuthIsLoading); | ||
const dispatch = useDispatch(); | ||
const status = useSelector(selectAuthError); | ||
const [isRequestPending, setRequestPending] = useState(true); | ||
|
||
useEffect(() => { | ||
setRequestPending(false); | ||
|
||
if ( | ||
status === 'Request failed with status code 400' && | ||
!isRequestPending && | ||
!isLoading | ||
) { | ||
const onRegister = data => { | ||
if (status === 'Request failed with status code 400') { | ||
toast.success( | ||
'You or someone else is already registered with such data!' | ||
); | ||
} | ||
}, [isRequestPending, status, isLoading]); | ||
dispatch(register(data)); | ||
}; | ||
|
||
return ( | ||
<div> | ||
<title>Registration</title> | ||
|
||
<RegisterForm /> | ||
<RegisterForm onData={onRegister} /> | ||
</div> | ||
); | ||
} |