diff --git a/client/.env.development b/client/.env.development index b23305d..ab28adf 100644 --- a/client/.env.development +++ b/client/.env.development @@ -1,2 +1,3 @@ REACT_APP_GOOGLE_MAPS_API_KEY=AIzaSyCxttBHhvoDHLXbUgnMtjO3OVDw46iFSQw REACT_APP_SERVER_URL=http://localhost:4000/graphql +REACT_APP_GOOGLE_OAUTH=962299963873-vfn6gg5ig0ilop0v70fgi7bonovplopr.apps.googleusercontent.com diff --git a/client/.eslintrc.js b/client/.eslintrc.js index e254df4..06edd8a 100644 --- a/client/.eslintrc.js +++ b/client/.eslintrc.js @@ -18,4 +18,10 @@ module.exports = { "plugin:react/recommended", "plugin:prettier/recommended", ], + rules: { + 'prettier/prettier': [ + 'error', + {endOfLine: 'auto'} + ] + }, }; diff --git a/client/package.json b/client/package.json index d98e8d6..a871b07 100644 --- a/client/package.json +++ b/client/package.json @@ -27,6 +27,7 @@ "react": "^17.0.2", "react-datetime": "2.16.3", "react-dom": "^17.0.2", + "react-google-login": "^5.2.2", "react-router-dom": "5.2.0", "react-scripts": "4.0.3", "react-slick": "0.26.1", diff --git a/client/src/CoviSource/Components/Pages/CreateProvider/CreateProvider.js b/client/src/CoviSource/Components/Pages/CreateProvider/CreateProvider.js index ad9b2bb..9703981 100644 --- a/client/src/CoviSource/Components/Pages/CreateProvider/CreateProvider.js +++ b/client/src/CoviSource/Components/Pages/CreateProvider/CreateProvider.js @@ -4,7 +4,6 @@ import { makeStyles } from "@material-ui/core/styles"; import InputAdornment from "@material-ui/core/InputAdornment"; // @material-ui/icons import LocationCity from "@material-ui/icons/LocationCity"; -// import People from "@material-ui/icons/People"; import Hospital from "@material-ui/icons/LocalHospital"; // core components import GridContainer from "components/Grid/GridContainer.js"; @@ -23,10 +22,10 @@ import "./CreateProvider.scss"; import image from "assets/img/bg7.jpg"; import CreateContact from "./CreateContact"; -import { useMutation } from "@apollo/client"; +import { useMutation, useQuery } from "@apollo/client"; import { CREATE_PROVIDER } from "CoviSource/graphql/mutations/Provider/CreateProvider"; import CreateResource from "./CreateResource"; -// import Map from "CoviSource/Components/UtilityComponents/Map/Map"; +import { GET_USER } from "CoviSource/graphql/queries/User/GetUser"; const useStyles = makeStyles(styles); @@ -40,6 +39,16 @@ const formReducer = (state, event) => { export default function CreateProvider(props) { const [formData, setFormData] = useReducer(formReducer, {}); const [resourceData, setresourceData] = useState({}); + const { + data: queryData, + error: queryError, + loading: queryLoading, + } = useQuery(GET_USER); + if (queryLoading) return <>Loading...>; + if (queryError) return <>Error>; + if (queryData.me === null) { + window.location.assign("/login"); + } const [cardAnimaton, setCardAnimation] = useState("cardHidden"); const [numberContact, setNumberContact] = useState(0); const [createProvider, { loading, data, error }] = useMutation( @@ -62,7 +71,6 @@ export default function CreateProvider(props) { name: event.target.name, value: event.target.value, }); - console.log(formData); }; const handleSubmit = (event) => { event.preventDefault(); diff --git a/client/src/CoviSource/Components/Pages/LandingPage/LandingPage.js b/client/src/CoviSource/Components/Pages/LandingPage/LandingPage.js index 517606c..f22365a 100644 --- a/client/src/CoviSource/Components/Pages/LandingPage/LandingPage.js +++ b/client/src/CoviSource/Components/Pages/LandingPage/LandingPage.js @@ -6,11 +6,8 @@ import classNames from "classnames"; // core components import Header from "CoviSource/Components/UtilityComponents/Header/Header"; - -// import Footer from "components/Footer/Footer.js"; import GridContainer from "components/Grid/GridContainer.js"; import GridItem from "components/Grid/GridItem.js"; -// import Button from "components/CustomButtons/Button.js"; import Parallax from "components/Parallax/Parallax.js"; // sections for the page @@ -34,174 +31,11 @@ export default function LandingPage(props) { const { loading, data, error } = useQuery(GET_ALL_PROVIDERS); if (loading) return <>Loading...>; if (error) return <>Error>; - if (data) console.log(data); - - // const [data, setData] = useState([ - // { - // username: "someUsername", - // resourceProviderName: "Resource Provider Name", - // availability: "UNUPDATED", - // resources: [ - // { - // resource: "Oxygen refilling", - // quantity: 32, - // updated: "06:00 PM, 27 APRIL", - // }, - // { - // resource: "Hospital Beds", - // quantity: 23, - // updated: "06:00 PM, 27 APRIL", - // }, - // { - // resource: "Remdesivir Vials", - // quantity: 65, - // updated: "06:00 PM, 27 APRIL", - // }, - // ], - // address: "Provider Address", - // contactPersonName: "Contact Person's Name", - // phoneNumber: "9821095754", - // serviceName: "Service Provided", - // }, - // { - // username: "anotherUsername", - // resourceProviderName: "Free oxygen seva vijaya nagar", - // availability: "AVAILABLE", - // resources: [ - // { - // resource: "Oxygen refilling", - // quantity: 32, - // updated: "06:00 PM, 27 APRIL", - // }, - // { - // resource: "Hospital Beds", - // quantity: 23, - // updated: "06:00 PM, 27 APRIL", - // }, - // { - // resource: "Remdesivir Vials", - // quantity: 65, - // updated: "06:00 PM, 27 APRIL", - // }, - // ], - // address: "Free oxygen seva, near gurudwara, delhi", - // contactPersonName: "Jaspal Singh", - // phoneNumber: "9821095754", - // serviceName: "Oxygen refilling", - // }, - // { - // username: "anotherUsername2", - // resourceProviderName: "Apex Hospital", - // availability: "UNAVAILABLE", - // resources: [ - // { - // resource: "Oxygen Cylinders", - // quantity: 0, - // updated: "06:00 PM, 27 APRIL", - // }, - // { - // resource: "Hospital Beds", - // quantity: 0, - // updated: "06:00 PM, 27 APRIL", - // }, - // { - // resource: "Remdesivir Vials", - // quantity: 0, - // updated: "06:00 PM, 27 APRIL", - // }, - // ], - // address: "Apex Hospital, Kalyan West, Mumbai", - // contactPersonName: "Dr. D P Goel", - // phoneNumber: "9789965234", - // serviceName: "Hospital", - // }, - // ]); const onSearchButtonClick = function () { console.log("Search Button Clicked"); - - // a fetch operation will be made here which will then update the state -> data; - // setData([ - // { - // username: "someUsername", - // resourceProviderName: "Resource Provider Name", - // availability: "UNUPDATED", - // resources: [ - // { - // resource: "Oxygen refilling", - // quantity: 32, - // updated: "06:00 PM, 27 APRIL", - // }, - // { - // resource: "Hospital Beds", - // quantity: 23, - // updated: "06:00 PM, 27 APRIL", - // }, - // { - // resource: "Remdesivir Vials", - // quantity: 65, - // updated: "06:00 PM, 27 APRIL", - // }, - // ], - // address: "Provider Address", - // contactPersonName: "Contact Person's Name", - // phoneNumber: "9821095754", - // serviceName: "Service Provided", - // }, - // { - // username: "anotherUsername", - // resourceProviderName: "Free oxygen seva vijaya nagar", - // availability: "AVAILABLE", - // resources: [ - // { - // resource: "Oxygen refilling", - // quantity: 32, - // updated: "06:00 PM, 27 APRIL", - // }, - // { - // resource: "Hospital Beds", - // quantity: 23, - // updated: "06:00 PM, 27 APRIL", - // }, - // { - // resource: "Remdesivir Vials", - // quantity: 65, - // updated: "06:00 PM, 27 APRIL", - // }, - // ], - // address: "Free oxygen seva, near gurudwara, delhi", - // contactPersonName: "Jaspal Singh", - // phoneNumber: "9821095754", - // serviceName: "Oxygen refilling", - // }, - // { - // username: "anotherUsername2", - // resourceProviderName: "Apex Hospital", - // availability: "UNAVAILABLE", - // resources: [ - // { - // resource: "Oxygen Cylinders", - // quantity: 0, - // updated: "06:00 PM, 27 APRIL", - // }, - // { - // resource: "Hospital Beds", - // quantity: 0, - // updated: "06:00 PM, 27 APRIL", - // }, - // { - // resource: "Remdesivir Vials", - // quantity: 0, - // updated: "06:00 PM, 27 APRIL", - // }, - // ], - // address: "Apex Hospital, Kalyan West, Mumbai", - // contactPersonName: "Dr. D P Goel", - // phoneNumber: "9789965234", - // serviceName: "Hospital", - // }, - // ]); }; + const renderResourcesCards = () => { return (
Or Be Classical
diff --git a/client/src/CoviSource/Components/Pages/OrganisationPage/OrganisationPage.js b/client/src/CoviSource/Components/Pages/OrganisationPage/OrganisationPage.js index 3435998..291326e 100644 --- a/client/src/CoviSource/Components/Pages/OrganisationPage/OrganisationPage.js +++ b/client/src/CoviSource/Components/Pages/OrganisationPage/OrganisationPage.js @@ -31,9 +31,6 @@ export default function OrganisationPage() { console.log(error); return <>Error>; } - if (data) { - console.log(data); - } const getBannerClass = function () { return "banner banner" + status[data.availability]; diff --git a/client/src/CoviSource/Components/Pages/RegistrationPage/RegistrationPage.js b/client/src/CoviSource/Components/Pages/RegistrationPage/RegistrationPage.js index 51d8e57..2c4151b 100644 --- a/client/src/CoviSource/Components/Pages/RegistrationPage/RegistrationPage.js +++ b/client/src/CoviSource/Components/Pages/RegistrationPage/RegistrationPage.js @@ -5,7 +5,6 @@ import InputAdornment from "@material-ui/core/InputAdornment"; // @material-ui/icons import Email from "@material-ui/icons/Email"; import People from "@material-ui/icons/People"; -// import Hospital from "@material-ui/icons/LocalHospital"; import Password from "@material-ui/icons/Lock"; // core components import GridContainer from "components/Grid/GridContainer.js"; @@ -25,11 +24,14 @@ import "./RegistrationPage.scss"; import image from "assets/img/bg2.jpg"; import Phone from "@material-ui/icons/Phone"; -import { useMutation } from "@apollo/client"; +import { useMutation, useQuery } from "@apollo/client"; import { ADD_USER } from "CoviSource/graphql/mutations/User/AddUser"; +import { GET_USER } from "CoviSource/graphql/queries/User/GetUser"; +import GoogleLogin from "react-google-login"; const useStyles = makeStyles(styles); +// To map each entry field to its value const formReducer = (state, event) => { return { ...state, @@ -46,6 +48,19 @@ export default function RegistrationPage(props) { const classes = useStyles(); const { ...rest } = props; + const { + data: queryData, + error: queryError, + loading: queryLoading, + } = useQuery(GET_USER); + + if (queryLoading) return <>Loading...>; + if (queryError) return <>Error>; + if (queryData.me) { + window.location.assign("/"); + } + + // addUser mutation const [addUser, { data, loading, error }] = useMutation(ADD_USER); const scrollChangeData = { @@ -53,6 +68,7 @@ export default function RegistrationPage(props) { color: "white", }; + // Handling change for individual entries of form data const handleChange = (event) => { setFormData({ name: event.target.name, @@ -60,6 +76,7 @@ export default function RegistrationPage(props) { }); }; + // Submit function to call the mutation const handleSubmit = (event) => { event.preventDefault(); addUser({ @@ -72,6 +89,38 @@ export default function RegistrationPage(props) { }, }, }); + // If loading then do nothing + if (loading); + // If error, alert the user + if (error) { + alert(error); + } + if (data) { + // If backend sends an error, alert the user + if (data.register.errors) { + alert(data.register.errors[0].message); + } + // Success + if (data.register.user) { + alert("Registration sucessful!"); + // Send to homepage + window.location.assign("/"); + } + } + }; + + // On obtaining valid Google OAuth tokens + const googleSuccess = async (res) => { + await addUser({ + variables: { + input: { + name: `${res.profileObj.givenName} ${res.profileObj.familyName}`, + email: res.profileObj.email, + phoneNumber: `${res.profileObj.googleId}`.substring(0, 10), + password: res.qc.login_hint, + }, + }, + }); if (loading); if (error) { alert(error); @@ -87,6 +136,11 @@ export default function RegistrationPage(props) { } }; + // On invalid Google OAuth + const googleFailure = () => { + alert("Google Signup was unsucessfull"); + }; + return (Or Be Classical
diff --git a/client/src/components/Badge/Badge.js b/client/src/components/Badge/Badge.js deleted file mode 100755 index 3d29d5a..0000000 --- a/client/src/components/Badge/Badge.js +++ /dev/null @@ -1,35 +0,0 @@ -import React from "react"; -// nodejs library to set properties for components -import PropTypes from "prop-types"; - -// @material-ui/core components -import { makeStyles } from "@material-ui/core/styles"; - -import styles from "assets/jss/material-kit-react/components/badgeStyle.js"; - -const useStyles = makeStyles(styles); - -export default function Badge(props) { - const classes = useStyles(); - const { color, children } = props; - return ( - {children} - ); -} - -Badge.defaultProps = { - color: "gray", -}; - -Badge.propTypes = { - color: PropTypes.oneOf([ - "primary", - "warning", - "danger", - "success", - "info", - "rose", - "gray", - ]), - children: PropTypes.node, -}; diff --git a/client/src/components/Clearfix/Clearfix.js b/client/src/components/Clearfix/Clearfix.js deleted file mode 100755 index c95a1bc..0000000 --- a/client/src/components/Clearfix/Clearfix.js +++ /dev/null @@ -1,25 +0,0 @@ -import React from "react"; - -// mterial-ui components -import { makeStyles } from "@material-ui/core/styles"; - -const styles = { - clearfix: { - "&:after,&:before": { - display: "table", - content: '" "', - }, - "&:after": { - clear: "both", - }, - }, -}; - -const useStyles = makeStyles(styles); - -export default function Clearfix() { - const classes = useStyles(); - return ; -} - -Clearfix.propTypes = {}; diff --git a/client/src/components/CustomDropdown/CustomDropdown.js b/client/src/components/CustomDropdown/CustomDropdown.js deleted file mode 100755 index 6c176db..0000000 --- a/client/src/components/CustomDropdown/CustomDropdown.js +++ /dev/null @@ -1,195 +0,0 @@ -import React from "react"; -// nodejs library that concatenates classes -import classNames from "classnames"; -// nodejs library to set properties for components -import PropTypes from "prop-types"; - -// @material-ui/core components -import { makeStyles } from "@material-ui/core/styles"; -import MenuItem from "@material-ui/core/MenuItem"; -import MenuList from "@material-ui/core/MenuList"; -import ClickAwayListener from "@material-ui/core/ClickAwayListener"; -import Paper from "@material-ui/core/Paper"; -import Grow from "@material-ui/core/Grow"; -import Divider from "@material-ui/core/Divider"; -import Icon from "@material-ui/core/Icon"; -import Popper from "@material-ui/core/Popper"; - -// core components -import Button from "components/CustomButtons/Button.js"; - -import styles from "assets/jss/material-kit-react/components/customDropdownStyle.js"; - -const useStyles = makeStyles(styles); - -export default function CustomDropdown(props) { - const [anchorEl, setAnchorEl] = React.useState(null); - const handleClick = (event) => { - if (anchorEl && anchorEl.contains(event.target)) { - setAnchorEl(null); - } else { - setAnchorEl(event.currentTarget); - } - }; - const handleClose = (param) => { - setAnchorEl(null); - if (props && props.onClick) { - props.onClick(param); - } - }; - const handleCloseAway = (event) => { - if (anchorEl.contains(event.target)) { - return; - } - setAnchorEl(null); - }; - const classes = useStyles(); - const { - buttonText, - buttonIcon, - dropdownList, - buttonProps, - dropup, - dropdownHeader, - caret, - hoverColor, - left, - rtlActive, - noLiPadding, - } = props; - const caretClasses = classNames({ - [classes.caret]: true, - [classes.caretActive]: Boolean(anchorEl), - [classes.caretRTL]: rtlActive, - }); - const dropdownItem = classNames({ - [classes.dropdownItem]: true, - [classes[hoverColor + "Hover"]]: true, - [classes.noLiPadding]: noLiPadding, - [classes.dropdownItemRTL]: rtlActive, - }); - let icon = null; - switch (typeof buttonIcon) { - case "object": - icon ={description}
--- ); -} - -Quote.propTypes = { - text: PropTypes.node, - author: PropTypes.node, -}; diff --git a/client/src/components/Typography/Small.js b/client/src/components/Typography/Small.js deleted file mode 100755 index 54101ac..0000000 --- a/client/src/components/Typography/Small.js +++ /dev/null @@ -1,23 +0,0 @@ -import React from "react"; -// nodejs library to set properties for components -import PropTypes from "prop-types"; -// @material-ui/core components -import { makeStyles } from "@material-ui/core/styles"; -// core components -import styles from "assets/jss/material-kit-react/components/typographyStyle.js"; - -const useStyles = makeStyles(styles); - -export default function Small(props) { - const classes = useStyles(); - const { children } = props; - return ( -{text}
- {author} -