| @@ -23,7 +23,7 @@ import HomePage from './pages/HomePage/HomePageMUI'; | |||
| import NotFoundPage from './pages/ErrorPages/NotFoundPage'; | |||
| import ErrorPage from './pages/ErrorPages/ErrorPage'; | |||
| import ForgotPasswordPage from './pages/ForgotPasswordPage/ForgotPasswordPage'; | |||
| // import PrivateRoute from './components/Router/PrivateRoute'; | |||
| import PrivateRoute from './components/Router/PrivateRoute'; | |||
| import MailSent from './pages/ForgotPasswordPage/ForgotPasswordMailSent/MailSent'; | |||
| import Register from './pages/RegisterPages/Register/Register'; | |||
| import RegisterSuccessful from './pages/RegisterPages/RegisterSuccessful.js/RegisterSuccessful'; | |||
| @@ -51,14 +51,9 @@ const AppRoutes = () => { | |||
| <Route path={ITEM_DETAILS_PAGE} component={ItemDetailsPage} /> | |||
| <Route path={PROFILE_PAGE} component={ProfilePage} /> | |||
| <Route path={HOME_PAGE} component={HomePage} /> | |||
| <Route path={CHAT_MESSAGE_PAGE} component={ChatMessagesPage} /> | |||
| <Route path={CHAT_PAGE} component={ChatPage} /> | |||
| {/* | |||
| <PrivateRoute | |||
| exact | |||
| path={HOME_PAGE} | |||
| component={HomePage} | |||
| /> */} | |||
| <PrivateRoute path={CHAT_MESSAGE_PAGE} component={ChatMessagesPage} /> | |||
| <PrivateRoute path={CHAT_PAGE} component={ChatPage} /> | |||
| <Redirect from="*" to={NOT_FOUND_PAGE} /> | |||
| </Switch> | |||
| )}; | |||
| @@ -33,6 +33,7 @@ const Offers = (props) => { | |||
| useEffect(() => { | |||
| if (history?.location?.state?.logo) { | |||
| dispatch(fetchOffers({queryString: ""})); | |||
| setPage(1); | |||
| history.location.state = undefined; | |||
| } | |||
| }, [history.location.state]) | |||
| @@ -1,6 +1,8 @@ | |||
| import React, { useEffect, useState } from "react"; | |||
| import { useTranslation } from "react-i18next"; | |||
| import { useDispatch, useSelector } from "react-redux"; | |||
| import { useHistory } from "react-router-dom"; | |||
| import { CHAT_PAGE } from "../../../constants/pages"; | |||
| import { fetchHeaderChats } from "../../../store/actions/chat/chatActions"; | |||
| import { selectLatestChats } from "../../../store/selectors/chatSelectors"; | |||
| import { selectUserId } from "../../../store/selectors/loginSelectors"; | |||
| @@ -20,6 +22,7 @@ export const MyMessages = () => { | |||
| const dispatch = useDispatch(); | |||
| const userId = useSelector(selectUserId); | |||
| const chats = useSelector(selectLatestChats); | |||
| const history = useHistory(); | |||
| const [lastChats, setLastChats] = useState([]); | |||
| useEffect(() => { | |||
| @@ -32,10 +35,14 @@ export const MyMessages = () => { | |||
| setLastChats([...convertMessages(chats)]); | |||
| } | |||
| }, [chats]); | |||
| const goToMessages = () => { | |||
| history.push(CHAT_PAGE); | |||
| } | |||
| return ( | |||
| <HeaderPopover | |||
| title={t("header.myMessages")} | |||
| items={lastChats} | |||
| buttonOnClick={goToMessages} | |||
| buttonText={t("header.checkEverything")} | |||
| /> | |||
| ); | |||
| @@ -1,23 +1,22 @@ | |||
| import React, { useEffect } from 'react'; | |||
| import React, { useEffect, useMemo } from 'react'; | |||
| import { Redirect, Route } from 'react-router'; | |||
| import { useDispatch, useSelector } from 'react-redux'; | |||
| import { authenticateUser } from '../../store/actions/login/loginActions'; | |||
| // import { selectIsUserAuthenticated } from '../../store/selectors/userSelectors'; | |||
| import { logoutUser } from '../../store/actions/login/loginActions'; | |||
| import { LOGIN_PAGE } from '../../constants/pages'; | |||
| import { fetchProfile } from '../../store/actions/profile/profileActions'; | |||
| import { selectUserId } from '../../store/selectors/loginSelectors'; | |||
| const PrivateRoute = ({ ...props }) => { | |||
| const dispatch = useDispatch(); | |||
| const userId = useSelector(selectUserId); | |||
| // const isUserAuthenticated = useSelector(selectIsUserAuthenticated); | |||
| const isUserAuthenticated = true; | |||
| const isUserAuthenticated = useMemo(() => { | |||
| if (userId?.length === 0) return false; | |||
| return true; | |||
| }) | |||
| useEffect(() => { | |||
| if (!isUserAuthenticated) { | |||
| dispatch(authenticateUser()); | |||
| } else { | |||
| dispatch(fetchProfile(userId)) | |||
| dispatch(logoutUser()); | |||
| } | |||
| }, [isUserAuthenticated]); // eslint-disable-line | |||
| @@ -1,16 +1,5 @@ | |||
| import React from "react"; | |||
| // import Navbar from "../../components/MUI/NavbarComponent"; | |||
| // import FilterCard from "../../components/Cards/FilterCard/FilterCard"; | |||
| import { HomePageContainer } from "./HomePage.styled"; | |||
| // import MarketPlace from "../../components/MarketPlace/MarketPlace"; | |||
| // import MainLayout from "../../layouts/MainLayout/MainLayout"; | |||
| // import { useDispatch } from "react-redux"; | |||
| // // import { logoutUser } from "../../store/actions/login/loginActions"; | |||
| // import Mockupdata from "../../components/Cards/FilterCard/Mockupdata"; | |||
| // import qs from "query-string"; | |||
| // import { useHistory } from "react-router-dom"; | |||
| // import { setFilters } from "../../store/actions/filters/filtersActions"; | |||
| // import ProfileLayout from "../../layouts/ProfileLayout/ProfileLayout"; | |||
| import FilterCard from "../../components/Cards/FilterCard/FilterCard"; | |||
| import MainLayout from "../../layouts/MainLayout/MainLayout"; | |||
| import MarketPlace from "../../components/MarketPlace/MarketPlace"; | |||
| @@ -24,44 +13,3 @@ const HomePage = () => { | |||
| } | |||
| export default HomePage; | |||
| // import React from 'react'; | |||
| // import { Box } from '@mui/material'; | |||
| // import Navbar from '../../components/MUI/NavbarComponent'; | |||
| // import Modals from '../../components/MUI/Examples/ModalsExample'; | |||
| // import DataGrid from '../../components/MUI/Examples/DataGridExample'; | |||
| // import PagingSortingFiltering from '../../components/MUI/Examples/PagingSortingFilteringExample'; | |||
| // import PagingSortingFilteringServerSide from '../../components/MUI/Examples/PagingSortingFilteringExampleServerSide'; | |||
| // import RandomDataProvider from '../../context/RandomDataContext'; | |||
| // import { GridStyled } from './HomePage.styled'; | |||
| // import OfferCard from '../../components/Cards/OfferCard/OfferCard'; | |||
| // const HomePage = () => { | |||
| // return ( | |||
| // <> | |||
| // <Navbar /> | |||
| // <OfferCard /> | |||
| // <Box sx={{ mt: 4, mx: 4 }}> | |||
| // <GridStyled container spacing={2} justifyContent="center"> | |||
| // <GridStyled item xs={12} md={3}> | |||
| // <Modals /> | |||
| // </GridStyled> | |||
| // <GridStyled item xs={12} md={6}> | |||
| // <DataGrid /> | |||
| // </GridStyled> | |||
| // <GridStyled item xs={12} md={9}> | |||
| // <PagingSortingFiltering /> | |||
| // </GridStyled> | |||
| // <GridStyled item xs={12} md={9}> | |||
| // {/* Move to higher components? */} | |||
| // <RandomDataProvider> | |||
| // <PagingSortingFilteringServerSide /> | |||
| // </RandomDataProvider> | |||
| // </GridStyled> | |||
| // </GridStyled> | |||
| // </Box> | |||
| // </> | |||
| // ); | |||
| // }; | |||
| @@ -35,6 +35,7 @@ export default ({ dispatch }) => | |||
| // If refresh token is expired, log out user | |||
| if (new Date() > new Date(refreshTokenDecoded?.exp * 1000)) { | |||
| console.log('zato') | |||
| dispatch(logoutUser()); | |||
| } | |||
| // If access token is expired, refresh access token | |||
| @@ -14,7 +14,7 @@ export default ({ dispatch }) => (next) => (action) => { | |||
| error.response.config.url !== apiEndpoints.authentications.login && | |||
| error.response.config.url !== | |||
| apiEndpoints.authentications.confirmSecurityQuestion && | |||
| error.response.status === 401 | |||
| error.response.status === 4003 | |||
| ) { | |||
| return dispatch(logoutUser()); | |||
| } | |||