| }) | }) | ||||
| ); | ); | ||||
| }; | }; | ||||
| const routeToItem = (itemId) => { | |||||
| const routeToItem = (event, itemId) => { | |||||
| event.stopPropagation(); | |||||
| if (!props.disabledCheckButton) { | if (!props.disabledCheckButton) { | ||||
| if (props.isAdmin) { | if (props.isAdmin) { | ||||
| history.push( | history.push( | ||||
| : props?.offer?.pinned?.toString() | : props?.offer?.pinned?.toString() | ||||
| } | } | ||||
| halfwidth={props.halfwidth ? 1 : 0} | halfwidth={props.halfwidth ? 1 : 0} | ||||
| onClick={() => routeToItem(props?.offer?._id)} | |||||
| onClick={(event) => routeToItem(event, props?.offer?._id)} | |||||
| > | > | ||||
| {/* This only shows on vertical offer card */} | {/* This only shows on vertical offer card */} | ||||
| <OfferTitleAboveImage | <OfferTitleAboveImage | ||||
| ? 2 | ? 2 | ||||
| : 1 | : 1 | ||||
| } | } | ||||
| onClick={() => routeToItem(props?.offer?._id)} | |||||
| onClick={(event) => routeToItem(event, props?.offer?._id)} | |||||
| > | > | ||||
| {props?.offer?.name} | {props?.offer?.name} | ||||
| </OfferTitleAboveImage> | </OfferTitleAboveImage> | ||||
| <OfferInfo vertical={props.vertical}> | <OfferInfo vertical={props.vertical}> | ||||
| <OfferTitle | <OfferTitle | ||||
| vertical={props.vertical} | vertical={props.vertical} | ||||
| onClick={() => routeToItem(props?.offer?._id)} | |||||
| onClick={(event) => routeToItem(event, props?.offer?._id)} | |||||
| > | > | ||||
| {props?.offer?.name} | {props?.offer?.name} | ||||
| </OfferTitle> | </OfferTitle> |
| const { t } = useTranslation(); | const { t } = useTranslation(); | ||||
| const handleBackButton = () => { | const handleBackButton = () => { | ||||
| console.log("clicked") | |||||
| history.goBack(); | history.goBack(); | ||||
| }; | }; | ||||
| import { useDispatch, useSelector } from "react-redux"; | import { useDispatch, useSelector } from "react-redux"; | ||||
| import { useHistory } from "react-router-dom"; | import { useHistory } from "react-router-dom"; | ||||
| import { fetchHeaderChats } from "../../../store/actions/chat/chatActions"; | import { fetchHeaderChats } from "../../../store/actions/chat/chatActions"; | ||||
| import { selectLatestChats } from "../../../store/selectors/chatSelectors"; | |||||
| import { | |||||
| selectLatestChats, | |||||
| selectSelectedChat, | |||||
| } from "../../../store/selectors/chatSelectors"; | |||||
| import { selectUserId } from "../../../store/selectors/loginSelectors"; | import { selectUserId } from "../../../store/selectors/loginSelectors"; | ||||
| import HeaderPopover from "../HeaderPopover/HeaderPopover"; | import HeaderPopover from "../HeaderPopover/HeaderPopover"; | ||||
| import PropTypes from "prop-types"; | import PropTypes from "prop-types"; | ||||
| import { makeErrorToastMessage } from "../../../store/utils/makeToastMessage"; | import { makeErrorToastMessage } from "../../../store/utils/makeToastMessage"; | ||||
| import { EyeIcon } from "./MyMessages.styled"; | import { EyeIcon } from "./MyMessages.styled"; | ||||
| import { DIRECT_CHAT_PAGE } from "../../../constants/pages"; | import { DIRECT_CHAT_PAGE } from "../../../constants/pages"; | ||||
| import { replaceInRoute } from "../../../util/helpers/routeHelpers"; | |||||
| import { | |||||
| dynamicRouteMatches, | |||||
| replaceInRoute, | |||||
| } from "../../../util/helpers/routeHelpers"; | |||||
| export const MyMessages = (props) => { | export const MyMessages = (props) => { | ||||
| const { t } = useTranslation(); | const { t } = useTranslation(); | ||||
| const dispatch = useDispatch(); | const dispatch = useDispatch(); | ||||
| const userId = useSelector(selectUserId); | const userId = useSelector(selectUserId); | ||||
| const chats = useSelector(selectLatestChats); | const chats = useSelector(selectLatestChats); | ||||
| const selectedChat = useSelector(selectSelectedChat); | |||||
| const history = useHistory(); | const history = useHistory(); | ||||
| const [lastChats, setLastChats] = useState([]); | const [lastChats, setLastChats] = useState([]); | ||||
| const goToMessages = () => { | const goToMessages = () => { | ||||
| if (lastChats.length !== 0) { | if (lastChats.length !== 0) { | ||||
| console.log(chats); | console.log(chats); | ||||
| history.push({ | |||||
| pathname: replaceInRoute(DIRECT_CHAT_PAGE, { | |||||
| chatId: chats[0]._id, | |||||
| }), | |||||
| }); | |||||
| props.closePopover(); | |||||
| goToMessage(chats[0]?._id) | |||||
| } else { | } else { | ||||
| makeErrorToastMessage(t("messages.noMessagesToast")); | makeErrorToastMessage(t("messages.noMessagesToast")); | ||||
| props.closePopover(); | props.closePopover(); | ||||
| } | } | ||||
| }; | }; | ||||
| const goToMessage = (chatId) => { | const goToMessage = (chatId) => { | ||||
| history.push( | |||||
| replaceInRoute(DIRECT_CHAT_PAGE, { | |||||
| chatId, | |||||
| }) | |||||
| ); | |||||
| if ( | |||||
| !dynamicRouteMatches(DIRECT_CHAT_PAGE) || | |||||
| selectedChat?._id !== chatId | |||||
| ) { | |||||
| history.push( | |||||
| replaceInRoute(DIRECT_CHAT_PAGE, { | |||||
| chatId, | |||||
| }) | |||||
| ); | |||||
| } | |||||
| props.closePopover(); | props.closePopover(); | ||||
| }; | }; | ||||
| return ( | return ( |
| import HeaderPopover from "../HeaderPopover/HeaderPopover"; | import HeaderPopover from "../HeaderPopover/HeaderPopover"; | ||||
| import { useTranslation } from "react-i18next"; | import { useTranslation } from "react-i18next"; | ||||
| import { useDispatch, useSelector } from "react-redux"; | import { useDispatch, useSelector } from "react-redux"; | ||||
| import { selectMineHeaderOffers } from "../../../store/selectors/offersSelectors"; | |||||
| import { selectMineHeaderOffers, selectOffer } from "../../../store/selectors/offersSelectors"; | |||||
| import { fetchMineHeaderOffers } from "../../../store/actions/offers/offersActions"; | import { fetchMineHeaderOffers } from "../../../store/actions/offers/offersActions"; | ||||
| import { selectProfileName } from "../../../store/selectors/profileSelectors"; | import { selectProfileName } from "../../../store/selectors/profileSelectors"; | ||||
| import { useHistory } from "react-router-dom"; | import { useHistory } from "react-router-dom"; | ||||
| import { ITEM_DETAILS_PAGE, MY_OFFERS_PAGE } from "../../../constants/pages"; | import { ITEM_DETAILS_PAGE, MY_OFFERS_PAGE } from "../../../constants/pages"; | ||||
| import { useMemo } from "react"; | import { useMemo } from "react"; | ||||
| import { replaceInRoute } from "../../../util/helpers/routeHelpers"; | |||||
| import { dynamicRouteMatches, replaceInRoute, routeMatches } from "../../../util/helpers/routeHelpers"; | |||||
| export const MyPosts = (props) => { | export const MyPosts = (props) => { | ||||
| const { t } = useTranslation(); | const { t } = useTranslation(); | ||||
| const dispatch = useDispatch(); | const dispatch = useDispatch(); | ||||
| const mineOffers = useSelector(selectMineHeaderOffers); | const mineOffers = useSelector(selectMineHeaderOffers); | ||||
| const name = useSelector(selectProfileName); | const name = useSelector(selectProfileName); | ||||
| const offer = useSelector(selectOffer); | |||||
| const history = useHistory(); | const history = useHistory(); | ||||
| const [arrayOfMineOffers, setArrayOfMineOffers] = useState([]); | const [arrayOfMineOffers, setArrayOfMineOffers] = useState([]); | ||||
| useEffect(() => { | useEffect(() => { | ||||
| }, [arrayOfMineOffers, mineOffers]); | }, [arrayOfMineOffers, mineOffers]); | ||||
| const goToOffer = (id) => { | const goToOffer = (id) => { | ||||
| history.push( | |||||
| replaceInRoute(ITEM_DETAILS_PAGE, { | |||||
| offerId: id, | |||||
| }) | |||||
| ); | |||||
| if (!dynamicRouteMatches(ITEM_DETAILS_PAGE) || offer?._id !== id) { | |||||
| history.push( | |||||
| replaceInRoute(ITEM_DETAILS_PAGE, { | |||||
| offerId: id, | |||||
| }) | |||||
| ); | |||||
| } | |||||
| props.closePopover(); | props.closePopover(); | ||||
| }; | }; | ||||
| const goToMySwaps = () => { | const goToMySwaps = () => { | ||||
| history.push(MY_OFFERS_PAGE); | |||||
| if (!routeMatches(MY_OFFERS_PAGE)) { | |||||
| history.push(MY_OFFERS_PAGE); | |||||
| } | |||||
| props.closePopover(); | props.closePopover(); | ||||
| }; | }; | ||||
| return ( | return ( |
| import { InfoIcon } from "./AboutButton.styled"; | import { InfoIcon } from "./AboutButton.styled"; | ||||
| import { useHistory } from "react-router-dom"; | import { useHistory } from "react-router-dom"; | ||||
| import scrollConstants from "../../../../constants/scrollConstants"; | import scrollConstants from "../../../../constants/scrollConstants"; | ||||
| import { routeMatches } from "../../../../util/helpers/routeHelpers"; | |||||
| const AboutButton = (props) => { | const AboutButton = (props) => { | ||||
| const { t } = useTranslation(); | const { t } = useTranslation(); | ||||
| const history = useHistory(); | const history = useHistory(); | ||||
| const seeAbout = () => { | const seeAbout = () => { | ||||
| history.push({ | |||||
| pathname: ABOUT_PAGE, | |||||
| state: { | |||||
| navigation: scrollConstants.about.aboutPage, | |||||
| clicked: true, | |||||
| } | |||||
| }); | |||||
| if (!routeMatches(ABOUT_PAGE)) { | |||||
| history.push({ | |||||
| pathname: ABOUT_PAGE, | |||||
| state: { | |||||
| navigation: scrollConstants.about.aboutPage, | |||||
| clicked: true, | |||||
| }, | |||||
| }); | |||||
| } else { | |||||
| history.replace({ | |||||
| state: { | |||||
| clicked: true, | |||||
| navigation: scrollConstants.about.aboutPage, | |||||
| }, | |||||
| }); | |||||
| } | |||||
| props.closePopover(); | props.closePopover(); | ||||
| }; | }; | ||||
| return ( | return ( |
| import HeaderPopover from "../HeaderPopover/HeaderPopover"; | import HeaderPopover from "../HeaderPopover/HeaderPopover"; | ||||
| import { useTranslation } from "react-i18next"; | import { useTranslation } from "react-i18next"; | ||||
| import { useDispatch, useSelector } from "react-redux"; | import { useDispatch, useSelector } from "react-redux"; | ||||
| import { selectMineProfile } from "../../../store/selectors/profileSelectors"; | |||||
| import { | |||||
| selectMineProfile, | |||||
| selectProfile, | |||||
| } from "../../../store/selectors/profileSelectors"; | |||||
| import { | import { | ||||
| selectRoles, | selectRoles, | ||||
| selectUserId, | selectUserId, | ||||
| import PrivacyPolicyButton from "./PrivacyPolicyButton/PrivacyPolicyButton"; | import PrivacyPolicyButton from "./PrivacyPolicyButton/PrivacyPolicyButton"; | ||||
| import PricesButton from "./PricesButton/PricesButton"; | import PricesButton from "./PricesButton/PricesButton"; | ||||
| import { ADMIN_HOME_PAGE, PROFILE_PAGE } from "../../../constants/pages"; | import { ADMIN_HOME_PAGE, PROFILE_PAGE } from "../../../constants/pages"; | ||||
| import { replaceInRoute } from "../../../util/helpers/routeHelpers"; | |||||
| import { | |||||
| dynamicRouteMatches, | |||||
| replaceInRoute, | |||||
| } from "../../../util/helpers/routeHelpers"; | |||||
| export const MyProfile = (props) => { | export const MyProfile = (props) => { | ||||
| const { t } = useTranslation(); | const { t } = useTranslation(); | ||||
| const profile = useSelector(selectMineProfile); | const profile = useSelector(selectMineProfile); | ||||
| const selectedProfile = useSelector(selectProfile); | |||||
| const userId = useSelector(selectUserId); | const userId = useSelector(selectUserId); | ||||
| const dispatch = useDispatch(); | const dispatch = useDispatch(); | ||||
| const history = useHistory(); | const history = useHistory(); | ||||
| } | } | ||||
| }, [profile]); | }, [profile]); | ||||
| const seeMyProfile = () => { | const seeMyProfile = () => { | ||||
| history.push(replaceInRoute(PROFILE_PAGE, { | |||||
| profileId: userId | |||||
| })); | |||||
| if (!dynamicRouteMatches(PROFILE_PAGE) || selectedProfile?._id !== userId) | |||||
| history.push( | |||||
| replaceInRoute(PROFILE_PAGE, { | |||||
| profileId: userId, | |||||
| }) | |||||
| ); | |||||
| props.closePopover(); | props.closePopover(); | ||||
| }; | }; | ||||
| const goToAdminHome = () => { | const goToAdminHome = () => { |
| import { PopoverButton } from "../../HeaderPopover/HeaderPopover.styled"; | import { PopoverButton } from "../../HeaderPopover/HeaderPopover.styled"; | ||||
| import { useHistory } from "react-router-dom"; | import { useHistory } from "react-router-dom"; | ||||
| import scrollConstants from "../../../../constants/scrollConstants"; | import scrollConstants from "../../../../constants/scrollConstants"; | ||||
| import { routeMatches } from "../../../../util/helpers/routeHelpers"; | |||||
| const PricesButton = (props) => { | const PricesButton = (props) => { | ||||
| const { t } = useTranslation(); | const { t } = useTranslation(); | ||||
| const history = useHistory(); | const history = useHistory(); | ||||
| const seePrices = () => { | const seePrices = () => { | ||||
| history.push({ | |||||
| pathname: ABOUT_PAGE, | |||||
| state: { | |||||
| navigation: scrollConstants.about.pricesPage, | |||||
| clicked: true, | |||||
| }, | |||||
| }); | |||||
| if (!routeMatches(ABOUT_PAGE)) { | |||||
| history.push({ | |||||
| pathname: ABOUT_PAGE, | |||||
| state: { | |||||
| navigation: scrollConstants.about.pricesPage, | |||||
| clicked: true, | |||||
| }, | |||||
| }); | |||||
| } else { | |||||
| history.replace({ | |||||
| state: { | |||||
| clicked: true, | |||||
| navigation: scrollConstants.about.pricesPage, | |||||
| }, | |||||
| }); | |||||
| } | |||||
| props.closePopover(); | props.closePopover(); | ||||
| }; | }; | ||||
| return ( | return ( |
| import { useTranslation } from "react-i18next"; | import { useTranslation } from "react-i18next"; | ||||
| import { useHistory } from "react-router-dom"; | import { useHistory } from "react-router-dom"; | ||||
| import scrollConstants from "../../../../constants/scrollConstants"; | import scrollConstants from "../../../../constants/scrollConstants"; | ||||
| import { routeMatches } from "../../../../util/helpers/routeHelpers"; | |||||
| const PrivacyPolicyButton = (props) => { | const PrivacyPolicyButton = (props) => { | ||||
| const { t } = useTranslation(); | const { t } = useTranslation(); | ||||
| const history = useHistory(); | const history = useHistory(); | ||||
| const seePrivacy = () => { | const seePrivacy = () => { | ||||
| history.push({ | |||||
| pathname: ABOUT_PAGE, | |||||
| state: { | |||||
| clicked: true, | |||||
| navigation: scrollConstants.about.privacyPolicyPage, | |||||
| }, | |||||
| }); | |||||
| if (!routeMatches(ABOUT_PAGE)) { | |||||
| history.push({ | |||||
| pathname: ABOUT_PAGE, | |||||
| state: { | |||||
| clicked: true, | |||||
| navigation: scrollConstants.about.privacyPolicyPage, | |||||
| }, | |||||
| }); | |||||
| } else { | |||||
| history.replace({ | |||||
| state: { | |||||
| clicked: true, | |||||
| navigation: scrollConstants.about.privacyPolicyPage, | |||||
| } | |||||
| }) | |||||
| } | |||||
| props.closePopover(); | props.closePopover(); | ||||
| }; | }; | ||||
| return ( | return ( |