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 (