| line-height: 22px; | line-height: 22px; | ||||
| margin-top: 5px; | margin-top: 5px; | ||||
| font-size: 18px; | font-size: 18px; | ||||
| max-width: none; | |||||
| margin-bottom: 0px !important; | margin-bottom: 0px !important; | ||||
| `} | `} |
| const threeDotsBefore = props.current - 2 > 1; | const threeDotsBefore = props.current - 2 > 1; | ||||
| const threeDotsAfter = props.current + 2 < pages; | const threeDotsAfter = props.current + 2 < pages; | ||||
| return ( | return ( | ||||
| <PagingContainer> | |||||
| <PagingContainer className={props.className}> | |||||
| {/* Left arrow */} | {/* Left arrow */} | ||||
| <Arrow | <Arrow | ||||
| onClick={() => props.changePage(props.current - 1)} | onClick={() => props.changePage(props.current - 1)} | ||||
| current: PropTypes.number, | current: PropTypes.number, | ||||
| changePage: PropTypes.func, | changePage: PropTypes.func, | ||||
| customPaging: PropTypes.bool, | customPaging: PropTypes.bool, | ||||
| className: PropTypes.string, | |||||
| }; | }; | ||||
| Paging.defaultProps = { | Paging.defaultProps = { | ||||
| elementsPerPage: 10, | elementsPerPage: 10, |
| import { selectUserId } from "../../store/selectors/loginSelectors"; | import { selectUserId } from "../../store/selectors/loginSelectors"; | ||||
| import { useRouteMatch } from "react-router-dom"; | import { useRouteMatch } from "react-router-dom"; | ||||
| import { fetchProfile } from "../../store/actions/profile/profileActions"; | import { fetchProfile } from "../../store/actions/profile/profileActions"; | ||||
| import { fetchProfileOffers } from "../../store/actions/offers/offersActions"; | |||||
| import Header from "./Header/Header"; | import Header from "./Header/Header"; | ||||
| const Profile = (props) => { | const Profile = (props) => { | ||||
| useEffect(() => { | useEffect(() => { | ||||
| if (idProfile?.length > 0) { | if (idProfile?.length > 0) { | ||||
| dispatch(fetchProfile(idProfile)); | dispatch(fetchProfile(idProfile)); | ||||
| dispatch(fetchProfileOffers(idProfile)); | |||||
| } | } | ||||
| }, [idProfile]); | }, [idProfile]); | ||||
| const isMyProfile = useMemo(() => { | const isMyProfile = useMemo(() => { | ||||
| <ProfileContainer className={props.className}> | <ProfileContainer className={props.className}> | ||||
| <Header isAdmin={props.isAdmin} /> | <Header isAdmin={props.isAdmin} /> | ||||
| <ProfileCard isAdmin={props.isAdmin} isMyProfile={isMyProfile} /> | <ProfileCard isAdmin={props.isAdmin} isMyProfile={isMyProfile} /> | ||||
| <ProfileOffers isAdmin={props.isAdmin} isMyProfile={isMyProfile} /> | |||||
| <ProfileOffers | |||||
| isAdmin={props.isAdmin} | |||||
| isMyProfile={isMyProfile} | |||||
| idProfile={idProfile} | |||||
| /> | |||||
| </ProfileContainer> | </ProfileContainer> | ||||
| ); | ); | ||||
| }; | }; |
| OffersContainer, | OffersContainer, | ||||
| OffersScroller, | OffersScroller, | ||||
| ProfileOffersContainer, | ProfileOffersContainer, | ||||
| ProfilePaging, | |||||
| SkeletonContainer, | SkeletonContainer, | ||||
| } from "./ProfileOffers.styled"; | } from "./ProfileOffers.styled"; | ||||
| import { useState } from "react"; | import { useState } from "react"; | ||||
| import { useEffect } from "react"; | |||||
| import { useSelector } from "react-redux"; | |||||
| // import { useEffect } from "react"; | |||||
| import { useDispatch, useSelector } from "react-redux"; | |||||
| import OfferCard from "../../Cards/OfferCard/OfferCard"; | import OfferCard from "../../Cards/OfferCard/OfferCard"; | ||||
| import { selectProfileOffers } from "../../../store/selectors/offersSelectors"; | |||||
| import { | |||||
| selectProfileOffers, | |||||
| selectTotalOffers, | |||||
| } from "../../../store/selectors/offersSelectors"; | |||||
| import { selectLatestChats } from "../../../store/selectors/chatSelectors"; | import { selectLatestChats } from "../../../store/selectors/chatSelectors"; | ||||
| import { selectUserId } from "../../../store/selectors/loginSelectors"; | import { selectUserId } from "../../../store/selectors/loginSelectors"; | ||||
| import NoProfileOffers from "./NoProfileOffers.js/NoProfileOffers"; | import NoProfileOffers from "./NoProfileOffers.js/NoProfileOffers"; | ||||
| import HeaderTitle from "./HeaderTitle/HeaderTitle"; | import HeaderTitle from "./HeaderTitle/HeaderTitle"; | ||||
| import SearchBar from "./SearchBar/SearchBar"; | import SearchBar from "./SearchBar/SearchBar"; | ||||
| import { messageUserHelper } from "../../../util/helpers/messageHelper"; | import { messageUserHelper } from "../../../util/helpers/messageHelper"; | ||||
| import { sortEnum } from "../../../enums/sortEnum"; | |||||
| import usePaging from "../../../hooks/useOffers/usePaging"; | |||||
| import { useEffect } from "react"; | |||||
| import { | |||||
| fetchProfileOffers, | |||||
| setProfileOffers, | |||||
| } from "../../../store/actions/offers/offersActions"; | |||||
| import { useRef } from "react"; | |||||
| const ProfileOffers = (props) => { | const ProfileOffers = (props) => { | ||||
| const [offersToShow, setOffersToShow] = useState([]); | |||||
| const isLoadingMineOffers = useSelector( | const isLoadingMineOffers = useSelector( | ||||
| selectIsLoadingByActionType(OFFERS_PROFILE_SCOPE) | selectIsLoadingByActionType(OFFERS_PROFILE_SCOPE) | ||||
| ); | ); | ||||
| const { isMobile } = useIsMobile(); | const { isMobile } = useIsMobile(); | ||||
| const userId = useSelector(selectUserId); | const userId = useSelector(selectUserId); | ||||
| const arrayForMapping = Array.apply(null, Array(4)).map(() => {}); | const arrayForMapping = Array.apply(null, Array(4)).map(() => {}); | ||||
| const [searchValue, setSearchValue] = useState(""); | |||||
| const [sortOption, setSortOption] = useState(sortEnum.INITIAL); | |||||
| const [append, setAppend] = useState(true); | |||||
| const paging = usePaging(null, true); | |||||
| const total = useSelector(selectTotalOffers); | |||||
| const dispatch = useDispatch(); | |||||
| const searchRef = useRef(null); | |||||
| useEffect(() => { | |||||
| dispatch( | |||||
| fetchProfileOffers({ | |||||
| idProfile: props.idProfile, | |||||
| searchValue: searchValue, | |||||
| sortOption: sortOption, | |||||
| append: isMobile && append, | |||||
| page: paging.currentPage, | |||||
| }) | |||||
| ); | |||||
| setAppend(true); | |||||
| }, [searchValue, sortOption, paging.currentPage]); | |||||
| useEffect(() => { | |||||
| if ( | |||||
| isLoadingMineOffers === false && | |||||
| searchRef.current && | |||||
| searchRef.current?.searchValue !== searchValue | |||||
| ) { | |||||
| searchRef.current.changeSearchValue(searchValue); | |||||
| } | |||||
| }, [isLoadingMineOffers]); | |||||
| const messageUser = (offer) => { | const messageUser = (offer) => { | ||||
| messageUserHelper(chats, offer, userId); | messageUserHelper(chats, offer, userId); | ||||
| }; | }; | ||||
| useEffect(() => { | |||||
| if (profileOffers) setOffersToShow(profileOffers); | |||||
| }, [profileOffers]); | |||||
| const handleInfiniteScroll = () => { | |||||
| if (total !== profileOffers?.length) { | |||||
| paging.goToNextPage(); | |||||
| } | |||||
| }; | |||||
| const handleSearch = (value) => { | |||||
| let newOffersToShow = profileOffers.filter((item) => | |||||
| item.name.toLowerCase().includes(value.toLowerCase()) | |||||
| ); | |||||
| setOffersToShow([...newOffersToShow]); | |||||
| const handleChangeSortOption = (newValue) => { | |||||
| dispatch(setProfileOffers([])); | |||||
| setAppend(true); | |||||
| paging.changePage(1); | |||||
| setSortOption(newValue); | |||||
| }; | |||||
| const handleSearch = (newValue) => { | |||||
| dispatch(setProfileOffers([])); | |||||
| paging.changePage(1); | |||||
| setSearchValue(newValue); | |||||
| }; | }; | ||||
| return ( | return ( | ||||
| <ProfileOffersContainer isAdmin={props.isAdmin}> | <ProfileOffersContainer isAdmin={props.isAdmin}> | ||||
| {isLoadingMineOffers || isLoadingMineOffers === undefined ? ( | |||||
| {(isLoadingMineOffers || isLoadingMineOffers === undefined) && | |||||
| profileOffers?.length === 0 ? ( | |||||
| <> | <> | ||||
| <ProfileOffersHeaderSkeleton /> | <ProfileOffersHeaderSkeleton /> | ||||
| {isMobile ? ( | {isMobile ? ( | ||||
| ) : ( | ) : ( | ||||
| <OffersContainer> | <OffersContainer> | ||||
| <SelectSortField | <SelectSortField | ||||
| offersToShow={offersToShow} | |||||
| setOffersToShow={setOffersToShow} | |||||
| offersToShow={profileOffers} | |||||
| setSortOption={handleChangeSortOption} | |||||
| /> | /> | ||||
| <HeaderTitle isMyProfile={props.isMyProfile && !props.isAdmin} /> | <HeaderTitle isMyProfile={props.isMyProfile && !props.isAdmin} /> | ||||
| <SearchBar handleSearch={handleSearch} /> | |||||
| {!isMobile ? ( | |||||
| offersToShow.length !== 0 ? ( | |||||
| offersToShow.map((item) => ( | |||||
| <OfferCard | |||||
| isAdmin={props.isAdmin} | |||||
| isMyOffer={props.isMyProfile || props.isAdmin} | |||||
| offer={item} | |||||
| key={JSON.stringify(item)} | |||||
| messageUser={messageUser} | |||||
| /> | |||||
| )) | |||||
| ) : ( | |||||
| <NoProfileOffers /> | |||||
| ) | |||||
| ) : ( | |||||
| <OffersScroller hideArrows noOffers> | |||||
| {offersToShow.length !== 0 ? ( | |||||
| offersToShow.map((item) => ( | |||||
| <SearchBar | |||||
| handleSearch={handleSearch} | |||||
| value={searchValue} | |||||
| ref={searchRef} | |||||
| /> | |||||
| {!isMobile && | |||||
| (profileOffers.length !== 0 ? ( | |||||
| <> | |||||
| {profileOffers.map((item) => ( | |||||
| <OfferCard | <OfferCard | ||||
| isAdmin={props.isAdmin} | isAdmin={props.isAdmin} | ||||
| vertical | |||||
| isMyOffer={props.isMyProfile || props.isAdmin} | isMyOffer={props.isMyProfile || props.isAdmin} | ||||
| offer={item} | offer={item} | ||||
| key={JSON.stringify(item)} | key={JSON.stringify(item)} | ||||
| pinned={item.pinned} | |||||
| messageUser={messageUser} | messageUser={messageUser} | ||||
| /> | /> | ||||
| )) | |||||
| ) : ( | |||||
| <NoProfileOffers /> | |||||
| )} | |||||
| </OffersScroller> | |||||
| )} | |||||
| ))} | |||||
| </> | |||||
| ) : ( | |||||
| <NoProfileOffers /> | |||||
| ))} | |||||
| </OffersContainer> | </OffersContainer> | ||||
| )} | )} | ||||
| {isMobile ? ( | |||||
| <OffersScroller | |||||
| hideArrows | |||||
| noOffers | |||||
| infiniteScroll={handleInfiniteScroll} | |||||
| > | |||||
| {profileOffers.length !== 0 ? ( | |||||
| profileOffers.map((item) => ( | |||||
| <OfferCard | |||||
| isAdmin={props.isAdmin} | |||||
| vertical | |||||
| isMyOffer={props.isMyProfile || props.isAdmin} | |||||
| offer={item} | |||||
| key={JSON.stringify(item)} | |||||
| pinned={item.pinned} | |||||
| messageUser={messageUser} | |||||
| /> | |||||
| )) | |||||
| ) : ( | |||||
| <NoProfileOffers /> | |||||
| )} | |||||
| </OffersScroller> | |||||
| ) : ( | |||||
| <ProfilePaging | |||||
| current={paging.currentPage} | |||||
| changePage={paging.changePage} | |||||
| totalElements={total} | |||||
| /> | |||||
| )} | |||||
| </ProfileOffersContainer> | </ProfileOffersContainer> | ||||
| ); | ); | ||||
| }; | }; | ||||
| children: PropTypes.node, | children: PropTypes.node, | ||||
| isMyProfile: PropTypes.bool, | isMyProfile: PropTypes.bool, | ||||
| isAdmin: PropTypes.bool, | isAdmin: PropTypes.bool, | ||||
| idProfile: PropTypes.string, | |||||
| }; | }; | ||||
| export default ProfileOffers; | export default ProfileOffers; |
| import { Box } from "@mui/material"; | import { Box } from "@mui/material"; | ||||
| import styled from "styled-components"; | import styled from "styled-components"; | ||||
| import Paging from "../../Paging/Paging"; | |||||
| import HorizontalScroller from "../../Scroller/HorizontalScroller"; | import HorizontalScroller from "../../Scroller/HorizontalScroller"; | ||||
| export const ProfileOffersContainer = styled(Box)` | export const ProfileOffersContainer = styled(Box)` | ||||
| max-width: calc(100vw - 36px); | max-width: calc(100vw - 36px); | ||||
| overflow: hidden; | overflow: hidden; | ||||
| `; | `; | ||||
| export const ProfilePaging = styled(Paging)` | |||||
| position: static; | |||||
| margin-bottom: 9px; | |||||
| ` |
| import { useCallback } from "react"; | import { useCallback } from "react"; | ||||
| import { useRef } from "react"; | import { useRef } from "react"; | ||||
| import { useTranslation } from "react-i18next"; | import { useTranslation } from "react-i18next"; | ||||
| import { forwardRef } from "react"; | |||||
| import { useImperativeHandle } from "react"; | |||||
| import { useState } from "react"; | |||||
| const SearchBar = (props) => { | |||||
| const SearchBar = forwardRef((props, ref) => { | |||||
| const searchRef = useRef(null); | const searchRef = useRef(null); | ||||
| const [value, setSearchValue] = useState(""); | |||||
| const { t } = useTranslation(); | const { t } = useTranslation(); | ||||
| useImperativeHandle(ref, () => ({ | |||||
| changeSearchValue: (newValue) => { | |||||
| setSearchValue(newValue); | |||||
| }, | |||||
| searchValue: value, | |||||
| })); | |||||
| let listener = useCallback( | let listener = useCallback( | ||||
| (event) => { | (event) => { | ||||
| if (event.keyCode === 13) { | if (event.keyCode === 13) { | ||||
| <SearchInput | <SearchInput | ||||
| fullWidth | fullWidth | ||||
| ref={searchRef} | ref={searchRef} | ||||
| value={value} | |||||
| onChange={(event) => setSearchValue(event.target.value)} | |||||
| onFocus={handleFocusSearch} | onFocus={handleFocusSearch} | ||||
| onBlur={handleBlurSearch} | onBlur={handleBlurSearch} | ||||
| placeholder={t("header.searchOffers")} | placeholder={t("header.searchOffers")} | ||||
| }} | }} | ||||
| /> | /> | ||||
| ); | ); | ||||
| }; | |||||
| }); | |||||
| SearchBar.displayName = "SearchBar"; | |||||
| SearchBar.propTypes = { | SearchBar.propTypes = { | ||||
| handleSearch: PropTypes.func, | handleSearch: PropTypes.func, | ||||
| value: PropTypes.string, | |||||
| }; | }; | ||||
| export default SearchBar; | export default SearchBar; |
| & div fieldset { | & div fieldset { | ||||
| border-color: ${selectedTheme.colors.primaryPurple} !important; | border-color: ${selectedTheme.colors.primaryPurple} !important; | ||||
| } | } | ||||
| margin-bottom: 24px; | |||||
| @media (max-width: 600px) { | @media (max-width: 600px) { | ||||
| top: 5px; | top: 5px; | ||||
| height: 46px; | height: 46px; |
| } from "./SelectSortField.styled"; | } from "./SelectSortField.styled"; | ||||
| import { sortEnum } from "../../../../enums/sortEnum"; | import { sortEnum } from "../../../../enums/sortEnum"; | ||||
| import { useState } from "react"; | import { useState } from "react"; | ||||
| import { useEffect } from "react"; | |||||
| const SelectSortField = (props) => { | const SelectSortField = (props) => { | ||||
| const [sortOption, setSortOption] = useState(sortEnum.INITIAL); | const [sortOption, setSortOption] = useState(sortEnum.INITIAL); | ||||
| useEffect(() => { | |||||
| let newOffersToShow = [...props.offersToShow]; | |||||
| if (sortOption.value === sortEnum.OLD.value) { | |||||
| newOffersToShow.sort( | |||||
| (a, b) => new Date(a._created) - new Date(b._created) | |||||
| ); | |||||
| } | |||||
| if (sortOption.value === sortEnum.NEW.value) { | |||||
| newOffersToShow.sort( | |||||
| (a, b) => new Date(b._created) - new Date(a._created) | |||||
| ); | |||||
| } | |||||
| if (sortOption.value === sortEnum.POPULAR.value) { | |||||
| newOffersToShow.sort((a, b) => b.views.count - a.views.count); | |||||
| } | |||||
| props.setOffersToShow([...newOffersToShow]); | |||||
| }, [sortOption]); | |||||
| const handleChangeSelect = (event) => { | const handleChangeSelect = (event) => { | ||||
| let chosenOption; | let chosenOption; | ||||
| for (const sortOption in sortEnum) { | for (const sortOption in sortEnum) { | ||||
| if (sortEnum[sortOption].value === event.target.value) { | if (sortEnum[sortOption].value === event.target.value) { | ||||
| chosenOption = sortEnum[sortOption]; | chosenOption = sortEnum[sortOption]; | ||||
| setSortOption(chosenOption); | setSortOption(chosenOption); | ||||
| props.setSortOption(chosenOption); | |||||
| } | } | ||||
| } | } | ||||
| }; | }; | ||||
| SelectSortField.propTypes = { | SelectSortField.propTypes = { | ||||
| offersToShow: PropTypes.array, | offersToShow: PropTypes.array, | ||||
| setOffersToShow: PropTypes.func, | |||||
| setSortOption: PropTypes.func, | |||||
| }; | }; | ||||
| export default SelectSortField; | export default SelectSortField; |
| } from "./HorizontalScroller.styled"; | } from "./HorizontalScroller.styled"; | ||||
| import { ArrowButton } from "../Buttons/ArrowButton/ArrowButton"; | import { ArrowButton } from "../Buttons/ArrowButton/ArrowButton"; | ||||
| import useIsMobile from "../../hooks/useIsMobile"; | import useIsMobile from "../../hooks/useIsMobile"; | ||||
| import { debounceHelper } from "../../util/helpers/debounceHelper"; | |||||
| const HorizontalScroller = (props) => { | const HorizontalScroller = (props) => { | ||||
| const scrollRef = useRef(null); | const scrollRef = useRef(null); | ||||
| const [isDisabledLeftButton, setIsDisabledLeftButton] = useState(true); | const [isDisabledLeftButton, setIsDisabledLeftButton] = useState(true); | ||||
| const [isDisabledRightButton, setIsDisabledRightButton] = useState(false); | const [isDisabledRightButton, setIsDisabledRightButton] = useState(false); | ||||
| const handleScroll = (event) => { | const handleScroll = (event) => { | ||||
| if (!event.external) { | if (!event.external) { | ||||
| if (scrollRef.current.scrollLeft === 0) { | if (scrollRef.current.scrollLeft === 0) { | ||||
| if (isDisabledRightButton !== false) setIsDisabledRightButton(false); | if (isDisabledRightButton !== false) setIsDisabledRightButton(false); | ||||
| } | } | ||||
| } | } | ||||
| if (props.infiniteScroll) { | |||||
| if ( | |||||
| scrollRef.current.scrollWidth - scrollRef.current.scrollLeft < | |||||
| scrollRef.current.clientWidth + 170 | |||||
| ) { | |||||
| debounceHelper(() => props.infiniteScroll(), 500); | |||||
| } | |||||
| } | |||||
| }; | }; | ||||
| const handleRight = () => { | const handleRight = () => { | ||||
| listStyle: PropTypes.any, | listStyle: PropTypes.any, | ||||
| hideArrows: PropTypes.bool, | hideArrows: PropTypes.bool, | ||||
| isCarousel: PropTypes.bool, | isCarousel: PropTypes.bool, | ||||
| infiniteScroll: PropTypes.bool, | |||||
| }; | }; | ||||
| export default HorizontalScroller; | export default HorizontalScroller; |
| import { useEffect, useState } from "react"; | import { useEffect, useState } from "react"; | ||||
| const usePaging = (applyAllFilters) => { | |||||
| const usePaging = (applyAllFilters, disableScroll) => { | |||||
| const [currentPage, setCurrentPage] = useState(1); | const [currentPage, setCurrentPage] = useState(1); | ||||
| const [isInitallyLoaded, setIsInitiallyLoaded] = useState(false); | const [isInitallyLoaded, setIsInitiallyLoaded] = useState(false); | ||||
| if (isInitallyLoaded && applyAllFilters) { | if (isInitallyLoaded && applyAllFilters) { | ||||
| applyAllFilters(); | applyAllFilters(); | ||||
| } | } | ||||
| window.scrollTo({ | |||||
| top: 0, | |||||
| behavior: "smooth", | |||||
| }); | |||||
| if (!disableScroll) { | |||||
| window.scrollTo({ | |||||
| top: 0, | |||||
| behavior: "smooth", | |||||
| }); | |||||
| } | |||||
| }, [currentPage]); | }, [currentPage]); | ||||
| const changePage = (pageNumber) => { | const changePage = (pageNumber) => { |
| categories: "categories", | categories: "categories", | ||||
| locations: "locations", | locations: "locations", | ||||
| mineOffers: "users", | mineOffers: "users", | ||||
| profileOffers: "users/{userId}/offers", | |||||
| removeOffer: "/users/{userId}/offers/{offerId}", | removeOffer: "/users/{userId}/offers/{offerId}", | ||||
| removeOfferAsAdmin: "/admin/offers/{offerId}", | removeOfferAsAdmin: "/admin/offers/{offerId}", | ||||
| pinOffer: "admin/offers/{id}/pin", | pinOffer: "admin/offers/{id}/pin", |
| data | data | ||||
| ); | ); | ||||
| }; | }; | ||||
| export const attemptFetchProfileOffers = (payload) => { | |||||
| return getRequest(`${apiEndpoints.offers.mineOffers}/${payload}/offers`); | |||||
| export const attemptFetchProfileOffers = (userId, queryString = "") => { | |||||
| return getRequest( | |||||
| replaceInUrl(apiEndpoints.offers.profileOffers, { | |||||
| userId: userId, | |||||
| }) + `?${queryString}` | |||||
| ); | |||||
| }; | }; | ||||
| export const attemptRemoveOffer = (payload, offerId) => { | export const attemptRemoveOffer = (payload, offerId) => { | ||||
| return deleteRequest( | return deleteRequest( |
| export const OFFERS_NO_MORE = createSetType("OFFERS_NO_MORE"); | export const OFFERS_NO_MORE = createSetType("OFFERS_NO_MORE"); | ||||
| export const OFFERS_SET_TOTAL = createSetType("OFFERS_SET_TOTAL"); | export const OFFERS_SET_TOTAL = createSetType("OFFERS_SET_TOTAL"); | ||||
| export const OFFERS_PROFILE_SET = createSetType("OFFERS_PROFILE_SET"); | export const OFFERS_PROFILE_SET = createSetType("OFFERS_PROFILE_SET"); | ||||
| export const OFFERS_PROFILE_ADD = createSetType("OFFERS_PROFILE_ADD"); | |||||
| export const OFFERS_MINE_SET = createSetType("OFFERS_MY_ADD"); | export const OFFERS_MINE_SET = createSetType("OFFERS_MY_ADD"); | ||||
| export const OFFER_INDEX_SET = createSetType("OFFER_INDEX_SET"); | export const OFFER_INDEX_SET = createSetType("OFFER_INDEX_SET"); | ||||
| export const OFFER_INDEX_CLEAR = createClearType("OFFER_INDEX_CLEAR"); | export const OFFER_INDEX_CLEAR = createClearType("OFFER_INDEX_CLEAR"); |
| OFFERS_NO_MORE, | OFFERS_NO_MORE, | ||||
| OFFERS_PINNED_ADD, | OFFERS_PINNED_ADD, | ||||
| OFFERS_PINNED_SET, | OFFERS_PINNED_SET, | ||||
| OFFERS_PROFILE_ADD, | |||||
| OFFERS_PROFILE_ERROR, | OFFERS_PROFILE_ERROR, | ||||
| OFFERS_PROFILE_FETCH, | OFFERS_PROFILE_FETCH, | ||||
| OFFERS_PROFILE_SET, | OFFERS_PROFILE_SET, | ||||
| type: OFFERS_PROFILE_SET, | type: OFFERS_PROFILE_SET, | ||||
| payload, | payload, | ||||
| }); | }); | ||||
| export const addProfileOffers = (payload) => ({ | |||||
| type: OFFERS_PROFILE_ADD, | |||||
| payload, | |||||
| }); | |||||
| export const setOffer = (payload) => ({ | export const setOffer = (payload) => ({ | ||||
| type: OFFER_SET, | type: OFFER_SET, | ||||
| payload, | payload, |
| OFFER_FEATURED_PAGE_SET, | OFFER_FEATURED_PAGE_SET, | ||||
| OFFER_SELECTED_CLEAR, | OFFER_SELECTED_CLEAR, | ||||
| OFFERS_HEADER_SET, | OFFERS_HEADER_SET, | ||||
| OFFERS_PROFILE_ADD, | |||||
| } from "../../actions/offers/offersActionConstants"; | } from "../../actions/offers/offersActionConstants"; | ||||
| import createReducer from "../../utils/createReducer"; | import createReducer from "../../utils/createReducer"; | ||||
| [OFFERS_MINE_SET]: setMineOffers, | [OFFERS_MINE_SET]: setMineOffers, | ||||
| [OFFERS_HEADER_SET]: setHeaderOffers, | [OFFERS_HEADER_SET]: setHeaderOffers, | ||||
| [OFFERS_PROFILE_SET]: setProfileOffers, | [OFFERS_PROFILE_SET]: setProfileOffers, | ||||
| [OFFERS_PROFILE_ADD]: addProfileOffers, | |||||
| [OFFERS_FEATURED_CLEAR]: clearFeaturedOffers, | [OFFERS_FEATURED_CLEAR]: clearFeaturedOffers, | ||||
| [OFFERS_FEATURED_SET]: setFeaturedOffers, | [OFFERS_FEATURED_SET]: setFeaturedOffers, | ||||
| [OFFER_INDEX_SET]: setOfferIndex, | [OFFER_INDEX_SET]: setOfferIndex, | ||||
| mineHeaderOffers: payload, | mineHeaderOffers: payload, | ||||
| }; | }; | ||||
| } | } | ||||
| function addProfileOffers(state, { payload }) { | |||||
| return { | |||||
| ...state, | |||||
| profileOffers: [...state.profileOffers, ...payload], | |||||
| }; | |||||
| } |
| fetchMineHeaderOffersError, | fetchMineHeaderOffersError, | ||||
| pinOfferSuccess, | pinOfferSuccess, | ||||
| pinOfferError, | pinOfferError, | ||||
| addProfileOffers, | |||||
| // fetchAllOffersSuccess, | // fetchAllOffersSuccess, | ||||
| // fetchAllOffersError, | // fetchAllOffersError, | ||||
| // setFeaturedOfferPage, | // setFeaturedOfferPage, | ||||
| // import { NOT_FOUND_PAGE } from "../../constants/pages"; | // import { NOT_FOUND_PAGE } from "../../constants/pages"; | ||||
| import { makeErrorToastMessage } from "../utils/makeToastMessage"; | import { makeErrorToastMessage } from "../utils/makeToastMessage"; | ||||
| import i18next from "i18next"; | import i18next from "i18next"; | ||||
| import { | |||||
| KEY_NAME, | |||||
| KEY_PAGE, | |||||
| KEY_SIZE, | |||||
| KEY_SORTBY, | |||||
| } from "../../constants/queryStringConstants"; | |||||
| function* fetchOffers(payload) { | function* fetchOffers(payload) { | ||||
| try { | try { | ||||
| function* fetchProfileOffers(payload) { | function* fetchProfileOffers(payload) { | ||||
| try { | try { | ||||
| const userId = payload.payload; | |||||
| console.log(payload.payload); | |||||
| const userId = payload.payload.idProfile; | |||||
| if (!userId || userId?.length === 0) | if (!userId || userId?.length === 0) | ||||
| throw new Error("User id is not defined!"); | throw new Error("User id is not defined!"); | ||||
| const data = yield call(attemptFetchProfileOffers, userId); | |||||
| yield put(setProfileOffers(data.data.offers)); | |||||
| const queryString = new URLSearchParams(); | |||||
| queryString.set(KEY_SIZE, 10); | |||||
| queryString.set(KEY_PAGE, payload.payload.page); | |||||
| if (payload.payload.searchValue?.length > 0) | |||||
| queryString.set(KEY_NAME, payload.payload.searchValue); | |||||
| queryString.set(KEY_SORTBY, payload.payload.sortOption.queryString); | |||||
| const data = yield call( | |||||
| attemptFetchProfileOffers, | |||||
| userId, | |||||
| convertQueryStringForBackend(queryString) | |||||
| ); | |||||
| if (payload.payload.append) { | |||||
| yield put(addProfileOffers(data.data.offers)); | |||||
| } else { | |||||
| yield put(setProfileOffers(data.data.offers)); | |||||
| } | |||||
| yield put(setTotalOffers(data.data.total)); | |||||
| yield put(fetchProfileOffersSuccess()); | yield put(fetchProfileOffersSuccess()); | ||||
| } catch (e) { | } catch (e) { | ||||
| console.dir(e); | console.dir(e); |