| @@ -22,7 +22,6 @@ const App = () => { | |||
| useEffect(() => { | |||
| socketInit(userId); | |||
| }, [userId]); | |||
| return ( | |||
| <Router history={history}> | |||
| <Helmet> | |||
| @@ -32,7 +32,8 @@ const CategoryChoser = forwardRef((props, ref) => { | |||
| useEffect(() => { | |||
| if ( | |||
| !filters.category.selectedCategoryLocally || | |||
| (filters.category.selectedCategoryLocally && | |||
| !("_id" in filters.category.selectedCategoryLocally)) || | |||
| (filters.category.selectedCategoryLocally?._id === 0 && !isOpened) | |||
| ) { | |||
| setIsOpened(false); | |||
| @@ -11,6 +11,7 @@ import FilterSubDropdown from "../../FilterDropdown/Checkbox/FilterSubDropdown/F | |||
| const CompanyChoser = forwardRef((props, ref) => { | |||
| const [isOpened, setIsOpened] = useState(false); | |||
| const [appliedFilters, setAppliedFilters] = useState(false); | |||
| const filters = props.filters; | |||
| const { t } = useTranslation(); | |||
| @@ -26,6 +27,18 @@ const CompanyChoser = forwardRef((props, ref) => { | |||
| } | |||
| }, [filters.companies.selectedCompaniesLocally]); | |||
| useEffect(() => { | |||
| if (appliedFilters) { | |||
| props?.offers?.apply(); | |||
| setAppliedFilters(false); | |||
| } | |||
| }, [filters.companies.selectedCompaniesLocally]); | |||
| const handleSetItemsSelected = (items) => { | |||
| filters.companies.setSelectedCompanies(items); | |||
| setAppliedFilters(true); | |||
| }; | |||
| return ( | |||
| <FilterSubDropdown | |||
| searchPlaceholder={t("filters.company.placeholder")} | |||
| @@ -35,7 +48,7 @@ const CompanyChoser = forwardRef((props, ref) => { | |||
| handleOpen={() => setIsOpened((prevIsOpened) => !prevIsOpened)} | |||
| icon={<CompanyIcon />} | |||
| title={t("filters.company.title")} | |||
| setItemsSelected={filters.companies.setSelectedCompanies} | |||
| setItemsSelected={handleSetItemsSelected} | |||
| companies | |||
| offers={props.offers} | |||
| /> | |||
| @@ -12,6 +12,7 @@ import { useTranslation } from "react-i18next"; | |||
| const LocationChoser = forwardRef((props, ref) => { | |||
| const { t } = useTranslation(); | |||
| const [appliedFilters, setAppliedFilters] = useState(false); | |||
| const [isOpened, setIsOpened] = useState(false); | |||
| const filters = props.filters; | |||
| @@ -31,6 +32,18 @@ const LocationChoser = forwardRef((props, ref) => { | |||
| setIsOpened(true); | |||
| } | |||
| }, [filters.locations.selectedLocationsLocally]); | |||
| useEffect(() => { | |||
| if (appliedFilters) { | |||
| props?.offers?.apply(); | |||
| setAppliedFilters(false); | |||
| } | |||
| }, [appliedFilters]); | |||
| const handleSetItemsSelected = (items) => { | |||
| filters.locations.setSelectedLocations(items); | |||
| setAppliedFilters(true); | |||
| }; | |||
| return ( | |||
| <FilterCheckboxDropdown | |||
| searchPlaceholder={t("filters.location.placeholder")} | |||
| @@ -40,7 +53,7 @@ const LocationChoser = forwardRef((props, ref) => { | |||
| handleOpen={() => setIsOpened((prevIsOpened) => !prevIsOpened)} | |||
| icon={<LocationIcon />} | |||
| title={t("filters.location.title")} | |||
| setItemsSelected={filters.locations.setSelectedLocations} | |||
| setItemsSelected={handleSetItemsSelected} | |||
| offers={props.offers} | |||
| /> | |||
| ); | |||
| @@ -40,7 +40,8 @@ const SubcategoryChoser = forwardRef((props, ref) => { | |||
| useEffect(() => { | |||
| if (props?.queryStringHook?.isInitiallyLoaded || props.myOffers) { | |||
| if ( | |||
| !filters.category.selectedCategoryLocally || | |||
| (filters.category.selectedCategoryLocally && | |||
| !("_id" in filters.category.selectedCategoryLocally)) || | |||
| filters.category.selectedCategoryLocally?._id === 0 | |||
| ) { | |||
| setIsOpened(false); | |||
| @@ -51,12 +52,14 @@ const SubcategoryChoser = forwardRef((props, ref) => { | |||
| } | |||
| } else { | |||
| if ( | |||
| !filters.subcategory.selectedSubcategoryLocally || | |||
| (filters.subcategory.selectedSubcategoryLocally && | |||
| !("_id" in filters.subcategory.selectedSubcategoryLocally)) || | |||
| filters.subcategory.selectedSubcategoryLocally?._id === 0 | |||
| ) { | |||
| setIsOpened(false); | |||
| if ( | |||
| !filters.category.selectedCategoryLocally || | |||
| (filters.category.selectedCategoryLocally && | |||
| !("_id" in filters.category.selectedCategoryLocally)) || | |||
| filters.category.selectedCategoryLocally?._id === 0 | |||
| ) { | |||
| setIsDisabled(true); | |||
| @@ -16,8 +16,9 @@ const CheckboxDropdownList = (props) => { | |||
| const data = props.data; | |||
| const [isOpened, setIsOpened] = useState(false); | |||
| const handleDelete = (item) => { | |||
| props.setItemsSelected([...props.filters.filter((p) => p !== item)]); | |||
| props.offers.applyFilters(); | |||
| console.log(item); | |||
| console.log(props.filters) | |||
| props.setItemsSelected([...props.filters.filter((p) => p?._id !== item?._id)]); | |||
| }; | |||
| const handleOpen = () => { | |||
| setIsOpened((prevState) => !prevState); | |||
| @@ -48,6 +48,7 @@ const FilterSubDropdown = (props) => { | |||
| filters={props.filters} | |||
| icon={props.icon} | |||
| data={data} | |||
| offers={props?.offers} | |||
| searchPlaceholder={props.searchPlaceholder} | |||
| open={props?.open !== undefined ? props.open : isOpened} | |||
| handleOpen={handleOpen} | |||
| @@ -111,7 +111,10 @@ const FilterRadioDropdown = (props) => { | |||
| label={props.firstOption.label} | |||
| // number={item.numberOfProducts} | |||
| fullWidth | |||
| checked={!props.selected || props.selected._id === 0} | |||
| checked={ | |||
| (props?.selected && !("_id" in props?.selected)) || | |||
| props?.selected?._id === 0 | |||
| } | |||
| onChange={props.setSelected} | |||
| /> | |||
| </DropdownItem> | |||
| @@ -49,7 +49,10 @@ const ItemDetailsCard = (props) => { | |||
| const dispatch = useDispatch(); | |||
| const offer = useMemo(() => { | |||
| if (props.offer) { | |||
| if (props.offer._id === routeMatch.params?.offerId && !props?.createOffer) { | |||
| if ( | |||
| props.offer._id === routeMatch.params?.offerId && | |||
| !props?.createOffer | |||
| ) { | |||
| return props.offer; | |||
| } | |||
| if (props.createOffer) return props.offer.offer; | |||
| @@ -145,9 +148,11 @@ const ItemDetailsCard = (props) => { | |||
| <DateButtonsContainer> | |||
| {props.isMyOffer && ( | |||
| <ButtonsContainer> | |||
| <PinIconContainer onClick={showPinOfferModalHandler}> | |||
| {offer?.pinned ? <UnpinIcon /> : <PinIcon />} | |||
| </PinIconContainer> | |||
| {props?.isAdmin && ( | |||
| <PinIconContainer onClick={showPinOfferModalHandler}> | |||
| {offer?.pinned ? <UnpinIcon /> : <PinIcon />} | |||
| </PinIconContainer> | |||
| )} | |||
| <EditIconContainer onClick={showEditOfferModalHandler}> | |||
| <EditIcon /> | |||
| </EditIconContainer> | |||
| @@ -27,7 +27,6 @@ const OfferDetails = (props) => { | |||
| const [images, setImages] = useState([]); | |||
| const [imagesCarouselModal, setImagesCarouselModal] = useState(false); | |||
| useEffect(() => { | |||
| if (props?.offer?.images) { | |||
| props.offer.images.map((file) => { | |||
| @@ -47,6 +46,9 @@ const OfferDetails = (props) => { | |||
| } | |||
| }); | |||
| } | |||
| return () => { | |||
| setImages([]); | |||
| }; | |||
| }, [props?.offer?.images]); | |||
| const date = formatDateLocale(new Date(offer?._created)); | |||
| const onModalClose = () => { | |||
| @@ -122,7 +124,11 @@ const OfferDetails = (props) => { | |||
| </OfferInfoContainer> | |||
| </Details> | |||
| {imagesCarouselModal && ( | |||
| <ImagesCarousel offer={props.offer} images={images} onModalClose={onModalClose} /> | |||
| <ImagesCarousel | |||
| offer={props.offer} | |||
| images={images} | |||
| onModalClose={onModalClose} | |||
| /> | |||
| )} | |||
| </> | |||
| ); | |||
| @@ -3,6 +3,7 @@ import PropTypes from "prop-types"; | |||
| import { | |||
| CategoryIcon, | |||
| CategoryIconContainer, | |||
| OfferCategoryContainer, | |||
| OfferDescriptionCategory, | |||
| OfferDescriptionContainer, | |||
| OfferDescriptionTitle, | |||
| @@ -13,7 +14,7 @@ const OfferDescription = (props) => { | |||
| return ( | |||
| <OfferDescriptionContainer> | |||
| <OfferDescriptionTitle>{props.offerName}</OfferDescriptionTitle> | |||
| <OfferDescriptionCategory> | |||
| <OfferCategoryContainer> | |||
| <CategoryIconContainer | |||
| color={selectedTheme.colors.iconStrokeDisabledColor} | |||
| component="span" | |||
| @@ -21,8 +22,10 @@ const OfferDescription = (props) => { | |||
| > | |||
| <CategoryIcon /> | |||
| </CategoryIconContainer> | |||
| {props.categoryName} | |||
| </OfferDescriptionCategory> | |||
| <OfferDescriptionCategory> | |||
| {props.categoryName} | |||
| </OfferDescriptionCategory> | |||
| </OfferCategoryContainer> | |||
| </OfferDescriptionContainer> | |||
| ); | |||
| }; | |||
| @@ -35,15 +35,21 @@ export const OfferDescriptionCategory = styled(Typography)` | |||
| font-family: ${selectedTheme.fonts.textFont}; | |||
| color: ${selectedTheme.colors.primaryDarkText}; | |||
| `; | |||
| export const OfferCategoryContainer = styled(Box)` | |||
| display: flex; | |||
| flex-direction: row; | |||
| white-space: nowrap; | |||
| ` | |||
| export const CategoryIconContainer = styled(Icon)` | |||
| margin-right: 4px; | |||
| position: relative; | |||
| top: 2px; | |||
| display: inline; | |||
| & svg { | |||
| width: 14px; | |||
| position: relative; | |||
| top: -6px; | |||
| top: -4px; | |||
| } | |||
| `; | |||
| export const CategoryIcon = styled(Category)``; | |||
| @@ -87,11 +87,14 @@ const OfferCard = (props) => { | |||
| }) | |||
| ); | |||
| } else { | |||
| history.push( | |||
| replaceInRoute(ITEM_DETAILS_PAGE, { | |||
| history.push({ | |||
| pathname: replaceInRoute(ITEM_DETAILS_PAGE, { | |||
| offerId: itemId, | |||
| }) | |||
| ); | |||
| }), | |||
| state: { | |||
| view: true, | |||
| }, | |||
| }); | |||
| } | |||
| } | |||
| }; | |||
| @@ -54,7 +54,10 @@ const ProfileControl = (props) => { | |||
| ); | |||
| }; | |||
| const handleEditProfile = () => { | |||
| if (!props.profile?._blocked) { | |||
| console.log("edit") | |||
| console.log(props) | |||
| if (!props.profile?._blocked || props?.isAdmin) { | |||
| console.log("edit2") | |||
| dispatch( | |||
| toggleEditProfileModal({ | |||
| userId: props.profile._id, | |||
| @@ -67,9 +70,10 @@ const ProfileControl = (props) => { | |||
| ); | |||
| } | |||
| }; | |||
| console.log(props) | |||
| return ( | |||
| <ButtonsContainer> | |||
| {props.profile?._blocked && !props.isMobile && <BlockedProfile />} | |||
| {props.profile?._blocked && !props.isMobile && !props?.isAdmin && <BlockedProfile />} | |||
| {props.isAdmin && ( | |||
| <> | |||
| {props.profile?._blocked ? ( | |||
| @@ -10,9 +10,8 @@ import { | |||
| import FirstStepCreateReview from "./FirstStep/FirstStepCreateReview"; | |||
| import SecondStepCreateReview from "./SecondStep/SecondStepCreateReview"; | |||
| import ThirdStepCreateReview from "./ThirdStep/ThirdStepCreateReview"; | |||
| import { useDispatch, useSelector } from "react-redux"; | |||
| import { useDispatch } from "react-redux"; | |||
| import { giveReview } from "../../store/actions/review/reviewActions"; | |||
| import { selectUserId } from "../../store/selectors/loginSelectors"; | |||
| import { reviewEnum } from "../../enums/reviewEnum"; | |||
| import { fetchExchange } from "../../store/actions/exchange/exchangeActions"; | |||
| import { closeModal } from "../../store/actions/modal/modalActions"; | |||
| @@ -23,13 +22,9 @@ const CreateReview = (props) => { | |||
| const [informations, setInformations] = useState({}); | |||
| const [currentStep, setCurrentStep] = useState(1); | |||
| const dispatch = useDispatch(); | |||
| const userId = useSelector(selectUserId); | |||
| const closeModalHandler = () => { | |||
| dispatch(closeModal()); | |||
| }; | |||
| setTimeout(() => { | |||
| dispatch(closeModal()); | |||
| }, 3000); | |||
| const handleApiResponseSuccess = () => { | |||
| dispatch(fetchExchange(props.exchange._id)); | |||
| }; | |||
| @@ -45,8 +40,9 @@ const CreateReview = (props) => { | |||
| dispatch( | |||
| giveReview({ | |||
| review: { | |||
| exchangeId: props.exchange._id, | |||
| userId: userId, | |||
| exchange: { | |||
| _id: props.exchange._id, | |||
| }, | |||
| succeeded, | |||
| communication, | |||
| message: informations.comment, | |||
| @@ -7,9 +7,15 @@ import { | |||
| ThirdStepCreateReviewContainer, | |||
| } from "./ThirdStepCreateReview.styled"; | |||
| import { useTranslation } from "react-i18next"; | |||
| import { useDispatch } from "react-redux"; | |||
| import { closeModal } from "../../../store/actions/modal/modalActions"; | |||
| const ThirdStepCreateReview = () => { | |||
| const { t } = useTranslation(); | |||
| const dispatch = useDispatch(); | |||
| setTimeout(() => { | |||
| dispatch(closeModal()); | |||
| }, 3000); | |||
| return ( | |||
| <ThirdStepCreateReviewContainer> | |||
| <LogoImage /> | |||
| @@ -171,13 +171,11 @@ const DirectChat = () => { | |||
| }; | |||
| const handleAcceptExchangeSuccess = () => { | |||
| let interlocutor = userId === chat?.participants[0]._id ? 1 : 0; | |||
| console.log("accept salje i prima 3 POZVANA RESPONSE FUNKCIJA") | |||
| acceptExchangeSocket( | |||
| chat?._id, | |||
| userId, | |||
| chat?.participants[interlocutor]._id, | |||
| () => { | |||
| console.log("accept salje i prima 4 SOCKET FUNKCIJA") | |||
| dispatch( | |||
| addNewMessage({ | |||
| _id: chat?._id, | |||
| @@ -33,9 +33,9 @@ const DirectChatHeader = (props) => { | |||
| const isDisabledReviews = useMemo(() => { | |||
| if (!exchange.valid) return true; | |||
| if (exchange.seller?.userId === userId && exchange.seller?.givenReview) | |||
| if (exchange.seller?.user._id === userId && exchange.seller?.givenReview) | |||
| return true; | |||
| if (exchange.buyer?.userId === userId && exchange.buyer?.givenReview) | |||
| if (exchange.buyer?.user._id === userId && exchange.buyer?.givenReview) | |||
| return true; | |||
| return false; | |||
| }, [exchange, userId]); | |||
| @@ -51,14 +51,14 @@ const ItemDetailsHeaderCard = (props) => { | |||
| }; | |||
| const messageUser = (offer) => { | |||
| const chatItem = chats.find( | |||
| (item) => item.chat.offerId === offer?._id | |||
| (item) => item.offer._id === offer?._id | |||
| ); | |||
| if (chatItem !== undefined) { | |||
| history.push(DIRECT_CHAT_PAGE, { | |||
| chatId: chatItem.chat._id | |||
| chatId: chatItem._id | |||
| }); | |||
| } else { | |||
| if (offer?.userId !== userId) { | |||
| if (offer?.user?._id !== userId) { | |||
| history.push(`/messages/newMessage`, { | |||
| offerId: offer?._id, | |||
| }); | |||
| @@ -31,10 +31,12 @@ const TooltipHeader = (props) => { | |||
| const handleClickCategory = () => { | |||
| props?.offers?.filters?.locations.clear(); | |||
| props?.offers?.filters?.subcategory.clear(); | |||
| props?.offers?.filters?.companies?.clear(); | |||
| props?.offers?.applyFilters(); | |||
| }; | |||
| const handleClickSubcategory = () => { | |||
| props?.offers?.filters?.locations.clear(); | |||
| props?.offers?.filters?.companies?.clear(); | |||
| props?.offers?.applyFilters(); | |||
| }; | |||
| const goBack = () => { | |||
| @@ -9,11 +9,13 @@ import OffersNotFound from "./OffersNotFound/OffersNotFound"; | |||
| const Offers = (props) => { | |||
| const offers = props?.offers; | |||
| const arrayForMapping = Array.apply(null, Array(4)).map(() => {}); | |||
| console.log("rerender") | |||
| return ( | |||
| <> | |||
| <OffersFilterButton /> | |||
| <OffersSearchField /> | |||
| <OffersNotFound /> | |||
| <OffersNotFound skeleton={props?.skeleton} /> | |||
| <OffersList | |||
| loading={props?.skeleton} | |||
| offers={offers} | |||
| @@ -39,7 +39,7 @@ const OffersList = (props) => { | |||
| offer={item} | |||
| halfwidth={props?.isGrid} | |||
| messageUser={messageOneUser} | |||
| isMyOffer={item?.userId === userId || props?.isAdmin} | |||
| isMyOffer={item?.user._id === userId || props?.isAdmin} | |||
| isAdmin={props?.isAdmin} | |||
| /> | |||
| ); | |||
| @@ -54,6 +54,12 @@ const ProfileOffers = (props) => { | |||
| const dispatch = useDispatch(); | |||
| const searchRef = useRef(null); | |||
| useEffect(() => { | |||
| return () => { | |||
| dispatch(setProfileOffers([])); | |||
| }; | |||
| }, []); | |||
| useEffect(() => { | |||
| dispatch( | |||
| fetchProfileOffers({ | |||
| @@ -62,6 +68,7 @@ const ProfileOffers = (props) => { | |||
| sortOption: sortOption, | |||
| append: isMobile && append, | |||
| page: paging.currentPage, | |||
| isAdmin: props?.isAdmin, | |||
| }) | |||
| ); | |||
| setAppend(true); | |||
| @@ -107,14 +114,14 @@ const ProfileOffers = (props) => { | |||
| <ProfileOffersHeaderSkeleton /> | |||
| {isMobile ? ( | |||
| <SkeletonContainer> | |||
| <SkeletonOfferCard vertical /> | |||
| <SkeletonOfferCard vertical /> | |||
| <SkeletonOfferCard vertical /> | |||
| <SkeletonOfferCard vertical skeleton /> | |||
| <SkeletonOfferCard vertical skeleton /> | |||
| <SkeletonOfferCard vertical skeleton /> | |||
| </SkeletonContainer> | |||
| ) : ( | |||
| <> | |||
| {arrayForMapping.map((item, index) => ( | |||
| <SkeletonOfferCard key={index} /> | |||
| <SkeletonOfferCard key={index} skeleton /> | |||
| ))} | |||
| </> | |||
| )} | |||
| @@ -9,6 +9,10 @@ import useSearch from "./useSearch"; | |||
| import useSorting from "./useSorting"; | |||
| const useMyOffers = () => { | |||
| const applyFilters = () => { | |||
| paging.changePage(1); | |||
| setAppliedFilters(false); | |||
| }; | |||
| const filters = useFilters(true); | |||
| const sorting = useSorting(); | |||
| const mineOffers = useSelector(selectMineOffers); | |||
| @@ -31,11 +35,6 @@ const useMyOffers = () => { | |||
| setAppliedFilters(false); | |||
| } | |||
| const applyFilters = () => { | |||
| paging.changePage(1); | |||
| setAppliedFilters(false); | |||
| }; | |||
| // Filter, search and sort all mine offers | |||
| const allOffersToShow = useMemo(() => { | |||
| let mineOffersFiltered = [...mineOffers]; | |||
| @@ -1,4 +1,9 @@ | |||
| export default (informations, offer, images) => ({ | |||
| images: informations?.image || offer?.images || images, | |||
| condition: informations?.condition || offer?.condition || "default", | |||
| condition: | |||
| informations?.condition || | |||
| (typeof offer?.condition === "string" && | |||
| offer?.condition?.charAt(0)?.toUpperCase() + | |||
| offer?.condition?.slice(1)) || | |||
| "default", | |||
| }); | |||
| @@ -11,6 +11,7 @@ import { | |||
| import UserReviews from "../../components/UserReviews/UserReviews"; | |||
| import { selectOffer } from "../../store/selectors/offersSelectors"; | |||
| import ProfileMini from "../../components/ProfileMini/ProfileMini"; | |||
| import history from "../../store/utils/history"; | |||
| const ItemDetailsPage = (props) => { | |||
| const dispatch = useDispatch(); | |||
| @@ -19,7 +20,9 @@ const ItemDetailsPage = (props) => { | |||
| const offerId = props.match.params.offerId; | |||
| useEffect(() => { | |||
| dispatch(fetchOneOffer(offerId)); | |||
| const view = history?.location?.state?.view; | |||
| console.log(view) | |||
| dispatch(fetchOneOffer({ offerId, view })); | |||
| () => dispatch(clearSelectedOffer()); | |||
| }, []); | |||
| @@ -166,7 +166,7 @@ export default { | |||
| setFingerprint: "/affiliate/fingerprint", | |||
| }, | |||
| offers: { | |||
| getOneOffer: "offers", | |||
| getOneOffer: "offers/{offerId}", | |||
| getOffers: "offers", | |||
| getFeaturedOffers: "offers/featured", | |||
| addOffer: "/users/{userId}/offers", | |||
| @@ -176,6 +176,7 @@ export default { | |||
| locations: "locations", | |||
| mineOffers: "users", | |||
| profileOffers: "users/{userId}/offers", | |||
| profileOffersAsAdmin: "admin/users/{userId}/offers", | |||
| removeOffer: "/users/{userId}/offers/{offerId}", | |||
| removeOfferAsAdmin: "/admin/offers/{offerId}", | |||
| pinOffer: "admin/offers/{id}/pin", | |||
| @@ -190,7 +191,7 @@ export default { | |||
| exchange: { | |||
| getExchange: "exchanges", | |||
| validateExchange: "exchanges", | |||
| acceptExchange: "users/{userId}/exchanges/{exchangeId}/accept" | |||
| acceptExchange: "users/{userId}/exchanges/{exchangeId}/accept", | |||
| }, | |||
| reviews: { | |||
| getUserReviews: "/users/{userId}/reviews", | |||
| @@ -1,20 +1,20 @@ | |||
| import axios from "axios"; | |||
| import queryString from "qs"; | |||
| // import queryString from "qs"; | |||
| const request = axios.create({ | |||
| // baseURL: "http://192.168.88.150:3001/", // DJOLE | |||
| // 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", | |||
| }, | |||
| // withCredentials: true, | |||
| paramsSerializer: (params) => | |||
| queryString.stringify(params, { arrayFormat: "comma" }), | |||
| // paramsSerializer: (params) => | |||
| // queryString.stringify(params, { arrayFormat: "comma" }), | |||
| }); | |||
| export const getRequest = (url, params = null, options = null) => { | |||
| @@ -18,8 +18,12 @@ export const attemptFetchFeaturedOffers = (payload) => { | |||
| return getRequest(apiEndpoints.offers.getOffers); | |||
| }; | |||
| export const attemptFetchOneOffer = (payload) => { | |||
| const url = `${apiEndpoints.offers.getOneOffer}/${payload}`; | |||
| return getRequest(url); | |||
| return getRequest( | |||
| replaceInUrl(apiEndpoints.offers.getOneOffer, { | |||
| offerId: payload.offerId, | |||
| }), | |||
| payload.queryObject | |||
| ); | |||
| }; | |||
| export const attemptFetchMoreOffers = (page, payload) => { | |||
| if (payload) | |||
| @@ -42,6 +46,13 @@ export const attemptFetchProfileOffers = (userId, queryString = "") => { | |||
| }) + `?${queryString}` | |||
| ); | |||
| }; | |||
| export const attemptFetchProfileOffersAsAdmin = (userId, queryString = "") => { | |||
| return getRequest( | |||
| replaceInUrl(apiEndpoints.offers.profileOffersAsAdmin, { | |||
| userId: userId, | |||
| }) + `?${queryString}` | |||
| ); | |||
| }; | |||
| export const attemptRemoveOffer = (payload, offerId) => { | |||
| return deleteRequest( | |||
| replaceInUrl(apiEndpoints.offers.removeOffer, { | |||
| @@ -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 | |||
| @@ -38,8 +38,6 @@ export default ({ dispatch }) => | |||
| } | |||
| // If refresh token is expired, log out user | |||
| console.log(new Date(refreshTokenDecoded?.exp * 1000)) | |||
| console.log(new Date()) | |||
| if (new Date() > new Date(refreshTokenDecoded?.exp * 1000)) { | |||
| dispatch(logoutUser()); | |||
| return Promise.resolve(response) | |||
| @@ -5,6 +5,7 @@ import { | |||
| attemptFetchFeaturedOffers, | |||
| attemptFetchOffers, | |||
| attemptFetchOneOffer, | |||
| attemptFetchProfileOffersAsAdmin, | |||
| attemptPinOffer, | |||
| attemptRemoveOffer, | |||
| attemptRemoveOfferAsAdmin, | |||
| @@ -202,7 +203,17 @@ function* createOffer(payload) { | |||
| function* fetchOneOffer(payload) { | |||
| try { | |||
| const data = yield call(attemptFetchOneOffer, payload.payload); | |||
| let offerId = payload.payload; | |||
| console.log("sagabb", payload.payload); | |||
| const queryObject = new URLSearchParams(); | |||
| if (typeof payload.payload === "object") { | |||
| offerId = payload.payload.offerId; | |||
| queryObject.set("view", "true"); | |||
| } | |||
| const data = yield call(attemptFetchOneOffer, { | |||
| offerId, | |||
| queryObject, | |||
| }); | |||
| if (!data?.data) throw new Error(); | |||
| yield put(fetchOneOfferSuccess(data?.data)); | |||
| } catch (e) { | |||
| @@ -261,11 +272,20 @@ function* fetchProfileOffers(payload) { | |||
| queryString = yield select(selectQueryString); | |||
| } | |||
| console.log(queryString.toString()); | |||
| const data = yield call( | |||
| attemptFetchProfileOffers, | |||
| userId, | |||
| convertQueryStringForBackend(queryString) | |||
| ); | |||
| let data; | |||
| if (payload.payload.isAdmin) { | |||
| data = yield call( | |||
| attemptFetchProfileOffersAsAdmin, | |||
| userId, | |||
| convertQueryStringForBackend(queryString) | |||
| ); | |||
| } else { | |||
| data = yield call( | |||
| attemptFetchProfileOffers, | |||
| userId, | |||
| convertQueryStringForBackend(queryString) | |||
| ); | |||
| } | |||
| if (payload.payload.append) { | |||
| yield put(addProfileOffers(data.data.offers)); | |||
| } else { | |||
| @@ -319,7 +339,7 @@ function* editOffer(payload) { | |||
| const offerData = payload.payload.offerData; | |||
| const formData = new FormData(); | |||
| formData.append("category[name]", offerData.category.name); | |||
| formData.append("condition", offerData.condition); | |||
| formData.append("condition", offerData.condition.toLowerCase()); | |||
| formData.append("description", offerData.description); | |||
| // const oldImages = []; | |||
| for (var i = 0; i < offerData.images.length; i++) { | |||
| @@ -28,7 +28,7 @@ function* fetchReviews(payload) { | |||
| try { | |||
| console.log(payload); | |||
| const data = yield call(attemptFetchReview, payload.payload); | |||
| yield put(setReviews([...data.data].reverse())); | |||
| yield put(setReviews([...data.data.reviews].reverse())); | |||
| yield put(fetchReviewsSuccess()); | |||
| } catch (e) { | |||
| yield put(fetchReviewsError()); | |||