Browse Source

ran linter

pull/10/head
Nareshkumar Rao 3 years ago
parent
commit
75c884740c
  1. 2
      src/features/auth/covidSlice.js
  2. 117
      src/screens/HomeScreen.js
  3. 62
      src/screens/LockoutScreen.js
  4. 2
      src/screens/LoginScreen.js
  5. 32
      src/screens/ScannerScreen.js
  6. 11
      src/screens/SuccessScreen.js
  7. 11
      src/screens/VerifyScreen.js

2
src/features/auth/covidSlice.js

@ -16,7 +16,7 @@ export const covidSlice = createSlice({
setCovidNegative: state => { setCovidNegative: state => {
state.isCovidPositive = false; state.isCovidPositive = false;
Cookies.set('covidPositive', false); Cookies.set('covidPositive', false);
}
},
}, },
}); });

117
src/screens/HomeScreen.js

@ -50,64 +50,76 @@ function QRCode() {
} }
function ConfirmCOVIDPositiveAlertDialog() { function ConfirmCOVIDPositiveAlertDialog() {
const [isOpen, setOpen] = useState(false); const [isOpen, setOpen] = useState(false);
const toast = useToast(); const toast = useToast();
const history = useHistory(); const history = useHistory();
const dispatch = useDispatch(); const dispatch = useDispatch();
const onClose = () => { setOpen(false) }
const showErrorToast = (errorMessage = "An error has occured.") => {
const onClose = () => {
setOpen(false);
};
const showErrorToast = (errorMessage = 'An error has occured.') => {
toast.closeAll(); toast.closeAll();
toast({ toast({
title: 'Error!', title: 'Error!',
description: errorMessage, description: errorMessage,
status: 'error', status: 'error',
duration: 5000
duration: 5000,
}); });
}
};
const onConfirm = () => { const onConfirm = () => {
toast({ toast({
title: 'Confirming', title: 'Confirming',
description: 'Hold on while we confirm with our servers.', description: 'Hold on while we confirm with our servers.',
status: 'info', status: 'info',
duration: 10000
duration: 10000,
}); });
axios.post(`${process.env.REACT_APP_API_URL}/covid`,{
setPositive: true,
},{withCredentials:true})
.then(res => {
if(res.data.covidPositive){
dispatch(setCovidPositive());
toast.closeAll();
toast({
title: "Confirmed!",
status: 'info',
duration: 2000,
});
}else{
showErrorToast();
}
})
.catch(err => {
console.log(err);
try{
if(err.response.status === 401){
showErrorToast("You are not logged in!");
history.push("/login");
}else{
axios
.post(
`${process.env.REACT_APP_API_URL}/covid`,
{
setPositive: true,
},
{ withCredentials: true }
)
.then(res => {
if (res.data.covidPositive) {
dispatch(setCovidPositive());
toast.closeAll();
toast({
title: 'Confirmed!',
status: 'info',
duration: 2000,
});
} else {
showErrorToast(); showErrorToast();
} }
}catch(e){
showErrorToast();
}
});
})
.catch(err => {
console.log(err);
try {
if (err.response.status === 401) {
showErrorToast('You are not logged in!');
history.push('/login');
} else {
showErrorToast();
}
} catch (e) {
showErrorToast();
}
});
setOpen(false); setOpen(false);
}
};
const cancelRef = useRef(); const cancelRef = useRef();
return ( return (
<> <>
<Button colorScheme="red" mb={6} onClick={() => { setOpen(true); }}>
<Button
colorScheme="red"
mb={6}
onClick={() => {
setOpen(true);
}}
>
Report Positive COVID19 Report Positive COVID19
</Button> </Button>
<AlertDialog <AlertDialog
@ -121,13 +133,17 @@ function ConfirmCOVIDPositiveAlertDialog() {
Confirm Tested COVID19 Positive Confirm Tested COVID19 Positive
</AlertDialogHeader> </AlertDialogHeader>
<AlertDialogBody> <AlertDialogBody>
Please confirm that you have been tested POSITIVE with
COVID19. Upon confirmation, this app will inform the people
you have come in contact with in the last 7 days.
Please confirm that you have been tested POSITIVE with COVID19.
Upon confirmation, this app will inform the people you have come
in contact with in the last 7 days.
</AlertDialogBody> </AlertDialogBody>
<AlertDialogFooter> <AlertDialogFooter>
<Button ref={cancelRef} onClick={onClose}>Cancel</Button>
<Button colorScheme="red" onClick={onConfirm} ml={3}>Confirm</Button>
<Button ref={cancelRef} onClick={onClose}>
Cancel
</Button>
<Button colorScheme="red" onClick={onConfirm} ml={3}>
Confirm
</Button>
</AlertDialogFooter> </AlertDialogFooter>
</AlertDialogContent> </AlertDialogContent>
</AlertDialogOverlay> </AlertDialogOverlay>
@ -147,15 +163,20 @@ 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());
useEffect(() => {
axios
.post(
`${process.env.REACT_APP_API_URL}/covid`,
{},
{ withCredentials: true }
)
.then(res => {
if (res.data.covidPositive) {
dispatch(setCovidPositive());
} }
})
.catch(err=>{});
}, [dispatch]);
})
.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" />;

62
src/screens/LockoutScreen.js

@ -1,10 +1,13 @@
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";
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() { function Lockout() {
const isAuthenticated = useSelector(state => state.auth.isAuthenticated); const isAuthenticated = useSelector(state => state.auth.isAuthenticated);
@ -19,7 +22,12 @@ function Lockout() {
status: 'info', status: 'info',
duration: 10000, duration: 10000,
}); });
axios.post(`${process.env.REACT_APP_API_URL}/covid`, {}, { withCredentials: true })
axios
.post(
`${process.env.REACT_APP_API_URL}/covid`,
{},
{ withCredentials: true }
)
.then(res => { .then(res => {
toast.closeAll(); toast.closeAll();
if (res.data.covidPositive) { if (res.data.covidPositive) {
@ -33,18 +41,16 @@ function Lockout() {
try { try {
if (err.response.status === 401) { if (err.response.status === 401) {
dispatch(authLogout()); dispatch(authLogout());
history.push("/login");
}else{
history.push('/login');
} else {
toast({ toast({
title: 'Server Error Occurred', title: 'Server Error Occurred',
status: 'error', status: 'error',
duration: 10000, duration: 10000,
}); });
} }
}
catch (e) { }
} catch (e) {}
}); });
}, [dispatch, history, toast]); }, [dispatch, history, toast]);
if (!isAuthenticated) return <Redirect to="/login" />; if (!isAuthenticated) return <Redirect to="/login" />;
@ -52,24 +58,36 @@ function Lockout() {
return ( return (
<Flex <Flex
minHeight="100vh"
minHeight="100vh"
background="red.500" background="red.500"
alignItems="center" alignItems="center"
justifyContent="center" justifyContent="center"
> >
<Flex direction="column" background="white" mt={5} mb={5} p={12} rounded={6} id="contentFlex">
<Flex
direction="column"
background="white"
mt={5}
mb={5}
p={12}
rounded={6}
id="contentFlex"
>
<Heading>Lockout</Heading> <Heading>Lockout</Heading>
<Text> <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>
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> </Text>
</Flex> </Flex>
</Flex> </Flex>
); );
} }
export default Lockout;
export default Lockout;

