From 70af4c7501f2e7b21910309e443988716200e196 Mon Sep 17 00:00:00 2001 From: Nareshkumar Rao <_accounts@nareshkumarrao.com> Date: Sun, 1 Aug 2021 22:31:09 +0200 Subject: [PATCH 1/5] cleaned up .env settings in gitignore --- .gitignore | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/.gitignore b/.gitignore index a6d314b..1f9e232 100644 --- a/.gitignore +++ b/.gitignore @@ -16,12 +16,9 @@ # misc .DS_Store .env.local -.env.development.local -.env.test.local -.env.production.local +.env.* +!.env.template npm-debug.log* yarn-debug.log* yarn-error.log* -.env.production -.env.development From bb557fad2aacd33ec73047ca114ecf34c0361b92 Mon Sep 17 00:00:00 2001 From: Nareshkumar Rao <_accounts@nareshkumarrao.com> Date: Thu, 5 Aug 2021 17:01:02 +0200 Subject: [PATCH 2/5] add report covid --- src/App.js | 4 ++ src/app/store.js | 2 + src/features/auth/covidSlice.js | 25 ++++++++ src/screens/HomeScreen.js | 102 +++++++++++++++++++++++++++++++- src/screens/LockoutScreen.js | 52 ++++++++++++++++ 5 files changed, 183 insertions(+), 2 deletions(-) create mode 100644 src/features/auth/covidSlice.js create mode 100644 src/screens/LockoutScreen.js diff --git a/src/App.js b/src/App.js index 05f10dd..1946186 100644 --- a/src/App.js +++ b/src/App.js @@ -7,6 +7,7 @@ import Success from './screens/SuccessScreen'; import './App.css'; import Verify from './screens/VerifyScreen'; import Scanner from './screens/ScannerScreen'; +import Lockout from './screens/LockoutScreen'; function App() { return ( @@ -25,6 +26,9 @@ function App() { + + + diff --git a/src/app/store.js b/src/app/store.js index 1457d32..0220126 100644 --- a/src/app/store.js +++ b/src/app/store.js @@ -1,8 +1,10 @@ import { configureStore } from '@reduxjs/toolkit'; import authSlice from '../features/auth/authSlice'; +import covidSlice from '../features/auth/covidSlice'; export const store = configureStore({ reducer: { auth: authSlice, + covid: covidSlice, }, }); diff --git a/src/features/auth/covidSlice.js b/src/features/auth/covidSlice.js new file mode 100644 index 0000000..14691c8 --- /dev/null +++ b/src/features/auth/covidSlice.js @@ -0,0 +1,25 @@ +import { createSlice } from '@reduxjs/toolkit'; +import Cookies from 'js-cookie'; + +const initialState = { + isCovidPositive: Cookies.get('covidPositive') === 'true' ? true : false, +}; + +export const covidSlice = createSlice({ + name: 'covid', + initialState, + reducers: { + setCovidPositive: state => { + state.isCovidPositive = true; + Cookies.set('covidPositive', true); + }, + setCovidNegative: state => { + state.isCovidPositive = false; + Cookies.set('covidPositive', false); + } + }, +}); + +export const { setCovidPositive, setCovidNegative } = covidSlice.actions; + +export default covidSlice.reducer; diff --git a/src/screens/HomeScreen.js b/src/screens/HomeScreen.js index 1d19593..30d948c 100644 --- a/src/screens/HomeScreen.js +++ b/src/screens/HomeScreen.js @@ -1,4 +1,10 @@ import { + AlertDialog, + AlertDialogBody, + AlertDialogContent, + AlertDialogFooter, + AlertDialogHeader, + AlertDialogOverlay, Button, Divider, Flex, @@ -6,12 +12,14 @@ import { Link, Spinner, Text, + useToast, } from '@chakra-ui/react'; import axios from 'axios'; -import { Fragment, React, useEffect, useState } from 'react'; +import { Fragment, React, useEffect, useRef, useState } from 'react'; import { useDispatch, useSelector } from 'react-redux'; import { Redirect, useHistory } from 'react-router-dom'; import { authLogout } from '../features/auth/authSlice'; +import { setCovidPositive } from '../features/auth/covidSlice'; function QRCode() { const [url, setURL] = useState(null); @@ -41,6 +49,92 @@ function QRCode() { } } +function ConfirmCOVIDPositiveAlertDialog() { + + const [isOpen, setOpen] = useState(false); + const toast = useToast(); + const history = useHistory(); + const dispatch = useDispatch(); + const onClose = () => { setOpen(false) } + const showErrorToast = (errorMessage = "An error has occured.") => { + toast.closeAll(); + toast({ + title: 'Error!', + description: errorMessage, + status: 'error', + duration: 5000 + }); + } + const onConfirm = () => { + toast({ + title: 'Confirming', + description: 'Hold on while we confirm with our servers.', + status: 'info', + duration: 10000 + }); + axios.post(`${process.env.REACT_APP_API_URL}/covid`,{ + setPositive: true, + },{withCredentials:true}) + .then(res => { + if(res.data.covidPositive){ + dispatch(setCovidPositive()); + toast({ + title: "Confirmed!", + status: 'info', + duration: 500, + }); + }else{ + showErrorToast(); + } + }) + .catch(err => { + console.log(err); + try{ + if(err.response.status === 401){ + showErrorToast("You are not logged in!"); + history.push("/login"); + }else{ + showErrorToast(); + } + }catch(e){ + showErrorToast(); + } + }); + setOpen(false); + } + const cancelRef = useRef(); + + return ( + <> + + + + + + Confirm Tested COVID19 Positive + + + Please confirm that you have been tested POSITIVE with + COVID19. Upon confirmation, this app will inform the people + you have come in contact with in the last 7 days. + + + + + + + + + + ); +} + function Home() { const history = useHistory(); const dispatch = useDispatch(); @@ -51,7 +145,9 @@ function Home() { }; const isAuthenticated = useSelector(state => state.auth.isAuthenticated); + const isCovidPositive = useSelector(state => state.covid.isCovidPositive); if (!isAuthenticated) return ; + if (isCovidPositive) return ; return ( )} - diff --git a/src/screens/LockoutScreen.js b/src/screens/LockoutScreen.js new file mode 100644 index 0000000..30e6013 --- /dev/null +++ b/src/screens/LockoutScreen.js @@ -0,0 +1,52 @@ +import { Flex, Heading, Text } from "@chakra-ui/react"; +import axios from "axios"; +import { useEffect } from "react"; +import { useDispatch, useSelector } from "react-redux"; +import { Redirect } from "react-router-dom"; +import { setCovidPositive } from "../features/auth/covidSlice"; + +function Lockout(){ + const isAuthenticated = useSelector(state => state.auth.isAuthenticated); + const isCovidPositive = useSelector(state => state.covid.isCovidPositive); + const dispatch = useDispatch(); + + useEffect( ()=>{ + + axios.post(`${process.env.REACT_APP_API_URL}/covid`,{},{withCredentials:true}) + .then(res=>{ + if(res.body.positivity){ + dispatch(setCovidPositive()); + } + }) + .catch(err=>{ + + }); + + }, [dispatch]); + + if (!isAuthenticated) return ; + if (!isCovidPositive) return ; + + return ( + + + Lockout + + You have reported that you have been tested POSITIVE with COVID19. + This lockout is to remind you to quarantine yourself according to local + COVID19 health policies. This lockout will automatically be lifted after + 14 days. +

