From 040f9f89344b62915cd30e9f6ac69b595ba288b5 Mon Sep 17 00:00:00 2001 From: Edgar097 Date: Thu, 24 Jun 2021 11:18:38 -0600 Subject: [PATCH 1/5] fix(routes) --- makefile | 2 ++ webapp/src/routes/OffersApproval/OffersApproval.js | 12 +++++++++--- .../src/routes/OffersManagement/OffersManagement.js | 13 +++++++++++-- 3 files changed, 22 insertions(+), 5 deletions(-) diff --git a/makefile b/makefile index 1182c976..f4310311 100644 --- a/makefile +++ b/makefile @@ -10,6 +10,8 @@ run: make -j 3 run-hapi run-hasura run-webapp run-env: + @fuser -k 3000/tcp + @fuser -k 9695/tcp @[ -f .env ] && source .env || echo "$(YELLOW)WARNING:$(RESET) .env file not found" run-postgres: diff --git a/webapp/src/routes/OffersApproval/OffersApproval.js b/webapp/src/routes/OffersApproval/OffersApproval.js index d78f3151..970ddc6d 100644 --- a/webapp/src/routes/OffersApproval/OffersApproval.js +++ b/webapp/src/routes/OffersApproval/OffersApproval.js @@ -10,6 +10,7 @@ import MenuItem from '@material-ui/core/MenuItem' import FormControl from '@material-ui/core/FormControl' import Select from '@material-ui/core/Select' import SnackbarContent from '@material-ui/core/SnackbarContent' +import { useHistory } from 'react-router-dom' import ShowOffersAproval from '../../components/ShowElements/ShowOffersAproval' import { @@ -27,7 +28,11 @@ const OffersApproval = () => { const [loadingOffers, setLoadingOffers] = useState(true) const [offers, setOffers] = useState([]) const [currentUser] = useUser() - const [account] = useState(currentUser.account) + const history = useHistory() + const [account] = useState( + currentUser ? currentUser.account : + () => {history.replace('/')} + ) const [discountOffers, setDiscountOffers] = useState([]) const [freeOffers, setFreetOffers] = useState([]) const [badgeOffers, setBadgeOffers] = useState([]) @@ -92,8 +97,9 @@ const OffersApproval = () => { }, [allOffers]) useEffect(() => { - getInfo() - getOffers() + if(account){ + getOffers() + } }, []) useEffect(() => { diff --git a/webapp/src/routes/OffersManagement/OffersManagement.js b/webapp/src/routes/OffersManagement/OffersManagement.js index 89404b1b..3f08bf34 100644 --- a/webapp/src/routes/OffersManagement/OffersManagement.js +++ b/webapp/src/routes/OffersManagement/OffersManagement.js @@ -19,6 +19,7 @@ import CircularProgress from '@material-ui/core/CircularProgress' import * as m from 'moment-timezone' import moment from 'moment' import { useTranslation } from 'react-i18next' +import { useHistory } from 'react-router-dom' import { GET_SPONSOR_OFFERS_QUERY, @@ -30,13 +31,13 @@ import { import OfferDetails from './OfferDetails' import GenericOfferFormComponent from './GenericOfferFormComponent' import styles from './styles' -import { TextField } from '@material-ui/core' const useStyles = makeStyles(styles) const OffersManagement = () => { const { t } = useTranslation('translations') const classes = useStyles() + const history = useHistory() const [offers, setOffers] = useState(undefined) const [profileIDLoaded, setProfileIDLoaded] = useState(false) const [offersLoaded, setOffersLoaded] = useState(false) @@ -113,7 +114,7 @@ const OffersManagement = () => { } const [ loadProfileID, - { data: { profile: { profile } = {} } = {} } + {error: profileError ,data: { profile: { profile } = {} } = {} } ] = useLazyQuery(PROFILE_ID_QUERY, { fetchPolicy: 'network-only' }) const [ @@ -216,6 +217,10 @@ const OffersManagement = () => { setOpenSnackbar({ ...openSnackbar, show: false }) } + const errorManager = () => { + history.replace('/') + } + const getGenericOfferComponent = (editing, data) => { return ( { loadProfileID() }, [loadProfileID]) + useEffect(() => { + if(profileError) errorManager() + }, [profileError]) + useEffect(() => { if (profile) setProfileIDLoaded(true) }, [profile]) From 786b5782a0aa6eec77c23dcd232e5b28bd54a86d Mon Sep 17 00:00:00 2001 From: Edgar097 Date: Thu, 24 Jun 2021 11:51:28 -0600 Subject: [PATCH 2/5] fix(routes): automatic home route --- makefile | 2 -- .../NotificationStructure.js | 6 ++--- webapp/src/routes/EditProfile/EditProfile.js | 3 ++- .../HistoryDashboard/HistoryDashboard.js | 23 +++++++++++-------- 4 files changed, 18 insertions(+), 16 deletions(-) diff --git a/makefile b/makefile index f4310311..1182c976 100644 --- a/makefile +++ b/makefile @@ -10,8 +10,6 @@ run: make -j 3 run-hapi run-hasura run-webapp run-env: - @fuser -k 3000/tcp - @fuser -k 9695/tcp @[ -f .env ] && source .env || echo "$(YELLOW)WARNING:$(RESET) .env file not found" run-postgres: diff --git a/webapp/src/components/NotificationStructure/NotificationStructure.js b/webapp/src/components/NotificationStructure/NotificationStructure.js index 9455c800..20b19870 100644 --- a/webapp/src/components/NotificationStructure/NotificationStructure.js +++ b/webapp/src/components/NotificationStructure/NotificationStructure.js @@ -49,14 +49,14 @@ const NotificationStructure = ({ id, title, description, state, dateAndTime }) = return ( <> + {profileError && ()} { useEffect(() => { if (!currentUser) { client && client.resetStore() - history.replace('/') return } @@ -149,6 +149,7 @@ const ProfilePage = () => { return ( + {!profile && ()} {messegaAlert} diff --git a/webapp/src/routes/Profile/ProfilePageGuest.js b/webapp/src/routes/Profile/ProfilePageGuest.js index d9c4510c..8909e2e1 100644 --- a/webapp/src/routes/Profile/ProfilePageGuest.js +++ b/webapp/src/routes/Profile/ProfilePageGuest.js @@ -15,7 +15,7 @@ const ProfilePageGuest = () => { return ( <> - {t('common.name')} + {t('profile.profile')} {t('profile.guest')} From ec63964008142ba2d48290e86b9e864cac39d9c0 Mon Sep 17 00:00:00 2001 From: Edgar097 Date: Wed, 30 Jun 2021 14:29:18 -0600 Subject: [PATCH 4/5] fix(login): not allowing to log in --- makefile | 2 ++ webapp/src/components/LoginModal/Login.js | 2 +- webapp/src/routes/EditProfile/EditProfile.js | 4 ++-- webapp/src/routes/HistoryDashboard/HistoryDashboard.js | 2 +- webapp/src/routes/OffersManagement/OffersManagement.js | 6 ++++-- webapp/src/routes/Profile/ProfilePage.js | 2 +- 6 files changed, 11 insertions(+), 7 deletions(-) diff --git a/makefile b/makefile index 1182c976..f4310311 100644 --- a/makefile +++ b/makefile @@ -10,6 +10,8 @@ run: make -j 3 run-hapi run-hasura run-webapp run-env: + @fuser -k 3000/tcp + @fuser -k 9695/tcp @[ -f .env ] && source .env || echo "$(YELLOW)WARNING:$(RESET) .env file not found" run-postgres: diff --git a/webapp/src/components/LoginModal/Login.js b/webapp/src/components/LoginModal/Login.js index c0d50496..b0386ad8 100644 --- a/webapp/src/components/LoginModal/Login.js +++ b/webapp/src/components/LoginModal/Login.js @@ -133,7 +133,6 @@ const LoginModal = ({ isNavBar, isSideBar, isOutside }) => { password: user.secret } }) - if(isOutside) window.location.reload(); } const handleLoginWithAuth = async (status, email, secret) => { @@ -180,6 +179,7 @@ const LoginModal = ({ isNavBar, isSideBar, isOutside }) => { if (loginResult) { login(loginResult.token) setOpen(false) + if(isOutside) window.location.reload(); } }, [loginResult]) diff --git a/webapp/src/routes/EditProfile/EditProfile.js b/webapp/src/routes/EditProfile/EditProfile.js index c0f7e1bc..6df7e615 100644 --- a/webapp/src/routes/EditProfile/EditProfile.js +++ b/webapp/src/routes/EditProfile/EditProfile.js @@ -46,7 +46,7 @@ const EditProfilePage = () => { loadProfile, { error: errorProfile, loading, data: { profile: { profile } = {} } = {} } ] = useLazyQuery(PROFILE_QUERY, { fetchPolicy: 'network-only' }) - + console.log(currentUser) const [ revokeConsent, { @@ -153,7 +153,7 @@ const EditProfilePage = () => { return ( <> - {!profile && ()} + {!currentUser && ()} {isDesktop && ( {loading && } diff --git a/webapp/src/routes/HistoryDashboard/HistoryDashboard.js b/webapp/src/routes/HistoryDashboard/HistoryDashboard.js index a6585de8..ddd06243 100644 --- a/webapp/src/routes/HistoryDashboard/HistoryDashboard.js +++ b/webapp/src/routes/HistoryDashboard/HistoryDashboard.js @@ -66,7 +66,7 @@ const HistoryDashboard = (user) => { return ( <> - {errorReport && ()} + {!currentUser && ()} {t('historyDashboard.title')} diff --git a/webapp/src/routes/OffersManagement/OffersManagement.js b/webapp/src/routes/OffersManagement/OffersManagement.js index cfbbdac1..b4ff03f2 100644 --- a/webapp/src/routes/OffersManagement/OffersManagement.js +++ b/webapp/src/routes/OffersManagement/OffersManagement.js @@ -31,6 +31,7 @@ import { import OfferDetails from './OfferDetails' import GenericOfferFormComponent from './GenericOfferFormComponent' import LoginModal from '../../components/LoginModal' +import { useUser } from '../../context/user.context' import styles from './styles' const useStyles = makeStyles(styles) @@ -39,6 +40,7 @@ const OffersManagement = () => { const { t } = useTranslation('translations') const classes = useStyles() const history = useHistory() + const [currentUser] = useUser() const [offers, setOffers] = useState(undefined) const [profileIDLoaded, setProfileIDLoaded] = useState(false) const [offersLoaded, setOffersLoaded] = useState(false) @@ -115,7 +117,7 @@ const OffersManagement = () => { } const [ loadProfileID, - {error: profileError ,data: { profile: { profile } = {} } = {} } + {data: { profile: { profile } = {} } = {} } ] = useLazyQuery(PROFILE_ID_QUERY, { fetchPolicy: 'network-only' }) const [ @@ -408,7 +410,7 @@ const OffersManagement = () => { - {profileError && ()} + {!currentUser && ()} { return ( - {!profile && ()} + {!currentUser && ()} {messegaAlert} From 97d1ae2cf8ac495fb12d7165837d5c310f22883a Mon Sep 17 00:00:00 2001 From: Edgar097 Date: Wed, 30 Jun 2021 14:30:02 -0600 Subject: [PATCH 5/5] makefile --- makefile | 2 -- 1 file changed, 2 deletions(-) diff --git a/makefile b/makefile index f4310311..1182c976 100644 --- a/makefile +++ b/makefile @@ -10,8 +10,6 @@ run: make -j 3 run-hapi run-hasura run-webapp run-env: - @fuser -k 3000/tcp - @fuser -k 9695/tcp @[ -f .env ] && source .env || echo "$(YELLOW)WARNING:$(RESET) .env file not found" run-postgres: