| const ItemDetailsCard = (props) => { | const ItemDetailsCard = (props) => { | ||||
| const [showModalRemove, setShowModalRemove] = useState(false); | const [showModalRemove, setShowModalRemove] = useState(false); | ||||
| const [showModalEdit, setShowModalEdit] = useState(false); | const [showModalEdit, setShowModalEdit] = useState(false); | ||||
| const [isMyProfile, setIsMyProfile] = useState(false); | |||||
| const offer = props.offer; | const offer = props.offer; | ||||
| const chats = useSelector(selectLatestChats); | const chats = useSelector(selectLatestChats); | ||||
| const userId = useSelector(selectUserId); | const userId = useSelector(selectUserId); | ||||
| const { t } = useTranslation(); | const { t } = useTranslation(); | ||||
| const dispatch = useDispatch(); | const dispatch = useDispatch(); | ||||
| const idProfile = offer?.offer?.userId; | |||||
| const increaseOfferCounter = useMemo(() => { | const increaseOfferCounter = useMemo(() => { | ||||
| return _.once(function (id) { | return _.once(function (id) { | ||||
| } | } | ||||
| }, [offer]); | }, [offer]); | ||||
| useEffect(() => { | |||||
| if (userId === idProfile) setIsMyProfile(true); | |||||
| }, [userId, idProfile]); | |||||
| const date = formatDateLocale(new Date(offer?.offer?._created)); | const date = formatDateLocale(new Date(offer?.offer?._created)); | ||||
| </Info> | </Info> | ||||
| <DateButtonsContainer> | <DateButtonsContainer> | ||||
| <PostDate>{date}</PostDate> | <PostDate>{date}</PostDate> | ||||
| {isMyProfile && ( | |||||
| {props.isMyOffer && ( | |||||
| <ButtonsContainer> | <ButtonsContainer> | ||||
| <EditDeleteButtons> | <EditDeleteButtons> | ||||
| <EditIconContainer onClick={() => setShowModalEdit(true)}> | <EditIconContainer onClick={() => setShowModalEdit(true)}> | ||||
| buttoncolor={selectedTheme.primaryPurple} | buttoncolor={selectedTheme.primaryPurple} | ||||
| textcolor={props.sponsored ? "white" : selectedTheme.primaryPurple} | textcolor={props.sponsored ? "white" : selectedTheme.primaryPurple} | ||||
| onClick={startExchange} | onClick={startExchange} | ||||
| disabled={props.isMyOffer} | |||||
| > | > | ||||
| {t("itemDetailsCard.startExchangeButton")} | {t("itemDetailsCard.startExchangeButton")} | ||||
| </CheckButton> | </CheckButton> | ||||
| showBarterButton: PropTypes.bool, | showBarterButton: PropTypes.bool, | ||||
| showPublishButton: PropTypes.bool, | showPublishButton: PropTypes.bool, | ||||
| className: PropTypes.string, | className: PropTypes.string, | ||||
| isMyOffer: PropTypes.bool, | |||||
| }; | }; | ||||
| ItemDetailsCard.defaultProps = { | ItemDetailsCard.defaultProps = { | ||||
| halfwidth: false, | halfwidth: false, |
| right: 12px; | right: 12px; | ||||
| font-weight: 600; | font-weight: 600; | ||||
| &:hover button { | &:hover button { | ||||
| background-color: ${selectedTheme.primaryPurple} !important; | |||||
| color: white !important; | color: white !important; | ||||
| background-color: ${props => !props.disabled ? selectedTheme.primaryPurple : selectedTheme.primaryPurpleDisabled} !important; | |||||
| } | } | ||||
| @media (max-width: 600px) { | @media (max-width: 600px) { | ||||
| height: 44px; | height: 44px; |
| import React, { useEffect } from "react"; | |||||
| import React, { useEffect, useState } from "react"; | |||||
| import { PropTypes } from "prop-types"; | import { PropTypes } from "prop-types"; | ||||
| import { ItemDetailsPageContainer } from "./ItemDetailsPage.styled"; | import { ItemDetailsPageContainer } from "./ItemDetailsPage.styled"; | ||||
| import { useDispatch, useSelector } from "react-redux"; | import { useDispatch, useSelector } from "react-redux"; | ||||
| import ItemDetails from "../../components/ItemDetails/ItemDetails"; | import ItemDetails from "../../components/ItemDetails/ItemDetails"; | ||||
| import ItemDetailsLayout from "../../layouts/ItemDetailsLayout/ItemDetailsLayout"; | import ItemDetailsLayout from "../../layouts/ItemDetailsLayout/ItemDetailsLayout"; | ||||
| import { fetchOneOffer } from "../../store/actions/offers/offersActions"; | |||||
| import { clearSelectedOffer, fetchOneOffer } from "../../store/actions/offers/offersActions"; | |||||
| import UserReviews from "../../components/UserReviews/UserReviews"; | import UserReviews from "../../components/UserReviews/UserReviews"; | ||||
| import { selectOffer } from "../../store/selectors/offersSelectors"; | import { selectOffer } from "../../store/selectors/offersSelectors"; | ||||
| const ItemDetailsPage = (props) => { | const ItemDetailsPage = (props) => { | ||||
| const dispatch = useDispatch(); | const dispatch = useDispatch(); | ||||
| const selectedOffer = useSelector(selectOffer); | const selectedOffer = useSelector(selectOffer); | ||||
| const [isInitiallyLoaded, setIsInitiallyLoaded] = useState(false); | |||||
| const offerId = props.match.params.idProizvod; | const offerId = props.match.params.idProizvod; | ||||
| useEffect(() => { | useEffect(() => { | ||||
| if (offerId && !selectedOffer?.offer) { | |||||
| dispatch(fetchOneOffer(offerId)); | |||||
| () => dispatch(clearSelectedOffer()); | |||||
| }, []); | |||||
| useEffect(() => { | |||||
| console.log("effect: selectedOffer", selectedOffer, " isInitiallyLoaded: ", isInitiallyLoaded) | |||||
| if (!selectedOffer?.offer && isInitiallyLoaded) { | |||||
| dispatch(fetchOneOffer(offerId)); | dispatch(fetchOneOffer(offerId)); | ||||
| } | } | ||||
| }, [offerId, selectedOffer?.offer]); | |||||
| if (selectedOffer?.offer) { | |||||
| setIsInitiallyLoaded(true); | |||||
| } | |||||
| }, [selectedOffer?.offer]); | |||||
| return ( | return ( | ||||
| <ItemDetailsPageContainer> | <ItemDetailsPageContainer> |
| export const OFFER_INDEX_CLEAR = createClearType("OFFER_INDEX_CLEAR"); | export const OFFER_INDEX_CLEAR = createClearType("OFFER_INDEX_CLEAR"); | ||||
| export const OFFER_PAGE_SET = createSetType("OFFER_PAGE_SET"); | export const OFFER_PAGE_SET = createSetType("OFFER_PAGE_SET"); | ||||
| export const OFFER_FEATURED_PAGE_SET = createSetType("OFFER_FEATURED_PAGE_SET"); | export const OFFER_FEATURED_PAGE_SET = createSetType("OFFER_FEATURED_PAGE_SET"); | ||||
| export const OFFER_SELECTED_CLEAR = createClearType("OFFER_SELECTED_CLEAR") | |||||
| export const OFFER_ADD_SCOPE = "OFFER_ADD_SCOPE"; | export const OFFER_ADD_SCOPE = "OFFER_ADD_SCOPE"; | ||||
| export const OFFER_ADD = createFetchType(OFFER_ADD_SCOPE); | export const OFFER_ADD = createFetchType(OFFER_ADD_SCOPE); |
| OFFER_REMOVE, | OFFER_REMOVE, | ||||
| OFFER_REMOVE_ERROR, | OFFER_REMOVE_ERROR, | ||||
| OFFER_REMOVE_SUCCESS, | OFFER_REMOVE_SUCCESS, | ||||
| OFFER_SELECTED_CLEAR, | |||||
| OFFER_SET, | OFFER_SET, | ||||
| ONE_OFFER_ERROR, | ONE_OFFER_ERROR, | ||||
| ONE_OFFER_FETCH, | ONE_OFFER_FETCH, | ||||
| type: OFFER_FEATURED_PAGE_SET, | type: OFFER_FEATURED_PAGE_SET, | ||||
| payload | payload | ||||
| }) | }) | ||||
| export const clearSelectedOffer = () => ({ | |||||
| type: OFFER_SELECTED_CLEAR | |||||
| }) |
| OFFERS_SET, | OFFERS_SET, | ||||
| OFFER_ADD, | OFFER_ADD, | ||||
| OFFER_SET, | OFFER_SET, | ||||
| ONE_OFFER_FETCH, | |||||
| ONE_OFFER_ERROR, | ONE_OFFER_ERROR, | ||||
| ONE_OFFER_SUCCESS, | ONE_OFFER_SUCCESS, | ||||
| OFFERS_SET_TOTAL, | OFFERS_SET_TOTAL, | ||||
| OFFER_INDEX_CLEAR, | OFFER_INDEX_CLEAR, | ||||
| OFFER_PAGE_SET, | OFFER_PAGE_SET, | ||||
| OFFER_FEATURED_PAGE_SET, | OFFER_FEATURED_PAGE_SET, | ||||
| OFFER_SELECTED_CLEAR, | |||||
| } from "../../actions/offers/offersActionConstants"; | } from "../../actions/offers/offersActionConstants"; | ||||
| import createReducer from "../../utils/createReducer"; | import createReducer from "../../utils/createReducer"; | ||||
| [OFFER_SET]: setOffer, | [OFFER_SET]: setOffer, | ||||
| [ONE_OFFER_ERROR]: fetchOneOfferError, | [ONE_OFFER_ERROR]: fetchOneOfferError, | ||||
| [ONE_OFFER_SUCCESS]: fetchOneOfferSuccess, | [ONE_OFFER_SUCCESS]: fetchOneOfferSuccess, | ||||
| [ONE_OFFER_FETCH]: fetchOneOffer, | |||||
| [OFFERS_NO_MORE]: setNoMoreOffersStatus, | [OFFERS_NO_MORE]: setNoMoreOffersStatus, | ||||
| [OFFERS_PINNED_ADD]: addPinnedOffers, | [OFFERS_PINNED_ADD]: addPinnedOffers, | ||||
| [OFFERS_PINNED_SET]: setPinnedOffers, | [OFFERS_PINNED_SET]: setPinnedOffers, | ||||
| [OFFER_INDEX_CLEAR]: clearOfferIndex, | [OFFER_INDEX_CLEAR]: clearOfferIndex, | ||||
| [OFFER_PAGE_SET]: setOfferPage, | [OFFER_PAGE_SET]: setOfferPage, | ||||
| [OFFER_FEATURED_PAGE_SET]: setFeaturedOfferPage, | [OFFER_FEATURED_PAGE_SET]: setFeaturedOfferPage, | ||||
| [OFFER_SELECTED_CLEAR]: clearSelectedOffer, | |||||
| }, | }, | ||||
| initialState | initialState | ||||
| ); | ); | ||||
| offer: action.payload, | offer: action.payload, | ||||
| }; | }; | ||||
| } | } | ||||
| function fetchOneOffer(state, action) { | |||||
| return { | |||||
| ...state, | |||||
| selectedOffer: action.payload, | |||||
| }; | |||||
| } | |||||
| function fetchOneOfferSuccess(state, action) { | function fetchOneOfferSuccess(state, action) { | ||||
| return { | return { | ||||
| ...state, | ...state, | ||||
| function setFeaturedOffers(state, action) { | function setFeaturedOffers(state, action) { | ||||
| return { | return { | ||||
| ...state, | ...state, | ||||
| pinnedOffers: action.payload | |||||
| } | |||||
| pinnedOffers: action.payload, | |||||
| }; | |||||
| } | } | ||||
| function clearFeaturedOffers(state) { | function clearFeaturedOffers(state) { | ||||
| return { | return { | ||||
| ...state, | ...state, | ||||
| pinnedOffers: [] | |||||
| } | |||||
| pinnedOffers: [], | |||||
| }; | |||||
| } | } | ||||
| function setOfferIndex(state, {payload}) { | |||||
| function setOfferIndex(state, { payload }) { | |||||
| return { | return { | ||||
| ...state, | ...state, | ||||
| offerIndex: payload | |||||
| } | |||||
| offerIndex: payload, | |||||
| }; | |||||
| } | } | ||||
| function clearOfferIndex(state) { | function clearOfferIndex(state) { | ||||
| return { | return { | ||||
| ...state, | ...state, | ||||
| offerIndex: null, | offerIndex: null, | ||||
| } | |||||
| }; | |||||
| } | |||||
| function setOfferPage(state, { payload }) { | |||||
| return { | |||||
| ...state, | |||||
| offerPage: payload, | |||||
| }; | |||||
| } | } | ||||
| function setOfferPage(state, {payload}) { | |||||
| function setFeaturedOfferPage(state, { payload }) { | |||||
| return { | return { | ||||
| ...state, | ...state, | ||||
| offerPage: payload | |||||
| } | |||||
| featuredOfferPage: payload, | |||||
| }; | |||||
| } | } | ||||
| function setFeaturedOfferPage(state, {payload}) { | |||||
| function clearSelectedOffer(state) { | |||||
| return { | return { | ||||
| ...state, | ...state, | ||||
| featuredOfferPage: payload | |||||
| } | |||||
| selectedOffer: "", | |||||
| }; | |||||
| } | } |