Browse Source

loading toasts

pull/4/head
Nareshkumar Rao 3 years ago
parent
commit
4e3851f1d6
  1. 9
      src/screens/LoginScreen.js
  2. 17
      src/screens/ScannerScreen.js

9
src/screens/LoginScreen.js

@ -17,6 +17,13 @@ function Login() {
if (isAuthenticated) return <Redirect to="/home" />;
const handleTelegramResponse = (response) => {
toast({
title: "Logging you in",
description: "Hold on, we're logging you in.",
status: 'info',
duration: 10000,
isClosable: false
});
axios
.post(
`${process.env.REACT_APP_API_URL}/login`,
@ -37,6 +44,7 @@ function Login() {
history.push('/home');
}
} else {
toast.closeAll();
dispatch(authLogout());
toast({
title: 'An error occurred',
@ -48,6 +56,7 @@ function Login() {
}
})
.catch(err => {
toast.closeAll();
if(err.response){
if(err.response.status === 401){
dispatch(authLogout());

17
src/screens/ScannerScreen.js

@ -30,6 +30,13 @@ function Scanner() {
const re = /verify\/.*$/;
const hash = re.exec(scanData);
if (hash) {
toast({
title: "Checking QR code.",
description: "Hold on, we're checking this QR code.",
status: 'info',
duration: 10000,
isClosable: false
});
axios
.post(
`${process.env.REACT_APP_API_URL}/verify`,
@ -41,6 +48,7 @@ function Scanner() {
.then(res => {
if (res.data.success) {
if (res.data.loggedIn) {
toast.closeAll();
toast({
title: 'Contact Succesfully Logged',
status: 'info',
@ -54,12 +62,21 @@ function Scanner() {
}
})
.catch(e => {
toast.closeAll();
toast({
title: 'Bad Verification',
status: 'error',
duration: 2000,
});
});
}else{
toast.closeAll();
toast({
title: "Bad QR code",
status: 'error',
duration: 3000,
isClosable: true
});
}
}
}, [scanData, dispatch, history, toast]);

Loading…
Cancel
Save