+ Please avoid contact with other people for the duration of this lockout! +
+
+
+ ); +} + +export default Lockout; \ No newline at end of file From cbc2b2c8629336cf68f70a11e196aeb3783fd628 Mon Sep 17 00:00:00 2001 From: Nareshkumar Rao <_accounts@nareshkumarrao.com> Date: Thu, 5 Aug 2021 17:49:58 +0200 Subject: [PATCH 3/5] lockout updates --- src/screens/HomeScreen.js | 9 ++++ src/screens/LockoutScreen.js | 87 ++++++++++++++++++++---------------- src/screens/ScannerScreen.js | 12 +++++ 3 files changed, 69 insertions(+), 39 deletions(-) diff --git a/src/screens/HomeScreen.js b/src/screens/HomeScreen.js index 30d948c..2d29f4a 100644 --- a/src/screens/HomeScreen.js +++ b/src/screens/HomeScreen.js @@ -146,6 +146,15 @@ function Home() { const isAuthenticated = useSelector(state => state.auth.isAuthenticated); const isCovidPositive = useSelector(state => state.covid.isCovidPositive); + useEffect( ()=>{ + axios.post(`${process.env.REACT_APP_API_URL}/covid`,{},{withCredentials:true}) + .then(res=>{ + if(res.data.covidPositive){ + dispatch(setCovidPositive()); + } + }) + .catch(err=>{}); +}, [dispatch]); if (!isAuthenticated) return ; if (isCovidPositive) return ; diff --git a/src/screens/LockoutScreen.js b/src/screens/LockoutScreen.js index 30e6013..73820da 100644 --- a/src/screens/LockoutScreen.js +++ b/src/screens/LockoutScreen.js @@ -2,51 +2,60 @@ import { Flex, Heading, Text } from "@chakra-ui/react"; import axios from "axios"; import { useEffect } from "react"; import { useDispatch, useSelector } from "react-redux"; -import { Redirect } from "react-router-dom"; -import { setCovidPositive } from "../features/auth/covidSlice"; +import { Redirect, useHistory } from "react-router-dom"; +import { authLogout } from "../features/auth/authSlice"; +import { setCovidNegative, setCovidPositive } from "../features/auth/covidSlice"; -function Lockout(){ - const isAuthenticated = useSelector(state => state.auth.isAuthenticated); - const isCovidPositive = useSelector(state => state.covid.isCovidPositive); - const dispatch = useDispatch(); +function Lockout() { + const isAuthenticated = useSelector(state => state.auth.isAuthenticated); + const isCovidPositive = useSelector(state => state.covid.isCovidPositive); + const dispatch = useDispatch(); + const history = useHistory(); - useEffect( ()=>{ + useEffect(() => { + axios.post(`${process.env.REACT_APP_API_URL}/covid`, {}, { withCredentials: true }) + .then(res => { + if (res.data.covidPositive) { + dispatch(setCovidPositive()); + } else if (res.data.covidPositive === false) { + dispatch(setCovidNegative()); + } + }) + .catch(err => { + try { + if (err.response.status === 401) { + dispatch(authLogout()); + history.push("/login"); + } + } + catch (e) { } + }); - axios.post(`${process.env.REACT_APP_API_URL}/covid`,{},{withCredentials:true}) - .then(res=>{ - if(res.body.positivity){ - dispatch(setCovidPositive()); - } - }) - .catch(err=>{ + }, [dispatch, history]); - }); - - }, [dispatch]); + if (!isAuthenticated) return ; + if (!isCovidPositive) return ; - if (!isAuthenticated) return ; - if (!isCovidPositive) return ; - - return ( - - - Lockout - - You have reported that you have been tested POSITIVE with COVID19. - This lockout is to remind you to quarantine yourself according to local - COVID19 health policies. This lockout will automatically be lifted after - 14 days. -

- Please avoid contact with other people for the duration of this lockout! -
-
+ return ( + + + Lockout + + You have reported that you have been tested POSITIVE with COVID19. + This lockout is to remind you to quarantine yourself according to local + COVID19 health policies. This lockout will automatically be lifted after + 14 days. +

+ Please avoid contact with other people for the duration of this lockout! +
- ); +
+ ); } export default Lockout; \ No newline at end of file diff --git a/src/screens/ScannerScreen.js b/src/screens/ScannerScreen.js index 1fb0a33..c18f16b 100644 --- a/src/screens/ScannerScreen.js +++ b/src/screens/ScannerScreen.js @@ -5,6 +5,7 @@ import QrReader from 'react-qr-reader'; import { useDispatch, useSelector } from 'react-redux'; import { Redirect, useHistory } from 'react-router-dom'; import { authLogout } from '../features/auth/authSlice'; +import { setCovidPositive } from '../features/auth/covidSlice'; function Scanner() { const toast = useToast(); @@ -87,7 +88,18 @@ function Scanner() { }, [scanData, dispatch, history, toast]); const isAuthenticated = useSelector(state => state.auth.isAuthenticated); + const isCovidPositive = useSelector(state => state.covid.isCovidPositive); + useEffect( ()=>{ + axios.post(`${process.env.REACT_APP_API_URL}/covid`,{},{withCredentials:true}) + .then(res=>{ + if(res.data.covidPositive){ + dispatch(setCovidPositive()); + } + }) + .catch(err=>{}); +}, [dispatch]); if (!isAuthenticated) return ; + if (isCovidPositive) return ; return ( Date: Thu, 5 Aug 2021 21:01:58 +0200 Subject: [PATCH 4/5] toast fix --- src/screens/HomeScreen.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/screens/HomeScreen.js b/src/screens/HomeScreen.js index 2d29f4a..1626813 100644 --- a/src/screens/HomeScreen.js +++ b/src/screens/HomeScreen.js @@ -78,10 +78,11 @@ function ConfirmCOVIDPositiveAlertDialog() { .then(res => { if(res.data.covidPositive){ dispatch(setCovidPositive()); + toast.closeAll(); toast({ title: "Confirmed!", status: 'info', - duration: 500, + duration: 2000, }); }else{ showErrorToast(); From a0c42f7e5542e549f2a1ce888e05ab610068274c Mon Sep 17 00:00:00 2001 From: Nareshkumar Rao <_accounts@nareshkumarrao.com> Date: Thu, 5 Aug 2021 21:57:14 +0200 Subject: [PATCH 5/5] toast for loading lockout status --- src/screens/LockoutScreen.js | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/src/screens/LockoutScreen.js b/src/screens/LockoutScreen.js index 73820da..02ce749 100644 --- a/src/screens/LockoutScreen.js +++ b/src/screens/LockoutScreen.js @@ -1,4 +1,4 @@ -import { Flex, Heading, Text } from "@chakra-ui/react"; +import { Flex, Heading, Text, useToast } from "@chakra-ui/react"; import axios from "axios"; import { useEffect } from "react"; import { useDispatch, useSelector } from "react-redux"; @@ -11,10 +11,17 @@ function Lockout() { const isCovidPositive = useSelector(state => state.covid.isCovidPositive); const dispatch = useDispatch(); const history = useHistory(); + const toast = useToast(); useEffect(() => { + toast({ + title: 'Checking your lockout status...', + status: 'info', + duration: 10000, + }); axios.post(`${process.env.REACT_APP_API_URL}/covid`, {}, { withCredentials: true }) .then(res => { + toast.closeAll(); if (res.data.covidPositive) { dispatch(setCovidPositive()); } else if (res.data.covidPositive === false) { @@ -26,12 +33,19 @@ function Lockout() { if (err.response.status === 401) { dispatch(authLogout()); history.push("/login"); + }else{ + toast.closeAll(); + toast({ + title: 'Server Error Occurred', + status: 'error', + duration: 10000, + }); } } catch (e) { } }); - }, [dispatch, history]); + }, [dispatch, history, toast]); if (!isAuthenticated) return ; if (!isCovidPositive) return ;