From c36c4ef0524400735f4cdb05de5d54f5b7944306 Mon Sep 17 00:00:00 2001 From: Nareshkumar Rao <_accounts@nareshkumarrao.com> Date: Thu, 29 Jul 2021 18:14:04 +0200 Subject: [PATCH 1/3] added logout button --- src/screens/HomeScreen.js | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/src/screens/HomeScreen.js b/src/screens/HomeScreen.js index cafed57..161f1fa 100644 --- a/src/screens/HomeScreen.js +++ b/src/screens/HomeScreen.js @@ -35,6 +35,12 @@ function QRCode() { function Home() { const history = useHistory(); + const dispatch = useDispatch(); + + const handleLogout = () => { + dispatch(authLogout()); + history.push("/login"); + } const isAuthenticated = useSelector(state => state.auth.isAuthenticated); if (!isAuthenticated) return ; @@ -59,7 +65,9 @@ function Home() { contact, or allow them to create an account! - + + + ); From 3fef324968cfb854dc6ee3e97d66c572b83416ef Mon Sep 17 00:00:00 2001 From: Nareshkumar Rao <_accounts@nareshkumarrao.com> Date: Thu, 29 Jul 2021 18:14:50 +0200 Subject: [PATCH 2/3] fixed equality in authSlice.js --- src/features/auth/authSlice.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/features/auth/authSlice.js b/src/features/auth/authSlice.js index e1d61a3..e1871d3 100644 --- a/src/features/auth/authSlice.js +++ b/src/features/auth/authSlice.js @@ -2,7 +2,7 @@ import { createSlice } from '@reduxjs/toolkit'; import Cookies from 'js-cookie'; const initialState = { - isAuthenticated: Cookies.get('authorized') == "true" ? true : false, + isAuthenticated: Cookies.get('authorized') === "true" ? true : false, }; export const authSlice = createSlice({ From 4e3851f1d6a18ded6d6917c7b1f88e384f69885b Mon Sep 17 00:00:00 2001 From: Nareshkumar Rao <_accounts@nareshkumarrao.com> Date: Thu, 29 Jul 2021 20:03:13 +0200 Subject: [PATCH 3/3] loading toasts --- src/screens/LoginScreen.js | 9 +++++++++ src/screens/ScannerScreen.js | 17 +++++++++++++++++ 2 files changed, 26 insertions(+) diff --git a/src/screens/LoginScreen.js b/src/screens/LoginScreen.js index ed2f428..86f2273 100644 --- a/src/screens/LoginScreen.js +++ b/src/screens/LoginScreen.js @@ -17,6 +17,13 @@ function Login() { if (isAuthenticated) return ; 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()); diff --git a/src/screens/ScannerScreen.js b/src/screens/ScannerScreen.js index 08641af..105e92d 100644 --- a/src/screens/ScannerScreen.js +++ b/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]);