Browse Source

lockout updates

pull/8/head
Nareshkumar Rao 3 years ago
parent
commit
cbc2b2c862
  1. 9
      src/screens/HomeScreen.js
  2. 21
      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" />;

21
src/screens/LockoutScreen.js

@ -2,27 +2,36 @@ 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();
const history = useHistory();
useEffect(() => {
axios.post(`${process.env.REACT_APP_API_URL}/covid`, {}, { withCredentials: true })
.then(res => {
if(res.body.positivity){
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) { }
});
}, [dispatch]);
}, [dispatch, history]);
if (!isAuthenticated) return <Redirect to="/login" />;
if (!isCovidPositive) return <Redirect to="/home" />;

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