| return ( | return ( | ||||
| <CheckboxButton | <CheckboxButton | ||||
| leftText={props.companies ? item.company.name : item.city} | |||||
| leftText={props.companies ? item.companyName : item.city} | |||||
| // rightText={item.offerCount} | // rightText={item.offerCount} | ||||
| value={item} | value={item} | ||||
| checked={ | checked={ | ||||
| props.filters.find((itemInList) => | props.filters.find((itemInList) => | ||||
| props.companies | props.companies | ||||
| ? itemInList?.company?.name?.toString() === | |||||
| item?.company?.name?.toString() | |||||
| ? itemInList?.companyName.toString() === | |||||
| item?.companyName.toString() | |||||
| : itemInList?.city?.toString() === item?.city?.toString() | : itemInList?.city?.toString() === item?.city?.toString() | ||||
| ) | ) | ||||
| ? true | ? true |
| <SelectedItemsContainer> | <SelectedItemsContainer> | ||||
| {props.filters.map((item) => ( | {props.filters.map((item) => ( | ||||
| <SelectedItem | <SelectedItem | ||||
| key={props.companies ? item.company.name : item.city} | |||||
| key={props.companies ? item.companyName : item.city} | |||||
| onClick={() => handleDelete(item)} | onClick={() => handleDelete(item)} | ||||
| > | > | ||||
| {props.companies | {props.companies | ||||
| ? data.find( | ? data.find( | ||||
| (p) => | (p) => | ||||
| p?.company?.name?.toString() === | |||||
| item?.company?.name?.toString() | |||||
| )?.company?.name | |||||
| p?.companyName?.toString() === | |||||
| item?.companyName?.toString() | |||||
| )?.companyName | |||||
| : data.find( | : data.find( | ||||
| (p) => p?.city?.toString() === item?.city?.toString() | (p) => p?.city?.toString() === item?.city?.toString() | ||||
| )?.city} | )?.city} |
| setDataToShow( | setDataToShow( | ||||
| data.filter((item) => | data.filter((item) => | ||||
| props.companies | props.companies | ||||
| ? item.company.name.toLowerCase().includes(toSearch.toLowerCase()) | |||||
| ? item.companyName.toLowerCase().includes(toSearch.toLowerCase()) | |||||
| : item.city.toLowerCase().includes(toSearch.toLowerCase()) | : item.city.toLowerCase().includes(toSearch.toLowerCase()) | ||||
| ) | ) | ||||
| ); | ); |
| if ( | if ( | ||||
| props.filters.find( | props.filters.find( | ||||
| (itemInList) => | (itemInList) => | ||||
| itemInList?.company?.name?.toString() === | |||||
| item?.company?.name?.toString() | |||||
| itemInList?.companyName?.toString() === | |||||
| item?.companyName?.toString() | |||||
| ) | ) | ||||
| ) { | ) { | ||||
| props.setItemsSelected([ | props.setItemsSelected([ | ||||
| ...props.filters.filter( | ...props.filters.filter( | ||||
| (p) => | |||||
| p?.company?.name?.toString() !== item?.company?.name?.toString() | |||||
| (p) => p?.companyName?.toString() !== item?.companyName?.toString() | |||||
| ), | ), | ||||
| ]); | ]); | ||||
| } else { | } else { | ||||
| <SmallDropdownContent dropdown={showDropdown}> | <SmallDropdownContent dropdown={showDropdown}> | ||||
| {dataFiltered.map((item) => { | {dataFiltered.map((item) => { | ||||
| return ( | return ( | ||||
| <DropdownItem key={item.company._id}> | |||||
| <DropdownItem key={item._id}> | |||||
| <Checkbox | <Checkbox | ||||
| item={item} | item={item} | ||||
| filters={props.filters} | filters={props.filters} |
| setDataToShow( | setDataToShow( | ||||
| data.filter((item) => | data.filter((item) => | ||||
| props.companies | props.companies | ||||
| ? item.company.name.toLowerCase().includes(toSearch.toLowerCase()) | |||||
| ? item.companyName.toLowerCase().includes(toSearch.toLowerCase()) | |||||
| : item.city.toLowerCase().includes(toSearch.toLowerCase()) | : item.city.toLowerCase().includes(toSearch.toLowerCase()) | ||||
| ) | ) | ||||
| ); | ); |
| const handleRemove = () => { | const handleRemove = () => { | ||||
| setRemoveModalOpened(true); | setRemoveModalOpened(true); | ||||
| }; | }; | ||||
| console.log(props); | |||||
| const review = useMemo(() => { | const review = useMemo(() => { | ||||
| if (props.givingReview) { | if (props.givingReview) { | ||||
| return { | return { | ||||
| isGoodCommunication = reviewEnum.NO.mainText.toUpperCase(); | isGoodCommunication = reviewEnum.NO.mainText.toUpperCase(); | ||||
| return { | return { | ||||
| _id: props.review._id, | _id: props.review._id, | ||||
| name: props.review.userWhoGaveReview.name, | |||||
| image: props.review.userWhoGaveReview.image, | |||||
| 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, | userId: props.review.userId, | ||||
| isGoodCommunication, | isGoodCommunication, | ||||
| isSuccessfulSwap, | isSuccessfulSwap, | ||||
| quote: props?.review?.message, | quote: props?.review?.message, | ||||
| offerName: props.review.offer.name, | |||||
| offerImage: props.review.offer.image, | |||||
| offerName: | |||||
| props?.review?.reviewAdditionalData?.offerData?.name || | |||||
| props?.review?.userWhoGaveReview?.name, | |||||
| offerImage: | |||||
| props?.review?.reviewAdditionalData?.offerData?.firstImage || | |||||
| props?.review?.userWhoGaveReview?.image, | |||||
| userWhoReceived: | |||||
| props?.review?.reviewAdditionalData?.userWhoReceived?.company?.name, | |||||
| }; | }; | ||||
| }, [props.review]); | }, [props.review]); | ||||
| console.log(review); | |||||
| return ( | return ( | ||||
| <> | <> | ||||
| <UserReviewsSingleCard | <UserReviewsSingleCard | ||||
| review={review} | review={review} | ||||
| showRemoveIcon={props.showRemoveIcon} | showRemoveIcon={props.showRemoveIcon} | ||||
| handleRemove={handleRemove} | handleRemove={handleRemove} | ||||
| hasGivenReview={props.hasGivenReview} | |||||
| rightReviews={props.rightReviews} | |||||
| /> | /> | ||||
| {removeModalOpened && ( | {removeModalOpened && ( | ||||
| <DeleteReview | <DeleteReview | ||||
| review: PropTypes.any, | review: PropTypes.any, | ||||
| givingReview: PropTypes.bool, | givingReview: PropTypes.bool, | ||||
| showRemoveIcon: PropTypes.bool, | showRemoveIcon: PropTypes.bool, | ||||
| hasGivenReview: PropTypes.bool, | |||||
| rightReviews: PropTypes.bool, | |||||
| }; | }; | ||||
| UserReviewsCard.defaultProps = { | UserReviewsCard.defaultProps = { | ||||
| isProfileReviews: false, | isProfileReviews: false, |
| import React from "react"; | |||||
| import PropTypes from "prop-types"; | |||||
| import { | |||||
| GivenReviewsHeaderContainer, | |||||
| CompanyName, | |||||
| } from "./GivenReviewsHeader.styled"; | |||||
| import { useTranslation } from "react-i18next"; | |||||
| const GivenReviewsHeader = (props) => { | |||||
| const { t } = useTranslation(); | |||||
| console.log(props); | |||||
| return ( | |||||
| <GivenReviewsHeaderContainer hasGivenReview={props.hasGivenReview}> | |||||
| {t("reviews.givenHeaderTitle")} | |||||
| <CompanyName>{props.userWhoReceived}</CompanyName> | |||||
| </GivenReviewsHeaderContainer> | |||||
| ); | |||||
| }; | |||||
| GivenReviewsHeader.propTypes = { | |||||
| hasGivenReview: PropTypes.bool, | |||||
| userWhoReceived: PropTypes.any, | |||||
| }; | |||||
| export default GivenReviewsHeader; |
| import styled from "styled-components"; | |||||
| import { Box, Typography } from "@mui/material"; | |||||
| import selectedTheme from "../../../../../themes"; | |||||
| export const GivenReviewsHeaderContainer = styled(Box)` | |||||
| display: ${(props) => (props.hasGivenReview ? "none" : "flex")}; | |||||
| width: 100%; | |||||
| background-color: #f5edff; | |||||
| padding-top: 11px; | |||||
| padding-left: 18px; | |||||
| padding-bottom: 10px; | |||||
| margin-bottom: 18px; | |||||
| font-family: ${selectedTheme.fonts.textFont}; | |||||
| border-radius: 4px; | |||||
| `; | |||||
| export const CompanyName = styled(Typography)` | |||||
| color: ${selectedTheme.colors.primaryPurple}; | |||||
| font-weight: 600; | |||||
| `; |
| const RemoveButton = (props) => { | const RemoveButton = (props) => { | ||||
| return ( | return ( | ||||
| <RemoveButtonContainer onClick={props.onClick}> | |||||
| <RemoveButtonContainer | |||||
| onClick={props.onClick} | |||||
| hasGivenReview={props.hasGivenReview} | |||||
| > | |||||
| <RemoveIcon /> | <RemoveIcon /> | ||||
| </RemoveButtonContainer> | </RemoveButtonContainer> | ||||
| ); | ); | ||||
| RemoveButton.propTypes = { | RemoveButton.propTypes = { | ||||
| children: PropTypes.node, | children: PropTypes.node, | ||||
| onClick: PropTypes.func, | onClick: PropTypes.func, | ||||
| hasGivenReview: PropTypes.bool, | |||||
| }; | }; | ||||
| export default RemoveButton; | export default RemoveButton; |
| export const RemoveButtonContainer = styled(IconButton)` | export const RemoveButtonContainer = styled(IconButton)` | ||||
| position: absolute; | position: absolute; | ||||
| top: 16px; | |||||
| top: ${(props) => (!props.hasGivenReview ? "79px" : "16px")}; | |||||
| right: 16px; | right: 16px; | ||||
| background-color: ${selectedTheme.colors.primaryIconBackgroundColor}; | background-color: ${selectedTheme.colors.primaryIconBackgroundColor}; | ||||
| border-radius: 100%; | border-radius: 100%; | ||||
| height: 32px; | height: 32px; | ||||
| } | } | ||||
| `; | `; | ||||
| export const RemoveIcon = styled(Remove)` | |||||
| `; | |||||
| export const RemoveIcon = styled(Remove)``; |
| import ReviewDetails from "./ReviewDetails/ReviewDetails"; | import ReviewDetails from "./ReviewDetails/ReviewDetails"; | ||||
| import RemoveButton from "./RemoveButton/RemoveButton"; | import RemoveButton from "./RemoveButton/RemoveButton"; | ||||
| import ReviewOffer from "./ReviewOffer/ReviewOffer"; | import ReviewOffer from "./ReviewOffer/ReviewOffer"; | ||||
| import GivenReviewsHeader from "./GivenReviewsHeader/GivenReviewsHeader"; | |||||
| const UserReviewsSingleCard = (props) => { | const UserReviewsSingleCard = (props) => { | ||||
| const handleRemove = () => { | const handleRemove = () => { | ||||
| props.handleRemove(); | props.handleRemove(); | ||||
| }; | }; | ||||
| return ( | return ( | ||||
| <ReviewContainer> | <ReviewContainer> | ||||
| {!props.rightReviews && ( | |||||
| <GivenReviewsHeader | |||||
| hasGivenReview={props.hasGivenReview} | |||||
| userWhoReceived={props.review?.userWhoReceived} | |||||
| /> | |||||
| )} | |||||
| <ReviewerProfile | <ReviewerProfile | ||||
| profileName={props.review?.name} | profileName={props.review?.name} | ||||
| profileImage={props.review?.image} | profileImage={props.review?.image} | ||||
| isGoodCommunication={props.review?.isGoodCommunication} | isGoodCommunication={props.review?.isGoodCommunication} | ||||
| /> | /> | ||||
| {props.showRemoveIcon && ( | {props.showRemoveIcon && ( | ||||
| <RemoveButton review={props.review} onClick={handleRemove} /> | |||||
| <RemoveButton | |||||
| review={props.review} | |||||
| onClick={handleRemove} | |||||
| hasGivenReview={props.hasGivenReview} | |||||
| /> | |||||
| )} | )} | ||||
| <ReviewOffer | <ReviewOffer | ||||
| name={props.review?.offerName} | name={props.review?.offerName} | ||||
| review: PropTypes.any, | review: PropTypes.any, | ||||
| handleRemove: PropTypes.func, | handleRemove: PropTypes.func, | ||||
| showRemoveIcon: PropTypes.bool, | showRemoveIcon: PropTypes.bool, | ||||
| hasGivenReview: PropTypes.bool, | |||||
| userWhoReceived: PropTypes.any, | |||||
| rightReviews: PropTypes.bool, | |||||
| }; | }; | ||||
| export default UserReviewsSingleCard; | export default UserReviewsSingleCard; |
| export const ReviewContainer = styled(Box)` | export const ReviewContainer = styled(Box)` | ||||
| padding-top: 18px; | padding-top: 18px; | ||||
| padding-right: 12px; | |||||
| position: relative; | position: relative; | ||||
| @media (max-width: 600px) { | @media (max-width: 600px) { | ||||
| height: 258px; | height: 258px; | ||||
| left: -18px; | left: -18px; | ||||
| margin-top: 18px; | margin-top: 18px; | ||||
| } | } | ||||
| `; | |||||
| `; |
| const reviews = useSelector(selectSelectedReviews); | const reviews = useSelector(selectSelectedReviews); | ||||
| const dispatch = useDispatch(); | const dispatch = useDispatch(); | ||||
| const [value, setValue] = useState(); | const [value, setValue] = useState(); | ||||
| console.log(reviews); | |||||
| const changeValue = (event) => { | const changeValue = (event) => { | ||||
| if (props.isAdmin) { | if (props.isAdmin) { | ||||
| console.log("sortiranje: ", event.target.value) | |||||
| console.log("sortiranje: ", event.target.value); | |||||
| // if(event.target.value.value === 1) { | |||||
| // dispatch(setReviews(reviews.givenReviews)); | |||||
| // } else { | |||||
| // dispatch(setReviews(reviews.receivedReviews)); | |||||
| // } | |||||
| } else { | } else { | ||||
| dispatch( | dispatch( | ||||
| setReviews( | setReviews( | ||||
| ) | ) | ||||
| ) | ) | ||||
| ); | ); | ||||
| props.changeSorting(); | |||||
| } | } | ||||
| props.changeSorting(event.target.value); | |||||
| setValue(event.target.value); | setValue(event.target.value); | ||||
| }; | }; | ||||
| const sortEnum = useMemo(() => { | const sortEnum = useMemo(() => { |
| import React, { useEffect, useMemo, useRef } from "react"; | |||||
| import React, { useState, useEffect, useMemo, useRef } from "react"; | |||||
| import PropTypes from "prop-types"; | import PropTypes from "prop-types"; | ||||
| import { | import { | ||||
| ReviewList, | ReviewList, | ||||
| import { | import { | ||||
| fetchReviews, | fetchReviews, | ||||
| setReviews, | setReviews, | ||||
| fetchReviewsAsAdmin, | |||||
| } from "../../store/actions/review/reviewActions"; | } from "../../store/actions/review/reviewActions"; | ||||
| import { selectIsLoadingByActionType } from "../../store/selectors/loadingSelectors"; | import { selectIsLoadingByActionType } from "../../store/selectors/loadingSelectors"; | ||||
| import SkeletonUserReviews from "./SkeletonUserReviews/SkeletonUserReviews"; | import SkeletonUserReviews from "./SkeletonUserReviews/SkeletonUserReviews"; | ||||
| import { ONE_OFFER_SCOPE } from "../../store/actions/offers/offersActionConstants"; | import { ONE_OFFER_SCOPE } from "../../store/actions/offers/offersActionConstants"; | ||||
| import { REVIEW_GET_SCOPE } from "../../store/actions/review/reviewActionConstants"; | |||||
| import { | |||||
| REVIEW_GET_SCOPE, | |||||
| REVIEW_GET_AS_ADMIN_SCOPE, | |||||
| } from "../../store/actions/review/reviewActionConstants"; | |||||
| import ReviewsSorting from "./ReviewsSorting/ReviewsSorting"; | import ReviewsSorting from "./ReviewsSorting/ReviewsSorting"; | ||||
| import { sortReviews } from "../../util/helpers/reviewsHelper"; | import { sortReviews } from "../../util/helpers/reviewsHelper"; | ||||
| // import { selectUserId } from "../../store/selectors/loginSelectors"; | |||||
| const UserReviews = (props) => { | const UserReviews = (props) => { | ||||
| const [isGiven, setIsGiven] = useState(true); | |||||
| const { t } = useTranslation(); | const { t } = useTranslation(); | ||||
| const offer = useSelector(selectOffer); | const offer = useSelector(selectOffer); | ||||
| const reviews = useSelector(selectSelectedReviews); | const reviews = useSelector(selectSelectedReviews); | ||||
| const dispatch = useDispatch(); | const dispatch = useDispatch(); | ||||
| const listRef = useRef(null); | const listRef = useRef(null); | ||||
| const sortRef = useRef(null); | const sortRef = useRef(null); | ||||
| // const userId = useSelector(selectUserId); | |||||
| const isLoadingReview = useSelector( | const isLoadingReview = useSelector( | ||||
| selectIsLoadingByActionType( | selectIsLoadingByActionType( | ||||
| props.isProfileReviews ? REVIEW_GET_SCOPE : ONE_OFFER_SCOPE | |||||
| props.isAdmin | |||||
| ? REVIEW_GET_AS_ADMIN_SCOPE | |||||
| : props.isProfileReviews | |||||
| ? REVIEW_GET_SCOPE | |||||
| : ONE_OFFER_SCOPE | |||||
| ) | ) | ||||
| ); | ); | ||||
| useEffect(() => { | useEffect(() => { | ||||
| if (props.profileReviews && routeMatch.params?.idProfile) { | |||||
| let idProfile = routeMatch.params.idProfile; | |||||
| dispatch(fetchReviews(idProfile)); | |||||
| let idProfile = routeMatch.params.idProfile; | |||||
| if (idProfile) { | |||||
| if (props.isAdmin) { | |||||
| dispatch(fetchReviewsAsAdmin(idProfile)); | |||||
| } else { | |||||
| dispatch(fetchReviews(idProfile)); | |||||
| } | |||||
| } | } | ||||
| // if (props.profileReviews && routeMatch.params?.idProfile) { | |||||
| // let idProfile = routeMatch.params.idProfile; | |||||
| // dispatch(fetchReviews(idProfile)); | |||||
| // } | |||||
| }, [props.profileReviews, routeMatch]); | }, [props.profileReviews, routeMatch]); | ||||
| const lastThreeReviews = useMemo(() => { | const lastThreeReviews = useMemo(() => { | ||||
| if (props.givingReview) { | |||||
| return [...props.profileReviews]; | |||||
| console.log("isGiven", isGiven); | |||||
| if (props.isAdmin) { | |||||
| if (isGiven) { | |||||
| return reviews.givenReviews; | |||||
| } else { | |||||
| return reviews.receivedReviews; | |||||
| } | |||||
| } | } | ||||
| if (props.isProfileReviews) { | if (props.isProfileReviews) { | ||||
| return [...reviews]; | |||||
| return reviews; | |||||
| } | |||||
| if (props.givingReview) { | |||||
| return [...props.profileReviews]; | |||||
| } | } | ||||
| if (offer?.companyData?.lastThreeReviews) { | if (offer?.companyData?.lastThreeReviews) { | ||||
| // Making array of reviews in same order(sorting) so when comparing | // Making array of reviews in same order(sorting) so when comparing | ||||
| return [...reviews]; | return [...reviews]; | ||||
| } | } | ||||
| return []; | return []; | ||||
| }, [props.profileReviews, offer, props.isProfileReviews, reviews]); | |||||
| }, [props.profileReviews, offer, props.isProfileReviews, reviews, isGiven]); | |||||
| const scrollToTop = () => { | |||||
| const handleChangeSorting = (newSortOption) => { | |||||
| console.log(newSortOption); | |||||
| listRef.current.scrollTo({ top: 0, behaviour: "smooth" }); | listRef.current.scrollTo({ top: 0, behaviour: "smooth" }); | ||||
| if (props.isAdmin) { | |||||
| if (newSortOption.value === 1) { | |||||
| setIsGiven(true); | |||||
| } else { | |||||
| setIsGiven(false); | |||||
| } | |||||
| } | |||||
| }; | }; | ||||
| console.log(sortRef.current?.sortValue); | console.log(sortRef.current?.sortValue); | ||||
| console.log(lastThreeReviews); | |||||
| return ( | return ( | ||||
| <UserReviewsContainer className={props.className}> | <UserReviewsContainer className={props.className}> | ||||
| {!props.givingReview && | {!props.givingReview && | ||||
| <ReviewsTitle>{t("reviews.rates")}</ReviewsTitle> | <ReviewsTitle>{t("reviews.rates")}</ReviewsTitle> | ||||
| </ReviewsHeaderTitle> | </ReviewsHeaderTitle> | ||||
| <ReviewsSorting | <ReviewsSorting | ||||
| changeSorting={scrollToTop} | |||||
| changeSorting={handleChangeSorting} | |||||
| ref={sortRef} | ref={sortRef} | ||||
| isAdmin={props.isAdmin} | isAdmin={props.isAdmin} | ||||
| /> | /> | ||||
| key={index} | key={index} | ||||
| hasGivenReview={sortRef.current?.hasGivenReview} | hasGivenReview={sortRef.current?.hasGivenReview} | ||||
| givingReview={props.givingReview} | givingReview={props.givingReview} | ||||
| rightReviews={props.rightReviews} | |||||
| /> | /> | ||||
| )) | )) | ||||
| ) : ( | ) : ( | ||||
| givingReview: PropTypes.bool, | givingReview: PropTypes.bool, | ||||
| offer: PropTypes.any, | offer: PropTypes.any, | ||||
| isAdmin: PropTypes.bool, | isAdmin: PropTypes.bool, | ||||
| rightReviews: PropTypes.bool, | |||||
| }; | }; | ||||
| UserReviews.defaultProps = { | UserReviews.defaultProps = { | ||||
| isProfileReviews: false, | isProfileReviews: false, |
| export const KEY_SORTBY = "sortBy"; | export const KEY_SORTBY = "sortBy"; | ||||
| export const KEY_SORT_DATE = "_des_date"; | export const KEY_SORT_DATE = "_des_date"; | ||||
| export const KEY_SORT_POPULAR = "_des_popular"; | export const KEY_SORT_POPULAR = "_des_popular"; | ||||
| export const KEY_LOCATION = "location" | |||||
| export const KEY_LOCATION = "location"; | |||||
| export const KEY_COMPANY = "companyName"; | |||||
| export const KEY_NAME = "name"; | export const KEY_NAME = "name"; | ||||
| export const KEY_SEARCH = "search" | |||||
| export const KEY_SEARCH = "search"; | |||||
| export const VALUE_SORTBY_NEW = "newest"; | export const VALUE_SORTBY_NEW = "newest"; | ||||
| export const VALUE_SORTBY_OLD = "oldest"; | export const VALUE_SORTBY_OLD = "oldest"; | ||||
| export const VALUE_SORTBY_POPULAR = "popular"; | export const VALUE_SORTBY_POPULAR = "popular"; |
| dispatch(fetchAllProfiles()); | dispatch(fetchAllProfiles()); | ||||
| }, []); | }, []); | ||||
| const selectedCompanies = useMemo(() => Array.isArray(selectedCompaniesRedux) ? selectedCompaniesRedux : []) | |||||
| const allCompanies = useMemo(() => Array.isArray(allCompaniesRedux) ? selectedCompaniesRedux : []) | |||||
| const selectedCompanies = useMemo(() => | |||||
| Array.isArray(selectedCompaniesRedux) ? selectedCompaniesRedux : [] | |||||
| ); | |||||
| const allCompanies = useMemo(() => | |||||
| Array.isArray(allCompaniesRedux) ? allCompaniesRedux : [] | |||||
| ); | |||||
| useEffect(() => { | useEffect(() => { | ||||
| setSelectedCompaniesLocally(selectedCompanies); | setSelectedCompaniesLocally(selectedCompanies); | ||||
| let companiesToPush = []; | let companiesToPush = []; | ||||
| companies.forEach((companyName) => { | companies.forEach((companyName) => { | ||||
| companiesToPush.push( | companiesToPush.push( | ||||
| allCompanies.find((p) => p.company.name === companyName) | |||||
| allCompanies.find((p) => p.companyName === companyName) | |||||
| ); | ); | ||||
| }); | }); | ||||
| setSelectedCompanies([...companiesToPush]); | setSelectedCompanies([...companiesToPush]); |
| import { | import { | ||||
| KEY_CATEGORY, | KEY_CATEGORY, | ||||
| KEY_LOCATION, | KEY_LOCATION, | ||||
| KEY_COMPANY, | |||||
| KEY_PAGE, | KEY_PAGE, | ||||
| KEY_SEARCH, | KEY_SEARCH, | ||||
| KEY_SORTBY, | KEY_SORTBY, | ||||
| queryObject[KEY_LOCATION] | queryObject[KEY_LOCATION] | ||||
| ); | ); | ||||
| } | } | ||||
| if (KEY_COMPANY in queryObject) { | |||||
| filters.companies.setSelectedCompaniesFromArray( | |||||
| queryObject[KEY_COMPANY] | |||||
| ); | |||||
| } | |||||
| if (KEY_SORTBY in queryObject) { | if (KEY_SORTBY in queryObject) { | ||||
| sorting.changeSortingFromName(queryObject[KEY_SORTBY]); | sorting.changeSortingFromName(queryObject[KEY_SORTBY]); | ||||
| } | } | ||||
| const clearFiltersAndApply = () => { | const clearFiltersAndApply = () => { | ||||
| clear(); | clear(); | ||||
| console.log('clearfiltersandapply filterscleared') | |||||
| console.log("clearfiltersandapply filterscleared"); | |||||
| setFiltersCleared(true); | setFiltersCleared(true); | ||||
| }; | }; | ||||
| const clearOnlyFiltersAndApply = () => { | const clearOnlyFiltersAndApply = () => { | ||||
| filters.clear(); | filters.clear(); | ||||
| paging.changePage(1); | paging.changePage(1); | ||||
| console.log('clearonlyfiltersandapply filterscleared') | |||||
| console.log("clearonlyfiltersandapply filterscleared"); | |||||
| setFiltersCleared(true); | setFiltersCleared(true); | ||||
| }; | }; |
| finishedReviewTitle: "Hvala vam", | finishedReviewTitle: "Hvala vam", | ||||
| finishedReviewAltTitle: "na izdvojenom vremenu i datoj oceni!", | finishedReviewAltTitle: "na izdvojenom vremenu i datoj oceni!", | ||||
| sortBy: "Sortiraj po", | sortBy: "Sortiraj po", | ||||
| offerTitle: "Proizvod:" | |||||
| offerTitle: "Proizvod:", | |||||
| givenHeaderTitle: "Ocenjena kompanija: ", | |||||
| }, | }, | ||||
| messages: { | messages: { | ||||
| headerTitle: "Moje Ćaskanje", | headerTitle: "Moje Ćaskanje", |
| content={<ItemDetails singleOffer />} | content={<ItemDetails singleOffer />} | ||||
| rightCard={ | rightCard={ | ||||
| <> | <> | ||||
| <ProfileMini /> <UserReviews /> | |||||
| <ProfileMini /> <UserReviews rightReviews /> | |||||
| </> | </> | ||||
| } | } | ||||
| /> | /> |
| editLocation: "admin/locations/{locationId}", | editLocation: "admin/locations/{locationId}", | ||||
| deleteLocation: "admin/locations/{locationId}", | deleteLocation: "admin/locations/{locationId}", | ||||
| }, | }, | ||||
| reviews: { | |||||
| getUserReviewsAsAdmin: 'admin/reviews/{userId}' | |||||
| } | |||||
| }, | }, | ||||
| }; | }; |
| replaceInUrl(apiEndpoints.reviews.removeReview, { id: payload }) | replaceInUrl(apiEndpoints.reviews.removeReview, { id: payload }) | ||||
| ); | ); | ||||
| }; | }; | ||||
| export const attemptFetchReviewsAsAdmin = (payload) => { | |||||
| return getRequest( | |||||
| replaceInUrl(apiEndpoints.admin.reviews.getUserReviewsAsAdmin, {userId: payload}) | |||||
| ); | |||||
| }; |
| export const REVIEW_REMOVE_SUCCESS = createSuccessType(REVIEW_REMOVE_SCOPE); | export const REVIEW_REMOVE_SUCCESS = createSuccessType(REVIEW_REMOVE_SCOPE); | ||||
| export const REVIEW_REMOVE_ERROR = createErrorType(REVIEW_REMOVE_SCOPE); | export const REVIEW_REMOVE_ERROR = createErrorType(REVIEW_REMOVE_SCOPE); | ||||
| export const REVIEW_GET_AS_ADMIN_SCOPE = 'REVIEW_GET_AS_ADMIN_SCOPE'; | |||||
| export const REVIEW_GET_AS_ADMIN = createFetchType(REVIEW_GET_AS_ADMIN_SCOPE); | |||||
| export const REVIEW_GET_AS_ADMIN_SUCCESS = createSuccessType(REVIEW_GET_AS_ADMIN_SCOPE); | |||||
| export const REVIEW_GET_AS_ADMIN_ERROR = createErrorType(REVIEW_GET_AS_ADMIN_SCOPE); | |||||
| export const REVIEW_SET = createSetType("REVIEW_SET"); | export const REVIEW_SET = createSetType("REVIEW_SET"); |
| REVIEW_REMOVE, | REVIEW_REMOVE, | ||||
| REVIEW_REMOVE_ERROR, | REVIEW_REMOVE_ERROR, | ||||
| REVIEW_REMOVE_SUCCESS, | REVIEW_REMOVE_SUCCESS, | ||||
| REVIEW_GET_AS_ADMIN, | |||||
| REVIEW_GET_AS_ADMIN_SUCCESS, | |||||
| REVIEW_GET_AS_ADMIN_ERROR, | |||||
| REVIEW_SET, | REVIEW_SET, | ||||
| } from "./reviewActionConstants"; | } from "./reviewActionConstants"; | ||||
| export const removeReviewError = () => ({ | export const removeReviewError = () => ({ | ||||
| type: REVIEW_REMOVE_ERROR, | type: REVIEW_REMOVE_ERROR, | ||||
| }); | }); | ||||
| export const fetchReviewsAsAdmin = (payload) => ({ | |||||
| type: REVIEW_GET_AS_ADMIN, | |||||
| payload, | |||||
| }); | |||||
| export const fetchReviewsAsAdminSuccess = () => ({ | |||||
| type: REVIEW_GET_AS_ADMIN_SUCCESS, | |||||
| }); | |||||
| export const fetchReviewsAsAdminError = () => ({ | |||||
| type: REVIEW_GET_AS_ADMIN_ERROR | |||||
| }) | |||||
| export const setReviews = (payload) => ({ | export const setReviews = (payload) => ({ | ||||
| type: REVIEW_SET, | type: REVIEW_SET, | ||||
| payload, | payload, | ||||
| }); | }); | ||||
| attemptFetchReview, | attemptFetchReview, | ||||
| attemptGiveReview, | attemptGiveReview, | ||||
| attemptRemoveReview, | attemptRemoveReview, | ||||
| attemptFetchReviewsAsAdmin, | |||||
| } from "../../request/reviewRequest"; | } from "../../request/reviewRequest"; | ||||
| import { | import { | ||||
| REVIEW_GET, | REVIEW_GET, | ||||
| REVIEW_GIVE, | REVIEW_GIVE, | ||||
| REVIEW_REMOVE, | REVIEW_REMOVE, | ||||
| REVIEW_GET_AS_ADMIN, | |||||
| } from "../actions/review/reviewActionConstants"; | } from "../actions/review/reviewActionConstants"; | ||||
| import { | import { | ||||
| fetchReviewsError, | fetchReviewsError, | ||||
| giveReviewSuccess, | giveReviewSuccess, | ||||
| removeReviewError, | removeReviewError, | ||||
| removeReviewSuccess, | removeReviewSuccess, | ||||
| fetchReviewsAsAdminSuccess, | |||||
| fetchReviewsAsAdminError, | |||||
| setReviews, | setReviews, | ||||
| } from "../actions/review/reviewActions"; | } from "../actions/review/reviewActions"; | ||||
| import { selectUserId } from "../selectors/loginSelectors"; | import { selectUserId } from "../selectors/loginSelectors"; | ||||
| } | } | ||||
| } | } | ||||
| function* fetchReviewsAsAdmin(payload) { | |||||
| try { | |||||
| console.log(payload); | |||||
| const data = yield call(attemptFetchReviewsAsAdmin, payload.payload); | |||||
| if (payload.payload.handleApiResponseSuccess) { | |||||
| yield call(payload.payload.handleApiResponseSuccess); | |||||
| } | |||||
| console.log(data); | |||||
| yield put(setReviews(data.data)); | |||||
| yield put(fetchReviewsAsAdminSuccess()); | |||||
| } catch (e) { | |||||
| yield put(fetchReviewsAsAdminError()); | |||||
| console.dir(e); | |||||
| } | |||||
| } | |||||
| export default function* reviewSaga() { | export default function* reviewSaga() { | ||||
| yield all([ | yield all([ | ||||
| takeLatest(REVIEW_GET, fetchReviews), | takeLatest(REVIEW_GET, fetchReviews), | ||||
| takeLatest(REVIEW_GIVE, giveReview), | takeLatest(REVIEW_GIVE, giveReview), | ||||
| takeLatest(REVIEW_REMOVE, removeReview), | takeLatest(REVIEW_REMOVE, removeReview), | ||||
| takeLatest(REVIEW_GET_AS_ADMIN, fetchReviewsAsAdmin), | |||||
| ]); | ]); | ||||
| } | } |
| export const filterCompanies = (data, regexp) => { | export const filterCompanies = (data, regexp) => { | ||||
| return data.filter((company) => { | return data.filter((company) => { | ||||
| return regexp.test(company?.company?.name); | |||||
| return regexp.test(company?.companyName); | |||||
| }); | }); | ||||
| }; | }; |
| import { | import { | ||||
| initialSize, | initialSize, | ||||
| KEY_CATEGORY, | KEY_CATEGORY, | ||||
| KEY_COMPANY, | |||||
| KEY_LOCATION, | KEY_LOCATION, | ||||
| KEY_NAME, | KEY_NAME, | ||||
| KEY_PAGE, | KEY_PAGE, | ||||
| newQueryObject.append(KEY_LOCATION, item); | newQueryObject.append(KEY_LOCATION, item); | ||||
| }); | }); | ||||
| } | } | ||||
| if (queryObject.has(KEY_COMPANY)) { | |||||
| const arrayOfCompanies = queryObject.getAll(KEY_COMPANY); | |||||
| arrayOfCompanies.forEach((item) => { | |||||
| console.log(item); | |||||
| newQueryObject.append(KEY_COMPANY, item); | |||||
| }); | |||||
| } | |||||
| if (queryObject.has(KEY_SORTBY)) { | if (queryObject.has(KEY_SORTBY)) { | ||||
| newQueryObject.delete(KEY_SORTBY); | newQueryObject.delete(KEY_SORTBY); | ||||
| if (queryObject.get(KEY_SORTBY) === VALUE_SORTBY_NEW) { | if (queryObject.get(KEY_SORTBY) === VALUE_SORTBY_NEW) { | ||||
| newObject[KEY_LOCATION].push(item); | newObject[KEY_LOCATION].push(item); | ||||
| }); | }); | ||||
| } | } | ||||
| if (queryObject.has(KEY_COMPANY)) { | |||||
| const arrayOfCompanies = queryObject.getAll(KEY_COMPANY); | |||||
| newObject[KEY_COMPANY] = []; | |||||
| arrayOfCompanies.forEach((item) => { | |||||
| newObject[KEY_COMPANY].push(item); | |||||
| }); | |||||
| } | |||||
| if (queryObject.has(KEY_SORTBY)) { | if (queryObject.has(KEY_SORTBY)) { | ||||
| newObject[KEY_SORTBY] = queryObject.get(KEY_SORTBY); | newObject[KEY_SORTBY] = queryObject.get(KEY_SORTBY); | ||||
| } | } | ||||
| let categoryString = `${ALL_CATEGORIES}`; | let categoryString = `${ALL_CATEGORIES}`; | ||||
| let subcategoryString = ""; | let subcategoryString = ""; | ||||
| let locationsString = ""; | let locationsString = ""; | ||||
| let companiesString = ""; | |||||
| // Adding category to header string | // Adding category to header string | ||||
| if (filters?.category?.selectedCategory?.name) { | if (filters?.category?.selectedCategory?.name) { | ||||
| categoryString = filters.category.selectedCategory?.name; | categoryString = filters.category.selectedCategory?.name; | ||||
| } | } | ||||
| }); | }); | ||||
| } | } | ||||
| let headerStringLocal = categoryString + subcategoryString + locationsString; | |||||
| if ( | |||||
| filters?.companies?.selectedCompanies && | |||||
| filters?.companies?.selectedCompanies?.length > 0 | |||||
| ) { | |||||
| companiesString = SPREAD; | |||||
| filters.companies.selectedCompanies.forEach((company, index) => { | |||||
| // Checking if item is last | |||||
| console.log(company); | |||||
| if (index + 1 === filters.companies.selectedCompanies.length) { | |||||
| companiesString += company.companyName; | |||||
| } else { | |||||
| companiesString += company.companyName + COMMA; | |||||
| } | |||||
| }); | |||||
| } | |||||
| let headerStringLocal = | |||||
| categoryString + subcategoryString + locationsString + companiesString; | |||||
| return { | return { | ||||
| categoryString, | categoryString, | ||||
| subcategoryString, | subcategoryString, | ||||
| locationsString, | locationsString, | ||||
| companiesString, | |||||
| text: headerStringLocal, | text: headerStringLocal, | ||||
| }; | }; | ||||
| }; | }; | ||||
| let categoryString = `${ALL_CATEGORIES}`; | let categoryString = `${ALL_CATEGORIES}`; | ||||
| let subcategoryString = ""; | let subcategoryString = ""; | ||||
| let locationsString = ""; | let locationsString = ""; | ||||
| let companiesString = ""; | |||||
| if (KEY_CATEGORY in queryObject) { | if (KEY_CATEGORY in queryObject) { | ||||
| categoryString = queryObject[KEY_CATEGORY]; | categoryString = queryObject[KEY_CATEGORY]; | ||||
| if (KEY_SUBCATEGORY in queryObject) { | if (KEY_SUBCATEGORY in queryObject) { | ||||
| }); | }); | ||||
| } | } | ||||
| } | } | ||||
| let headerStringLocal = categoryString + subcategoryString + locationsString; | |||||
| if (KEY_COMPANY in queryObject) { | |||||
| companiesString = SPREAD; | |||||
| if (!Array.isArray(queryObject[KEY_COMPANY])) { | |||||
| companiesString += queryObject[KEY_COMPANY]; | |||||
| } else { | |||||
| queryObject[KEY_COMPANY].forEach((company, index) => { | |||||
| // Checking if item is last | |||||
| if (index + 1 === queryObject[KEY_COMPANY].length) { | |||||
| companiesString += company; | |||||
| } else { | |||||
| companiesString += company + COMMA; | |||||
| } | |||||
| }); | |||||
| } | |||||
| } | |||||
| let headerStringLocal = | |||||
| categoryString + subcategoryString + locationsString + companiesString; | |||||
| return { | return { | ||||
| categoryString, | categoryString, | ||||
| subcategoryString, | subcategoryString, | ||||
| locationsString, | locationsString, | ||||
| companiesString, | |||||
| text: headerStringLocal, | text: headerStringLocal, | ||||
| }; | }; | ||||
| }; | }; | ||||
| newQueryString.append(KEY_LOCATION, location?.city) | newQueryString.append(KEY_LOCATION, location?.city) | ||||
| ); | ); | ||||
| } | } | ||||
| if (filters.companies.selectedCompaniesLocally?.length > 0) { | |||||
| filters.companies.selectedCompaniesLocally.forEach((company) => | |||||
| newQueryString.append(KEY_COMPANY, company?.companyName) | |||||
| ); | |||||
| } | |||||
| if (sorting.selectedSortOption?.value) { | if (sorting.selectedSortOption?.value) { | ||||
| if (sorting.selectedSortOption?.value === sortEnum.NEW.value) { | if (sorting.selectedSortOption?.value === sortEnum.NEW.value) { | ||||
| newQueryString.append(KEY_SORTBY, VALUE_SORTBY_NEW); | newQueryString.append(KEY_SORTBY, VALUE_SORTBY_NEW); |