Nareshkumar Rao
3 years ago
committed by
GitHub
7 changed files with 230 additions and 7 deletions
@ -1,8 +1,10 @@ |
|||||
import { configureStore } from '@reduxjs/toolkit'; |
import { configureStore } from '@reduxjs/toolkit'; |
||||
import authSlice from '../features/auth/authSlice'; |
import authSlice from '../features/auth/authSlice'; |
||||
|
import covidSlice from '../features/auth/covidSlice'; |
||||
|
|
||||
export const store = configureStore({ |
export const store = configureStore({ |
||||
reducer: { |
reducer: { |
||||
auth: authSlice, |
auth: authSlice, |
||||
|
covid: covidSlice, |
||||
}, |
}, |
||||
}); |
}); |
||||
|
@ -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; |
@ -0,0 +1,75 @@ |
|||||
|
import { Flex, Heading, Text, useToast } from "@chakra-ui/react"; |
||||
|
import axios from "axios"; |
||||
|
import { useEffect } from "react"; |
||||
|
import { useDispatch, useSelector } from "react-redux"; |
||||
|
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(); |
||||
|
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) { |
||||
|
dispatch(setCovidNegative()); |
||||
|
} |
||||
|
}) |
||||
|
.catch(err => { |
||||
|
try { |
||||
|
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, toast]); |
||||
|
|
||||
|
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> |
||||
|
</Flex> |
||||
|
); |
||||
|
} |
||||
|
|
||||
|
export default Lockout; |
Loading…
Reference in new issue