Browse Source

lockout updates

pull/8/head
Nareshkumar Rao 3 years ago
parent
commit
cbc2b2c862
  1. 9
      src/screens/HomeScreen.js
  2. 87
      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 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 (isCovidPositive) return <Redirect to="/lockout" />;

87
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 <Redirect to="/login" />;
if (!isCovidPositive) return <Redirect to="/home" />;
if (!isAuthenticated) return <Redirect to="/login" />;
if (!isCovidPositive) return <Redirect to="/home" />;
return (
<Flex
height="100vh"
background="red.500"
alignItems="center"
justifyContent="center"
>
<Flex direction="column" background="white" p={12} rounded={6} id="contentFlex">
<Heading>Lockout</Heading>
<Text>
You have reported that you have been tested <b>POSITIVE</b> 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.
<br/><br/>
<b>Please avoid contact with other people for the duration of this lockout!</b>
</Text>
</Flex>
return (
<Flex
height="100vh"
background="red.500"
alignItems="center"
justifyContent="center"
>
<Flex direction="column" background="white" p={12} rounded={6} id="contentFlex">
<Heading>Lockout</Heading>
<Text>
You have reported that you have been tested <b>POSITIVE</b> 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.
<br /><br />
<b>Please avoid contact with other people for the duration of this lockout!</b>
</Text>
</Flex>
);
</Flex>
);
}
export default Lockout;

12
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 <Redirect to="/login" />;
if (isCovidPositive) return <Redirect to="/lockout" />;
return (
<Flex

Loading…
Cancel
Save