| @@ -35,7 +35,10 @@ import { | |||
| ITEM_DETAILS_PAGE, | |||
| PROFILE_PAGE, | |||
| } from "../../../constants/pages"; | |||
| import { dynamicRouteMatches, replaceInRoute } from "../../../util/helpers/routeHelpers"; | |||
| import { | |||
| dynamicRouteMatches, | |||
| replaceInRoute, | |||
| } from "../../../util/helpers/routeHelpers"; | |||
| import { selectIsLoadingByActionType } from "../../../store/selectors/loadingSelectors"; | |||
| import { | |||
| OFFER_ADD_SCOPE, | |||
| @@ -64,8 +67,12 @@ const CreateOffer = ({ editOffer, offer, isAdmin, customUserId }) => { | |||
| if (editOffer) { | |||
| if (routeMatches(BASE_PAGE) || routeMatches(HOME_PAGE)) | |||
| dispatch(fetchOffers({ queryString })); | |||
| if (dynamicRouteMatches(PROFILE_PAGE) || dynamicRouteMatches(ADMIN_SINGLE_USER_PAGE)) | |||
| if (isAdmin) dispatch(fetchProfileOffers(customUserId)); | |||
| if ( | |||
| dynamicRouteMatches(PROFILE_PAGE) || | |||
| dynamicRouteMatches(ADMIN_SINGLE_USER_PAGE) | |||
| ) | |||
| if (isAdmin) | |||
| dispatch(fetchProfileOffers({ idProfile: customUserId, isAdmin })); | |||
| else dispatch(fetchProfileOffers(userId)); | |||
| if ( | |||
| @@ -108,6 +108,7 @@ const ItemDetailsCard = (props) => { | |||
| ); | |||
| }; | |||
| console.log(props) | |||
| return ( | |||
| <> | |||
| <ItemDetailsCardContainer | |||
| @@ -41,7 +41,10 @@ const OfferDetails = (props) => { | |||
| console.log("Error: ", error); | |||
| }; | |||
| } else { | |||
| setImages((prevImages) => [...prevImages, file]); | |||
| setImages((prevImages) => [ | |||
| ...prevImages, | |||
| getImageUrl(file, variants.offerCard, isMobile), | |||
| ]); | |||
| } | |||
| } | |||
| }); | |||
| @@ -54,6 +57,7 @@ const OfferDetails = (props) => { | |||
| const onModalClose = () => { | |||
| setImagesCarouselModal(false); | |||
| }; | |||
| console.log(props); | |||
| return ( | |||
| <> | |||
| <Details | |||
| @@ -66,11 +70,7 @@ const OfferDetails = (props) => { | |||
| <ScrollerVertical> | |||
| {images.map((item, index) => ( | |||
| <OfferImage | |||
| src={ | |||
| props.createOffer | |||
| ? images[index] | |||
| : getImageUrl(item, variants.offerCard, isMobile) | |||
| } | |||
| src={images[index]} | |||
| alt={t("offer.imageAlt")} | |||
| key={item} | |||
| previewCard={props.previewCard} | |||
| @@ -92,11 +92,7 @@ const OfferDetails = (props) => { | |||
| if (!item) return; | |||
| return ( | |||
| <OfferImage | |||
| src={ | |||
| props.createOffer | |||
| ? images[index] | |||
| : getImageUrl(item, variants.offerCard, isMobile) | |||
| } | |||
| src={images[index]} | |||
| key={item} | |||
| previewCard={props.previewCard} | |||
| onClick={() => | |||
| @@ -32,6 +32,7 @@ import SaveButton from "./SaveButton/SaveButton"; | |||
| import { closeModal } from "../../../../store/actions/modal/modalActions"; | |||
| import { | |||
| dynamicRouteMatches, | |||
| replaceInRoute, | |||
| routeMatches, | |||
| } from "../../../../util/helpers/routeHelpers"; | |||
| import { | |||
| @@ -48,7 +49,7 @@ const DeleteOffer = (props) => { | |||
| const { t } = useTranslation(); | |||
| const queryString = useSelector(selectQueryString); | |||
| const history = useHistory(); | |||
| const userId = props.offer.userId; | |||
| const userId = props.offer.user._id; | |||
| const { isMobile } = useIsMobile(); | |||
| const offerId = props.offer._id; | |||
| const closeDeleteModalHandler = () => { | |||
| @@ -60,15 +61,22 @@ const DeleteOffer = (props) => { | |||
| dynamicRouteMatches(PROFILE_PAGE) || | |||
| dynamicRouteMatches(ADMIN_SINGLE_USER_PAGE) | |||
| ) | |||
| dispatch(fetchProfileOffers(userId)); | |||
| dispatch(fetchProfileOffers({ idProfile: userId, isAdmin: true })); | |||
| if (routeMatches(HOME_PAGE) || routeMatches(BASE_PAGE)) | |||
| dispatch(fetchOffers({ queryString })); | |||
| if ( | |||
| dynamicRouteMatches(ITEM_DETAILS_PAGE) || | |||
| dynamicRouteMatches(ADMIN_ITEM_DETAILS_PAGE) | |||
| ) { | |||
| if (dynamicRouteMatches(ITEM_DETAILS_PAGE)) { | |||
| history.push( | |||
| replaceInRoute(PROFILE_PAGE, { | |||
| profileId: userId, | |||
| }) | |||
| ); | |||
| } | |||
| if (dynamicRouteMatches(ADMIN_ITEM_DETAILS_PAGE)) { | |||
| if (props.pin) dispatch(fetchOneOffer(props.offer?._id)); | |||
| else history.goBack(); | |||
| else | |||
| history.push( | |||
| replaceInRoute(ADMIN_SINGLE_USER_PAGE, { profileId: userId }) | |||
| ); | |||
| } | |||
| }; | |||
| @@ -115,7 +115,7 @@ const OfferCard = (props) => { | |||
| editOffer: true, | |||
| offer: props.offer, | |||
| isAdmin: props.isAdmin, | |||
| customUserId: props?.offer?.userId, | |||
| customUserId: props?.offer?.user._id, | |||
| }) | |||
| ); | |||
| }; | |||
| @@ -13,6 +13,12 @@ const UserReviewsCard = (props) => { | |||
| ...props.review, | |||
| }; | |||
| } | |||
| let userWhoGaveReview = | |||
| props?.review?.exchange?.buyer?.user?._id === props?.review?.user?._id | |||
| ? "buyer" | |||
| : "seller"; | |||
| let userWhoRevievedReview = | |||
| userWhoGaveReview === "buyer" ? "seller" : "buyer"; | |||
| let isSuccessfulSwap = reviewEnum.YES.mainText.toUpperCase(); | |||
| if ( | |||
| props.review.succeeded === reviewEnum.NO.backendText || | |||
| @@ -32,24 +38,16 @@ const UserReviewsCard = (props) => { | |||
| isGoodCommunication = reviewEnum.NO.mainText.toUpperCase(); | |||
| return { | |||
| _id: props.review._id, | |||
| name: | |||
| props.review?.reviewAdditionalData?.userWhoGave?.company?.name || | |||
| props.review?.offer?.name, | |||
| image: | |||
| props.review?.reviewAdditionalData?.userWhoGave?.image || | |||
| props.review?.offer?.image, | |||
| userId: props.review.userId, | |||
| name: props?.review?.exchange[userWhoGaveReview]?.user?.company?.name, | |||
| image: props?.review?.exchange[userWhoGaveReview]?.user?.image, | |||
| userId: props.review.user?._id, | |||
| isGoodCommunication, | |||
| isSuccessfulSwap, | |||
| quote: props?.review?.message, | |||
| offerName: | |||
| props?.review?.reviewAdditionalData?.offerData?.name || | |||
| props?.review?.userWhoGaveReview?.name, | |||
| offerImage: | |||
| props?.review?.reviewAdditionalData?.offerData?.firstImage || | |||
| props?.review?.userWhoGaveReview?.image, | |||
| offerName: props?.review?.exchange?.offer?.name, | |||
| offerImage: props?.review?.exchange?.offer?.images[0], | |||
| userWhoReceived: | |||
| props?.review?.reviewAdditionalData?.userWhoReceived?.company?.name, | |||
| props?.review?.exchange[userWhoRevievedReview]?.user?.company?.name, | |||
| _deleted: props?.review?._deleted, | |||
| }; | |||
| }, [props.review]); | |||
| @@ -67,6 +65,7 @@ const UserReviewsCard = (props) => { | |||
| handleRemove={handleRemove} | |||
| hasGivenReview={props.hasGivenReview} | |||
| rightReviews={props.rightReviews} | |||
| isProfileReviews={props?.isProfileReviews} | |||
| isAdmin={props.isAdmin} | |||
| /> | |||
| ); | |||
| @@ -84,6 +83,7 @@ UserReviewsCard.propTypes = { | |||
| hasGivenReview: PropTypes.bool, | |||
| rightReviews: PropTypes.bool, | |||
| isAdmin: PropTypes.bool, | |||
| userId: PropTypes.string, | |||
| }; | |||
| UserReviewsCard.defaultProps = { | |||
| isProfileReviews: false, | |||
| @@ -3,11 +3,13 @@ import PropTypes from "prop-types"; | |||
| import { RemoveButtonContainer, RemoveIcon } from "./RemoveButton.styled"; | |||
| const RemoveButton = (props) => { | |||
| console.log(props) | |||
| return ( | |||
| <RemoveButtonContainer | |||
| isRemoved={props.isRemoved} | |||
| onClick={props.onClick} | |||
| hasGivenReview={props.hasGivenReview} | |||
| isProfileReviews={props?.isProfileReviews} | |||
| > | |||
| <RemoveIcon isRemoved={props.isRemoved} /> | |||
| </RemoveButtonContainer> | |||
| @@ -19,6 +21,7 @@ RemoveButton.propTypes = { | |||
| onClick: PropTypes.func, | |||
| hasGivenReview: PropTypes.bool, | |||
| isRemoved: PropTypes.bool, | |||
| isProfileReviews: PropTypes.any | |||
| }; | |||
| export default RemoveButton; | |||
| @@ -6,18 +6,24 @@ import { IconButton } from "../../../../Buttons/IconButton/IconButton"; | |||
| export const RemoveButtonContainer = styled(IconButton)` | |||
| position: absolute; | |||
| top: ${(props) => (props.hasGivenReview ? "79px" : "16px")}; | |||
| top: ${(props) => | |||
| props.hasGivenReview && props.isProfileReviews ? "79px" : "16px"}; | |||
| right: 16px; | |||
| background-color: ${props => props.isRemoved ? "transparent" : selectedTheme.colors.primaryIconBackgroundColor}; | |||
| background-color: ${(props) => | |||
| props.isRemoved | |||
| ? "transparent" | |||
| : selectedTheme.colors.primaryIconBackgroundColor}; | |||
| border-radius: 100%; | |||
| width: 32px; | |||
| height: 32px; | |||
| ${props => props.isRemoved && css` | |||
| & button:hover { | |||
| background-color: transparent; | |||
| cursor: auto; | |||
| } | |||
| `} | |||
| ${(props) => | |||
| props.isRemoved && | |||
| css` | |||
| & button:hover { | |||
| background-color: transparent; | |||
| cursor: auto; | |||
| } | |||
| `} | |||
| & button { | |||
| width: 32px; | |||
| height: 32px; | |||
| @@ -25,6 +31,6 @@ export const RemoveButtonContainer = styled(IconButton)` | |||
| `; | |||
| export const RemoveIcon = styled(Remove)` | |||
| & path { | |||
| stroke: ${props => props.isRemoved && selectedTheme.colors.blockedColor}; | |||
| stroke: ${(props) => props.isRemoved && selectedTheme.colors.blockedColor}; | |||
| } | |||
| `; | |||
| @@ -41,6 +41,7 @@ const UserReviewsSingleCard = (props) => { | |||
| <RemoveButton | |||
| review={props.review} | |||
| onClick={handleRemove} | |||
| isProfileReviews={props?.isProfileReviews} | |||
| hasGivenReview={props.hasGivenReview} | |||
| isRemoved={props.review?._deleted} | |||
| /> | |||
| @@ -63,6 +64,7 @@ UserReviewsSingleCard.propTypes = { | |||
| isAdmin: PropTypes.bool, | |||
| className: PropTypes.string, | |||
| lastReview: PropTypes.bool, | |||
| isProfileReviews: PropTypes.any, | |||
| }; | |||
| UserReviewsSingleCard.defaultProps = { | |||
| lastReview: false, | |||
| @@ -37,8 +37,16 @@ const DirectChatHeader = (props) => { | |||
| return true; | |||
| if (exchange.buyer?.user._id === userId && exchange.buyer?.givenReview) | |||
| return true; | |||
| if (chat?.offer?._deleted) return true; | |||
| if (props.interlocutor?._blocked) return true; | |||
| return false; | |||
| }, [exchange, userId]); | |||
| }, [exchange, userId, props.interlocutor, chat]); | |||
| const isDisabledCheckButton = useMemo(() => { | |||
| if (props?.interlocutor?._blocked) return true; | |||
| if (chat?.offer?._deleted) return true; | |||
| return false; | |||
| }, [props.interlocutor, chat]); | |||
| const showReviewModal = () => { | |||
| dispatch( | |||
| @@ -62,14 +70,12 @@ const DirectChatHeader = (props) => { | |||
| <OfferCard | |||
| offer={props.offer} | |||
| aboveChat | |||
| disabledReviews={props.interlocutor?._blocked || isDisabledReviews} | |||
| disabledReviews={isDisabledReviews} | |||
| makeReview={showReviewModal} | |||
| acceptExchange={acceptExchange} | |||
| exchangeState={props?.exchangeState} | |||
| dontShowViews | |||
| disabledCheckButton={ | |||
| props.interlocutor?._blocked || props?.offer?._deleted | |||
| } | |||
| disabledCheckButton={isDisabledCheckButton} | |||
| /> | |||
| </DirectChatHeaderContainer> | |||
| ); | |||
| @@ -90,16 +90,17 @@ const DirectChatNewMessage = (props) => { | |||
| }) | |||
| ); | |||
| }; | |||
| console.log(props) | |||
| if (mineProfileBlocked) { | |||
| return <NotAllowedChat mineProfileBlocked />; | |||
| } | |||
| if (props?.chat?.interlocutor?._deleted) { | |||
| if (props?.interlocutor?._deleted) { | |||
| return <NotAllowedChat deleted />; | |||
| } | |||
| if (props?.chat?.offer?.offer?._deleted) { | |||
| if (props?.chat?.offer?._deleted) { | |||
| return <NotAllowedChat />; | |||
| } | |||
| if (props?.chat?.interlocutor?._blocked) { | |||
| if (props?.interlocutor?._blocked) { | |||
| return <NotAllowedChat blocked />; | |||
| } | |||
| return ( | |||
| @@ -16,9 +16,11 @@ const SearchInput = forwardRef((props, ref) => { | |||
| const { t } = useTranslation(); | |||
| const handleSearch = () => { | |||
| if (routeMatches(HOME_PAGE) || routeMatches(BASE_PAGE)) { | |||
| console.log("uslo unutra") | |||
| debounceHelper(() => props.handleSearch(ref.current.value), 500); | |||
| } | |||
| }; | |||
| console.log(routeMatches(HOME_PAGE)) | |||
| const handleManualSearch = () => { | |||
| debounceHelper(() => {}, 500); | |||
| props.handleSearch(ref.current.value); | |||
| @@ -25,10 +25,7 @@ const ItemDetails = (props) => { | |||
| selectIsLoadingByActionType(ONE_OFFER_SCOPE) | |||
| ); | |||
| let isMyProfile = useMemo(() => { | |||
| if ( | |||
| offer?.user?._id?.toString() === userId?.toString() || | |||
| props.isAdmin | |||
| ) | |||
| if (offer?.user?._id?.toString() === userId?.toString() || props.isAdmin) | |||
| return true; | |||
| return false; | |||
| }, [offer, userId, props.isAdmin]); | |||
| @@ -41,7 +38,11 @@ const ItemDetails = (props) => { | |||
| ) : ( | |||
| <> | |||
| {!props.singleOffer && ( | |||
| <ItemDetailsHeaderCard offer={offer} isMyProfile={isMyProfile} /> | |||
| <ItemDetailsHeaderCard | |||
| offer={offer} | |||
| isMyProfile={isMyProfile} | |||
| isAdmin={props?.isAdmin} | |||
| /> | |||
| )} | |||
| {props.singleOffer && ( | |||
| <OfferIconContainer> | |||
| @@ -49,7 +50,12 @@ const ItemDetails = (props) => { | |||
| <OfferIconText>{t("offer.product")}</OfferIconText> | |||
| </OfferIconContainer> | |||
| )} | |||
| <ItemDetailsCard offer={offer} isMyOffer={isMyProfile} isAdmin={props.isAdmin} singleOffer /> | |||
| <ItemDetailsCard | |||
| offer={offer} | |||
| isMyOffer={isMyProfile} | |||
| isAdmin={props.isAdmin} | |||
| singleOffer | |||
| /> | |||
| </> | |||
| )} | |||
| </ItemDetailsContainer> | |||
| @@ -26,7 +26,11 @@ import itemDetailsData from "../../../notFoundData/itemDetailsData"; | |||
| import { Tooltip } from "@mui/material"; | |||
| import { useTranslation } from "react-i18next"; | |||
| import { replaceInRoute } from "../../../util/helpers/routeHelpers"; | |||
| import { DIRECT_CHAT_PAGE, PROFILE_PAGE } from "../../../constants/pages"; | |||
| import { | |||
| ADMIN_SINGLE_USER_PAGE, | |||
| DIRECT_CHAT_PAGE, | |||
| PROFILE_PAGE, | |||
| } from "../../../constants/pages"; | |||
| const ItemDetailsHeaderCard = (props) => { | |||
| const history = useHistory(); | |||
| @@ -45,17 +49,25 @@ const ItemDetailsHeaderCard = (props) => { | |||
| const { isMobile } = useIsMobile(); | |||
| const handleGoProfile = () => { | |||
| history.push(replaceInRoute(PROFILE_PAGE, { | |||
| profileId: props?.offer?.user?._id | |||
| })); | |||
| if (props?.isAdmin) { | |||
| history.push( | |||
| replaceInRoute(ADMIN_SINGLE_USER_PAGE, { | |||
| profileId: props?.offer?.user?._id, | |||
| }) | |||
| ); | |||
| } else { | |||
| history.push( | |||
| replaceInRoute(PROFILE_PAGE, { | |||
| profileId: props?.offer?.user?._id, | |||
| }) | |||
| ); | |||
| } | |||
| }; | |||
| const messageUser = (offer) => { | |||
| const chatItem = chats.find( | |||
| (item) => item.offer._id === offer?._id | |||
| ); | |||
| const chatItem = chats.find((item) => item.offer._id === offer?._id); | |||
| if (chatItem !== undefined) { | |||
| history.push(DIRECT_CHAT_PAGE, { | |||
| chatId: chatItem._id | |||
| chatId: chatItem._id, | |||
| }); | |||
| } else { | |||
| if (offer?.user?._id !== userId) { | |||
| @@ -121,6 +133,7 @@ ItemDetailsHeaderCard.propTypes = { | |||
| offer: PropTypes.any, | |||
| isMyProfile: PropTypes.bool, | |||
| singleOffer: PropTypes.bool, | |||
| isAdmin: PropTypes.bool, | |||
| }; | |||
| ItemDetailsHeaderCard.defaultProps = { | |||
| halfwidth: false, | |||
| @@ -91,6 +91,7 @@ const Header = (props) => { | |||
| headerTitle={headerTitle} | |||
| headerIcon={headerIcon} | |||
| offers={props?.offers} | |||
| myOffers={props?.myOffers} | |||
| hideBackButton={props?.hideBackButton} | |||
| /> | |||
| {/* ^^^^^^ */} | |||
| @@ -103,11 +104,13 @@ const Header = (props) => { | |||
| /> | |||
| {/* Select option to choose sorting */} | |||
| <HeaderSelect | |||
| myOffers={props?.myOffers} | |||
| sorting={sorting} | |||
| hideSorting={props?.hideSorting} | |||
| /> | |||
| {!props?.hideSorting && ( | |||
| <HeaderSelect | |||
| myOffers={props?.myOffers} | |||
| sorting={sorting} | |||
| hideSorting={props?.hideSorting} | |||
| /> | |||
| )} | |||
| {/* ^^^^^^ */} | |||
| </HeaderOptions> | |||
| </HeaderContainer> | |||
| @@ -42,6 +42,7 @@ const TooltipHeader = (props) => { | |||
| const goBack = () => { | |||
| history.goBack(); | |||
| }; | |||
| console.log(props) | |||
| return ( | |||
| <Tooltip title={headerString.text}> | |||
| <TooltipInnerContainer> | |||
| @@ -9,13 +9,18 @@ import OffersNotFound from "./OffersNotFound/OffersNotFound"; | |||
| const Offers = (props) => { | |||
| const offers = props?.offers; | |||
| const arrayForMapping = Array.apply(null, Array(4)).map(() => {}); | |||
| console.log("rerender") | |||
| console.log("rerender"); | |||
| return ( | |||
| <> | |||
| <OffersFilterButton /> | |||
| <OffersFilterButton | |||
| offers={props?.offers} | |||
| isAdmin={props?.isAdmin} | |||
| myOffers={props?.myOffers} | |||
| toggleFilters={props?.toggleFilters} | |||
| /> | |||
| <OffersSearchField /> | |||
| <OffersNotFound skeleton={props?.skeleton} /> | |||
| {!props?.skeleton && <OffersNotFound />} | |||
| <OffersList | |||
| loading={props?.skeleton} | |||
| offers={offers} | |||
| @@ -52,13 +52,11 @@ const EditCategory = (props) => { | |||
| // }; | |||
| const closeModalHandler = () => { | |||
| console.log("closed") | |||
| dispatch(closeModal()); | |||
| }; | |||
| const handleApiResponseSuccess = () => { | |||
| console.log("succes") | |||
| if (clickedOnNext) { | |||
| if (clickedOnNext && props?.showSecondButton) { | |||
| formik.resetForm(); | |||
| inputRef.current.focus(); | |||
| } else closeModalHandler(); | |||
| @@ -8,8 +8,9 @@ import { selectMineHeaderOffers } from "../../../store/selectors/offersSelectors | |||
| import { fetchMineHeaderOffers } from "../../../store/actions/offers/offersActions"; | |||
| import { selectProfileName } from "../../../store/selectors/profileSelectors"; | |||
| import { useHistory } from "react-router-dom"; | |||
| import { MY_OFFERS_PAGE } from "../../../constants/pages"; | |||
| import { ITEM_DETAILS_PAGE, MY_OFFERS_PAGE } from "../../../constants/pages"; | |||
| import { useMemo } from "react"; | |||
| import { replaceInRoute } from "../../../util/helpers/routeHelpers"; | |||
| export const MyPosts = (props) => { | |||
| const { t } = useTranslation(); | |||
| @@ -59,7 +60,11 @@ export const MyPosts = (props) => { | |||
| }, [arrayOfMineOffers, mineOffers]); | |||
| const goToOffer = (id) => { | |||
| history.push(`/proizvodi/${id}`); | |||
| history.push( | |||
| replaceInRoute(ITEM_DETAILS_PAGE, { | |||
| offerId: id, | |||
| }) | |||
| ); | |||
| props.closePopover(); | |||
| }; | |||
| const goToMySwaps = () => { | |||
| @@ -19,13 +19,11 @@ const ReviewsSorting = forwardRef((props, ref) => { | |||
| const [value, setValue] = useState(); | |||
| const changeValue = (event) => { | |||
| if (props.isAdmin) { | |||
| // if(event.target.value.value === 1) { | |||
| // dispatch(setReviews(reviews.givenReviews)); | |||
| // } else { | |||
| // dispatch(setReviews(reviews.receivedReviews)); | |||
| // } | |||
| // if(event.target.value.value === 1) { | |||
| // dispatch(setReviews(reviews.givenReviews)); | |||
| // } else { | |||
| // dispatch(setReviews(reviews.receivedReviews)); | |||
| // } | |||
| } else { | |||
| dispatch( | |||
| setReviews( | |||
| @@ -42,19 +40,25 @@ const ReviewsSorting = forwardRef((props, ref) => { | |||
| const sortEnum = useMemo(() => { | |||
| if (props.isAdmin) return sortAdminEnum; | |||
| return reviewSortEnum; | |||
| }); | |||
| }, [props.isAdmin]); | |||
| const initialSortOption = useMemo(() => { | |||
| if (props.isAdmin) return sortAdminEnum.GIVEN; | |||
| return reviewSortEnum.INITIAL; | |||
| }, [props.isAdmin]); | |||
| useImperativeHandle(ref, () => ({ | |||
| sortValue: value, | |||
| hasGivenReview: value?.value === sortAdminEnum.GIVEN.value | |||
| })) | |||
| hasGivenReview: value?.value === sortAdminEnum.GIVEN.value, | |||
| })); | |||
| return ( | |||
| <HeaderSelect | |||
| value={value || sortEnum.INITIAL} | |||
| value={value || initialSortOption} | |||
| IconComponent={DownArrowIcon} | |||
| onChange={changeValue} | |||
| > | |||
| <SelectOption style={{ display: "none" }} value={sortEnum.INITIAL}> | |||
| {sortEnum.INITIAL.mainText} | |||
| <SelectOption style={{ display: "none" }} value={initialSortOption}> | |||
| {initialSortOption.mainText} | |||
| </SelectOption> | |||
| {Object.keys(sortEnum).map((property) => { | |||
| if (sortEnum[property].value === 0) return; | |||
| @@ -17,20 +17,19 @@ import { useDispatch, useSelector } from "react-redux"; | |||
| import { selectOffer } from "../../store/selectors/offersSelectors"; | |||
| import { selectSelectedReviews } from "../../store/selectors/reviewSelector"; | |||
| import { useRouteMatch } from "react-router-dom"; | |||
| import { | |||
| fetchReviews, | |||
| setReviews, | |||
| } from "../../store/actions/review/reviewActions"; | |||
| import { fetchReviews } from "../../store/actions/review/reviewActions"; | |||
| import { selectIsLoadingByActionType } from "../../store/selectors/loadingSelectors"; | |||
| import SkeletonUserReviews from "./SkeletonUserReviews/SkeletonUserReviews"; | |||
| import { ONE_OFFER_SCOPE } from "../../store/actions/offers/offersActionConstants"; | |||
| import { | |||
| REVIEW_GET_SCOPE, | |||
| REVIEW_GET_AS_ADMIN_SCOPE, | |||
| } from "../../store/actions/review/reviewActionConstants"; | |||
| import { REVIEW_GET_SCOPE } from "../../store/actions/review/reviewActionConstants"; | |||
| import ReviewsSorting from "./ReviewsSorting/ReviewsSorting"; | |||
| import { sortReviews } from "../../util/helpers/reviewsHelper"; | |||
| // import { selectUserId } from "../../store/selectors/loginSelectors"; | |||
| import { dynamicRouteMatches } from "../../util/helpers/routeHelpers"; | |||
| import { | |||
| ADMIN_SINGLE_USER_PAGE, | |||
| DIRECT_CHAT_PAGE, | |||
| PROFILE_PAGE, | |||
| } from "../../constants/pages"; | |||
| import { selectUserId } from "../../store/selectors/loginSelectors"; | |||
| const UserReviews = (props) => { | |||
| const [isGiven, setIsGiven] = useState(true); | |||
| @@ -41,53 +40,71 @@ const UserReviews = (props) => { | |||
| const dispatch = useDispatch(); | |||
| const listRef = useRef(null); | |||
| const sortRef = useRef(null); | |||
| // const userId = useSelector(selectUserId); | |||
| const mineUserId = useSelector(selectUserId); | |||
| const isLoadingReview = useSelector( | |||
| selectIsLoadingByActionType( | |||
| props.isAdmin | |||
| ? REVIEW_GET_AS_ADMIN_SCOPE | |||
| : props.isProfileReviews | |||
| ? REVIEW_GET_SCOPE | |||
| : ONE_OFFER_SCOPE | |||
| props.givingReview ? ONE_OFFER_SCOPE : REVIEW_GET_SCOPE | |||
| ) | |||
| ); | |||
| const userId = useMemo(() => { | |||
| if ( | |||
| dynamicRouteMatches(PROFILE_PAGE) || | |||
| dynamicRouteMatches(ADMIN_SINGLE_USER_PAGE) | |||
| ) { | |||
| return routeMatch.params.profileId; | |||
| } | |||
| if (dynamicRouteMatches(DIRECT_CHAT_PAGE)) { | |||
| return mineUserId; | |||
| } | |||
| return offer?.user?._id; | |||
| }, [offer]); | |||
| useEffect(() => { | |||
| let idProfile = routeMatch.params?.profileId; | |||
| if (idProfile) { | |||
| dispatch(fetchReviews(idProfile)); | |||
| if (!props?.givingReview && userId) { | |||
| dispatch(fetchReviews(userId)); | |||
| } | |||
| }, [props.givingReview, userId]); | |||
| // if (props.profileReviews && routeMatch.params?.profileId) { | |||
| // let idProfile = routeMatch.params?.profileId; | |||
| // dispatch(fetchReviews(idProfile)); | |||
| // } | |||
| }, [props.profileReviews, routeMatch]); | |||
| const lastThreeReviews = useMemo(() => { | |||
| if (props.isAdmin) { | |||
| if (isGiven) { | |||
| return reviews.givenReviews; | |||
| } else { | |||
| return reviews.receivedReviews; | |||
| } | |||
| if (props.isProfileReviews && Array.isArray(reviews) && !props.isAdmin) { | |||
| return reviews.filter((singleReview) => { | |||
| let userWhoRecievedReview = | |||
| singleReview?.exchange?.buyer?.user?._id === singleReview?.user?._id | |||
| ? "seller" | |||
| : "buyer"; | |||
| return ( | |||
| singleReview?.exchange[userWhoRecievedReview]?.user?._id === userId | |||
| ); | |||
| }); | |||
| } | |||
| if (props.isProfileReviews) { | |||
| return reviews; | |||
| } | |||
| if (props.givingReview) { | |||
| return [...props.profileReviews]; | |||
| } | |||
| if (offer?.companyData?.lastThreeReviews) { | |||
| // Making array of reviews in same order(sorting) so when comparing | |||
| // them, I can make valid condition | |||
| if ( | |||
| JSON.stringify(sortReviews(reviews)) !== | |||
| JSON.stringify(sortReviews(offer?.companyData?.lastThreeReviews)) | |||
| ) { | |||
| dispatch(setReviews([...offer?.companyData.lastThreeReviews])); | |||
| } | |||
| return [...offer?.companyData?.lastThreeReviews]; | |||
| if (Array.isArray(reviews)) { | |||
| return reviews.reduce((result, singleReview) => { | |||
| let userWhoGaveReview = | |||
| singleReview?.exchange?.buyer?.user?._id === singleReview?.user?._id | |||
| ? "buyer" | |||
| : "seller"; | |||
| let userWhoRevievedReview = | |||
| userWhoGaveReview === "buyer" ? "seller" : "buyer"; | |||
| if (props.isAdmin) { | |||
| if (isGiven) { | |||
| if ( | |||
| userId === singleReview?.exchange[userWhoGaveReview]?.user?._id | |||
| ) { | |||
| result.push(singleReview); | |||
| } | |||
| } else { | |||
| if ( | |||
| userId === | |||
| singleReview?.exchange[userWhoRevievedReview]?.user?._id | |||
| ) { | |||
| result.push(singleReview); | |||
| } | |||
| } | |||
| } | |||
| return result; | |||
| }, []); | |||
| } | |||
| return []; | |||
| }, [props.profileReviews, offer, props.isProfileReviews, reviews, isGiven]); | |||
| @@ -143,6 +160,8 @@ const UserReviews = (props) => { | |||
| showRemoveIcon={props.isAdmin} | |||
| review={review} | |||
| key={index} | |||
| isProfileReviews={props?.isProfileReviews} | |||
| userId={userId} | |||
| isAdmin={props.isAdmin} | |||
| hasGivenReview={isGiven} | |||
| givingReview={props.givingReview} | |||
| @@ -34,7 +34,8 @@ export const ReviewsBox = styled(Box)` | |||
| : "350px"}; | |||
| padding: 0; | |||
| width: 100%; | |||
| margin: 0 ${(props) => (props.isAdmin ? "18px" : "0")}; | |||
| margin: 0 | |||
| ${(props) => (props.isAdmin && props.isProfileReviews ? "18px" : "0")}; | |||
| margin-top: 60px; | |||
| } | |||
| `; | |||
| @@ -16,6 +16,7 @@ import { routeMatches } from "../../util/helpers/routeHelpers"; | |||
| const useSearch = (applyAllFilters) => { | |||
| const [searchStringLocally, setSearchStringLocally] = useState(""); | |||
| const [isInitallyLoaded, setIsInitiallyLoaded] = useState(false); | |||
| const [appliedSearch, setAppliedSearch] = useState(false); | |||
| const dispatch = useDispatch(); | |||
| const searchString = useSelector(selectSearchString); | |||
| const history = useHistory(); | |||
| @@ -47,6 +48,13 @@ const useSearch = (applyAllFilters) => { | |||
| } | |||
| }, [history.location.pathname]); | |||
| useEffect(() => { | |||
| if (appliedSearch) { | |||
| applyAllFilters(); | |||
| setAppliedSearch(false); | |||
| } | |||
| }, [appliedSearch]); | |||
| // On every local change of search string, global state of search string should be also updated | |||
| useEffect(() => { | |||
| if (isInitallyLoaded && applyAllFilters) { | |||
| @@ -62,7 +70,7 @@ const useSearch = (applyAllFilters) => { | |||
| const searchOffersImmediately = (searchValue) => { | |||
| setIsInitiallyLoaded(true); | |||
| searchOffers(searchValue); | |||
| applyAllFilters(); | |||
| setAppliedSearch(true); | |||
| }; | |||
| const setSearchStringManually = (searchValue) => { | |||
| @@ -17,7 +17,7 @@ const ProfileLayout = (props) => { | |||
| {props.children} | |||
| <ContentRightCardContainer container spacing={2}> | |||
| <Content sm={12} md={8} lg={8} xl={9} item>{props.content}</Content> | |||
| <RightCard sm={0} md={4} lg={4} xl={3} item singleOffer={props.singleOffer} profile={props.profile}> | |||
| <RightCard sm={12} md={4} lg={4} xl={3} item singleOffer={props.singleOffer} profile={props.profile}> | |||
| {props.rightCard} | |||
| </RightCard> | |||
| </ContentRightCardContainer> | |||
| @@ -12,7 +12,7 @@ export const ProfileLayoutContainer = styled(Container)` | |||
| /* flex: 1; */ | |||
| height: 100%; | |||
| @media (max-width: 1350px) { | |||
| padding-right: ${props => props.isAdmin ? "36px" : "0"}; | |||
| padding-right: ${(props) => (props.isAdmin ? "36px" : "0")}; | |||
| } | |||
| @media (max-width: 600px) { | |||
| padding-left: 0; | |||
| @@ -31,7 +31,6 @@ export const RightCard = styled(Grid)` | |||
| padding-left: 0; | |||
| ${(props) => props.profile && `min-width: 350px;`} | |||
| @media screen and (min-width: 600px) { | |||
| margin-top: 34px; | |||
| margin-left: ${(props) => (props.profile ? "0" : "36px")}; | |||
| @@ -44,6 +43,7 @@ export const RightCard = styled(Grid)` | |||
| margin-left: 0; | |||
| } | |||
| @media (max-width: 600px) { | |||
| width: 100%; | |||
| min-width: 0; | |||
| } | |||
| `; | |||
| @@ -42,7 +42,7 @@ const AdminItemDetailsPage = (props) => { | |||
| content={<ItemDetails singleOffer isAdmin />} | |||
| rightCard={ | |||
| <> | |||
| <ProfileMini /> <UserReviews rightReviews /> | |||
| <ProfileMini /> <UserReviews isAdmin rightReviews /> | |||
| </> | |||
| } | |||
| /> | |||
| @@ -6,8 +6,8 @@ const request = axios.create({ | |||
| // baseURL: "http://192.168.88.175:3005/", | |||
| // baseURL: "http://192.168.88.143:3001/", // DULE | |||
| // baseURL: "https://trampa-api.dilig.net/", | |||
| baseURL: "https://trampa-api-test.dilig.net/", | |||
| // baseURL: "http://localhost:3001/", | |||
| // baseURL: "https://trampa-api-test.dilig.net/", | |||
| baseURL: "http://localhost:3001/", | |||
| // baseURL: process.env.REACT_APP_BASE_API_URL, | |||
| headers: { | |||
| "Content-Type": "application/json", | |||
| @@ -16,9 +16,9 @@ import { logoutUser, refreshUserToken } from "../actions/login/loginActions"; | |||
| // const baseURL = "http://192.168.88.143:3001/"; // DULE | |||
| // const baseURL = "http://192.168.88.175:3005/"; | |||
| // const baseURL = "https://trampa-api.dilig.net/"; | |||
| const baseURL = "https://trampa-api-test.dilig.net/"; | |||
| // const baseURL = "https://trampa-api-test.dilig.net/"; | |||
| // const baseURL = "http://192.168.88.150:3001/"; // DJOLE | |||
| // const baseURL = "http://localhost:3001/"; | |||
| const baseURL = "http://localhost:3001/"; | |||
| // const baseURL = process.env.REACT_APP_BASE_API_URL | |||
| //Interceptor unique name | |||
| @@ -255,11 +255,14 @@ function* fetchProfileOffers(payload) { | |||
| try { | |||
| console.log(payload.payload); | |||
| let userId; | |||
| if (typeof payload.payload === "object") { | |||
| userId = payload.payload.idProfile; | |||
| } else userId = payload.payload; | |||
| if (!userId || userId?.length === 0) | |||
| throw new Error("User id is not defined!"); | |||
| let queryString = new URLSearchParams(); | |||
| queryString.set(KEY_SIZE, 10); | |||
| if (payload.payload[KEY_PAGE]) { | |||
| @@ -271,6 +274,7 @@ function* fetchProfileOffers(payload) { | |||
| } else { | |||
| queryString = yield select(selectQueryString); | |||
| } | |||
| console.log(queryString.toString()); | |||
| let data; | |||
| if (payload.payload.isAdmin) { | |||
| @@ -28,7 +28,7 @@ function* fetchReviews(payload) { | |||
| try { | |||
| console.log(payload); | |||
| const data = yield call(attemptFetchReview, payload.payload); | |||
| yield put(setReviews([...data.data.reviews].reverse())); | |||
| yield put(setReviews([...data.data.reviews])); | |||
| yield put(fetchReviewsSuccess()); | |||
| } catch (e) { | |||
| yield put(fetchReviewsError()); | |||