Browse Source

lockout updates

pull/8/head
Nareshkumar Rao 3 years ago
parent
commit
cbc2b2c862
  1. 9
      src/screens/HomeScreen.js
  2. 33
      src/screens/LockoutScreen.js
  3. 12
      src/screens/ScannerScreen.js

9
src/screens/HomeScreen.js

@ -146,6 +146,15 @@ function Home() {
const isAuthenticated = useSelector(state => state.auth.isAuthenticated); const isAuthenticated = useSelector(state => state.auth.isAuthenticated);
const isCovidPositive = useSelector(state => state.covid.isCovidPositive); 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 <Redirect to="/login" />; if (!isAuthenticated) return <Redirect to="/login" />;
if (isCovidPositive) return <Redirect to="/lockout" />; if (isCovidPositive) return <Redirect to="/lockout" />;

33
src/screens/LockoutScreen.js

@ -2,27 +2,36 @@ import { Flex, Heading, Text } from "@chakra-ui/react";
import axios from "axios"; import axios from "axios";
import { useEffect } from "react"; import { useEffect } from "react";
import { useDispatch, useSelector } from "react-redux"; 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(){
function Lockout() {
const isAuthenticated = useSelector(state => state.auth.isAuthenticated); const isAuthenticated = useSelector(state => state.auth.isAuthenticated);
const isCovidPositive = useSelector(state => state.covid.isCovidPositive); const isCovidPositive = useSelector(state => state.covid.isCovidPositive);
const dispatch = useDispatch(); const dispatch = useDispatch();
const history = useHistory();
useEffect( ()=>{
axios.post(`${process.env.REACT_APP_API_URL}/covid`,{},{withCredentials:true})
.then(res=>{
if(res.body.positivity){
useEffect(() => {
axios.post(`${process.env.REACT_APP_API_URL}/covid`, {}, { withCredentials: true })
.then(res => {
if (res.data.covidPositive) {
dispatch(setCovidPositive()); dispatch(setCovidPositive());
} else if (res.data.covidPositive === false) {
dispatch(setCovidNegative());
} }
}) })
.catch(err=>{
.catch(err => {
try {
if (err.response.status === 401) {
dispatch(authLogout());
history.push("/login");
}
}
catch (e) { }
}); });
}, [dispatch]);
}, [dispatch, history]);
if (!isAuthenticated) return <Redirect to="/login" />; if (!isAuthenticated) return <Redirect to="/login" />;
if (!isCovidPositive) return <Redirect to="/home" />; if (!isCovidPositive) return <Redirect to="/home" />;
@ -41,7 +50,7 @@ function Lockout(){
This lockout is to remind you to quarantine yourself according to local This lockout is to remind you to quarantine yourself according to local
COVID19 health policies. This lockout will automatically be lifted after COVID19 health policies. This lockout will automatically be lifted after
14 days. 14 days.
<br/><br/>
<br /><br />
<b>Please avoid contact with other people for the duration of this lockout!</b> <b>Please avoid contact with other people for the duration of this lockout!</b>
</Text> </Text>
</Flex> </Flex>

12
src/screens/ScannerScreen.js

@ -5,6 +5,7 @@ import QrReader from 'react-qr-reader';
import { useDispatch, useSelector } from 'react-redux'; import { useDispatch, useSelector } from 'react-redux';
import { Redirect, useHistory } from 'react-router-dom'; import { Redirect, useHistory } from 'react-router-dom';
import { authLogout } from '../features/auth/authSlice'; import { authLogout } from '../features/auth/authSlice';
import { setCovidPositive } from '../features/auth/covidSlice';
function Scanner() { function Scanner() {
const toast = useToast(); const toast = useToast();
@ -87,7 +88,18 @@ function Scanner() {
}, [scanData, dispatch, history, toast]); }, [scanData, dispatch, history, toast]);
const isAuthenticated = useSelector(state => state.auth.isAuthenticated); 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 <Redirect to="/login" />; if (!isAuthenticated) return <Redirect to="/login" />;
if (isCovidPositive) return <Redirect to="/lockout" />;
return ( return (
<Flex <Flex

Loading…
Cancel
Save