2
src/screens/LoginScreen.js

@ -80,7 +80,7 @@ function Login() {
return ( return (
<Flex <Flex
minHeight="100vh"
minHeight="100vh"
background="teal.100" background="teal.100"
alignItems="center" alignItems="center"
justifyContent="center" justifyContent="center"

32
src/screens/ScannerScreen.js

@ -89,26 +89,38 @@ function Scanner() {
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());
useEffect(() => {
axios
.post(
`${process.env.REACT_APP_API_URL}/covid`,
{},
{ withCredentials: true }
)
.then(res => {
if (res.data.covidPositive) {
dispatch(setCovidPositive());
} }
})
.catch(err=>{});
}, [dispatch]);
})
.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" />;
return ( return (
<Flex <Flex
minHeight="100vh"
minHeight="100vh"
background="teal.100" background="teal.100"
alignItems="center" alignItems="center"
justifyContent="center" justifyContent="center"
> >
<Flex direction="column" background="white" p={12} mb={6} mt={6} rounded={6}>
<Flex
direction="column"
background="white"
p={12}
mb={6}
mt={6}
rounded={6}
>
<QrReader <QrReader
mb={6} mb={6}
delay={300} delay={300}

11
src/screens/SuccessScreen.js

@ -6,12 +6,19 @@ function Success() {
return ( return (
<Flex <Flex
minHeight="100vh"
minHeight="100vh"
background="teal.100" background="teal.100"
alignItems="center" alignItems="center"
justifyContent="center" justifyContent="center"
> >
<Flex direction="column" background="white" mb={6} mt={6} p={12} rounded={6}>
<Flex
direction="column"
background="white"
mb={6}
mt={6}
p={12}
rounded={6}
>
<Heading>Success!</Heading> <Heading>Success!</Heading>
<Text fontSize="lg"> <Text fontSize="lg">
We have succesfully saved your contact! Stay safe out there, and let We have succesfully saved your contact! Stay safe out there, and let

11
src/screens/VerifyScreen.js

@ -43,12 +43,19 @@ function Verify(props) {
return ( return (
<Flex <Flex
minHeight="100vh"
minHeight="100vh"
background="teal.100" background="teal.100"
alignItems="center" alignItems="center"
justifyContent="center" justifyContent="center"
> >
<Flex direction="column" background="white" p={12} mt={6} mb={6} rounded={6}>
<Flex
direction="column"
background="white"
p={12}
mt={6}
mb={6}
rounded={6}
>
{verifyError ? errorMessage : loadingMessage} {verifyError ? errorMessage : loadingMessage}
</Flex> </Flex>
</Flex> </Flex>

Loading…
Cancel
Save