From 75c884740c716d533771c0d4b7c49d4a308f864c Mon Sep 17 00:00:00 2001 From: Nareshkumar Rao Date: Fri, 13 Aug 2021 00:16:52 +0200 Subject: [PATCH] ran linter --- src/features/auth/covidSlice.js | 2 +- src/screens/HomeScreen.js | 117 +++++++++++++++++++------------- src/screens/LockoutScreen.js | 62 +++++++++++------ src/screens/LoginScreen.js | 2 +- src/screens/ScannerScreen.js | 32 ++++++--- src/screens/SuccessScreen.js | 11 ++- src/screens/VerifyScreen.js | 11 ++- 7 files changed, 151 insertions(+), 86 deletions(-) diff --git a/src/features/auth/covidSlice.js b/src/features/auth/covidSlice.js index 14691c8..d6c5a8b 100644 --- a/src/features/auth/covidSlice.js +++ b/src/features/auth/covidSlice.js @@ -16,7 +16,7 @@ export const covidSlice = createSlice({ setCovidNegative: state => { state.isCovidPositive = false; Cookies.set('covidPositive', false); - } + }, }, }); diff --git a/src/screens/HomeScreen.js b/src/screens/HomeScreen.js index ba78603..adf47d5 100644 --- a/src/screens/HomeScreen.js +++ b/src/screens/HomeScreen.js @@ -50,64 +50,76 @@ function QRCode() { } function ConfirmCOVIDPositiveAlertDialog() { - const [isOpen, setOpen] = useState(false); const toast = useToast(); const history = useHistory(); 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({ title: 'Error!', description: errorMessage, status: 'error', - duration: 5000 + duration: 5000, }); - } + }; const onConfirm = () => { toast({ title: 'Confirming', description: 'Hold on while we confirm with our servers.', 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(); } - }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); - } + }; const cancelRef = useRef(); return ( <> - - 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. - - + + @@ -147,15 +163,20 @@ 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()); + 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 ; if (isCovidPositive) return ; diff --git a/src/screens/LockoutScreen.js b/src/screens/LockoutScreen.js index 85f01ea..82bd469 100644 --- a/src/screens/LockoutScreen.js +++ b/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() { const isAuthenticated = useSelector(state => state.auth.isAuthenticated); @@ -19,7 +22,12 @@ function Lockout() { status: 'info', 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 => { toast.closeAll(); if (res.data.covidPositive) { @@ -33,18 +41,16 @@ function Lockout() { try { if (err.response.status === 401) { dispatch(authLogout()); - history.push("/login"); - }else{ + history.push('/login'); + } else { toast({ title: 'Server Error Occurred', status: 'error', duration: 10000, }); } - } - catch (e) { } + } catch (e) {} }); - }, [dispatch, history, toast]); if (!isAuthenticated) return ; @@ -52,24 +58,36 @@ function Lockout() { return ( - + Lockout - You have reported that you have been tested POSITIVE 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. -

- Please avoid contact with other people for the duration of this lockout! + You have reported that you have been tested POSITIVE 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. +
+
+ + Please avoid contact with other people for the duration of this + lockout! +
); } -export default Lockout; \ No newline at end of file +export default Lockout; diff --git a/src/screens/LoginScreen.js b/src/screens/LoginScreen.js index f219f8d..56d5f50 100644 --- a/src/screens/LoginScreen.js +++ b/src/screens/LoginScreen.js @@ -80,7 +80,7 @@ function Login() { return ( 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()); + 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 ; if (isCovidPositive) return ; return ( - + - + Success! We have succesfully saved your contact! Stay safe out there, and let diff --git a/src/screens/VerifyScreen.js b/src/screens/VerifyScreen.js index 68bab13..aedcedf 100644 --- a/src/screens/VerifyScreen.js +++ b/src/screens/VerifyScreen.js @@ -43,12 +43,19 @@ function Verify(props) { return ( - + {verifyError ? errorMessage : loadingMessage}