| ITEM_DETAILS_PAGE, | ITEM_DETAILS_PAGE, | ||||
| PROFILE_PAGE, | PROFILE_PAGE, | ||||
| } from "../../../constants/pages"; | } from "../../../constants/pages"; | ||||
| import { dynamicRouteMatches, replaceInRoute } from "../../../util/helpers/routeHelpers"; | |||||
| import { | |||||
| dynamicRouteMatches, | |||||
| replaceInRoute, | |||||
| } from "../../../util/helpers/routeHelpers"; | |||||
| import { selectIsLoadingByActionType } from "../../../store/selectors/loadingSelectors"; | import { selectIsLoadingByActionType } from "../../../store/selectors/loadingSelectors"; | ||||
| import { | import { | ||||
| OFFER_ADD_SCOPE, | OFFER_ADD_SCOPE, | ||||
| const [currentStep, setCurrentStep] = useState(1); | const [currentStep, setCurrentStep] = useState(1); | ||||
| const { t } = useTranslation(); | const { t } = useTranslation(); | ||||
| const userId = useSelector(selectUserId); | const userId = useSelector(selectUserId); | ||||
| console.log(offer); | |||||
| const isLoading = useSelector( | const isLoading = useSelector( | ||||
| selectIsLoadingByActionType(editOffer ? OFFER_EDIT_SCOPE : OFFER_ADD_SCOPE) | selectIsLoadingByActionType(editOffer ? OFFER_EDIT_SCOPE : OFFER_ADD_SCOPE) | ||||
| ); | ); | ||||
| if (editOffer) { | if (editOffer) { | ||||
| if (routeMatches(BASE_PAGE) || routeMatches(HOME_PAGE)) | if (routeMatches(BASE_PAGE) || routeMatches(HOME_PAGE)) | ||||
| dispatch(fetchOffers({ queryString })); | dispatch(fetchOffers({ queryString })); | ||||
| if (dynamicRouteMatches(PROFILE_PAGE) || dynamicRouteMatches(ADMIN_SINGLE_USER_PAGE)) | |||||
| if ( | |||||
| dynamicRouteMatches(PROFILE_PAGE) || | |||||
| dynamicRouteMatches(ADMIN_SINGLE_USER_PAGE) | |||||
| ) | |||||
| if (isAdmin) dispatch(fetchProfileOffers(customUserId)); | if (isAdmin) dispatch(fetchProfileOffers(customUserId)); | ||||
| else dispatch(fetchProfileOffers(userId)); | else dispatch(fetchProfileOffers(userId)); | ||||
| editOffer: true, | editOffer: true, | ||||
| offer: offer?.offer, | offer: offer?.offer, | ||||
| isAdmin: props.isAdmin, | isAdmin: props.isAdmin, | ||||
| customUserId: offer?.offer?.userId | |||||
| customUserId: offer?.offer?.userId, | |||||
| }) | }) | ||||
| ); | ); | ||||
| }; | }; | ||||
| }) | }) | ||||
| ); | ); | ||||
| }; | }; | ||||
| console.log(offer); | |||||
| return ( | return ( | ||||
| <> | <> | ||||
| <ItemDetailsCardContainer | <ItemDetailsCardContainer |
| const { t } = useTranslation(); | const { t } = useTranslation(); | ||||
| const queryString = useSelector(selectQueryString); | const queryString = useSelector(selectQueryString); | ||||
| const history = useHistory(); | const history = useHistory(); | ||||
| const userId = props.offer.userId; | |||||
| const userId = props.offer.user._id; | |||||
| const { isMobile } = useIsMobile(); | const { isMobile } = useIsMobile(); | ||||
| const offerId = props.offer._id; | const offerId = props.offer._id; | ||||
| const closeDeleteModalHandler = () => { | const closeDeleteModalHandler = () => { |
| return true; | return true; | ||||
| }, [userId, props.offer]); | }, [userId, props.offer]); | ||||
| console.log("props", props); | |||||
| return ( | return ( | ||||
| <React.Fragment> | <React.Fragment> | ||||
| <OfferCardContainer | <OfferCardContainer |
| 100 | 100 | ||||
| ); | ); | ||||
| } | } | ||||
| console.log(profileFromRedux); | |||||
| return ( | return ( | ||||
| <> | <> | ||||
| {isLoading ? ( | {isLoading ? ( |
| }, [props.offer]); | }, [props.offer]); | ||||
| const userId = useSelector(selectUserId); | const userId = useSelector(selectUserId); | ||||
| const { isMobile } = useIsMobile(); | const { isMobile } = useIsMobile(); | ||||
| console.log(props); | |||||
| const handleGoProfile = () => { | const handleGoProfile = () => { | ||||
| history.push(`/profile/${offer?.offer?.userId}`); | |||||
| history.push(`/profile/${offer?.offer?.user?._id}`); | |||||
| }; | }; | ||||
| const messageUser = (offer) => { | const messageUser = (offer) => { | ||||
| const chatItem = chats.find( | const chatItem = chats.find( |
| const toggleFilters = () => { | const toggleFilters = () => { | ||||
| props?.toggleFilters(); | props?.toggleFilters(); | ||||
| }; | }; | ||||
| return ( | return ( | ||||
| <> | <> | ||||
| {!props?.skeleton ? ( | {!props?.skeleton ? ( |
| const isMyProfile = useMemo(() => { | const isMyProfile = useMemo(() => { | ||||
| return userId === routeMatch.params.idProfile; | return userId === routeMatch.params.idProfile; | ||||
| }, [userId, routeMatch]); | }, [userId, routeMatch]); | ||||
| console.log(userId); | |||||
| return ( | return ( | ||||
| <ProfileContainer className={props.className}> | <ProfileContainer className={props.className}> | ||||
| <Header isAdmin={props.isAdmin} /> | <Header isAdmin={props.isAdmin} /> |
| const total = useSelector(selectTotalOffers); | const total = useSelector(selectTotalOffers); | ||||
| const dispatch = useDispatch(); | const dispatch = useDispatch(); | ||||
| const searchRef = useRef(null); | const searchRef = useRef(null); | ||||
| console.log(props); | |||||
| console.log(profileOffers); | |||||
| useEffect(() => { | useEffect(() => { | ||||
| dispatch( | dispatch( |
| if (offer?.offer?.userId?.toString() === userId?.toString()) return true; | if (offer?.offer?.userId?.toString() === userId?.toString()) return true; | ||||
| return false; | return false; | ||||
| }, [offer, userId]); | }, [offer, userId]); | ||||
| console.log(offer); | |||||
| return ( | return ( | ||||
| <> | <> | ||||
| {isLoadingOfferContent || isLoadingOfferContent === undefined ? ( | {isLoadingOfferContent || isLoadingOfferContent === undefined ? ( |
| const selectedOffer = useSelector(selectOffer); | const selectedOffer = useSelector(selectOffer); | ||||
| const [isInitiallyLoaded, setIsInitiallyLoaded] = useState(false); | const [isInitiallyLoaded, setIsInitiallyLoaded] = useState(false); | ||||
| const offerId = props.match.params.idProizvod; | const offerId = props.match.params.idProizvod; | ||||
| console.log(selectedOffer); | |||||
| useEffect(() => { | useEffect(() => { | ||||
| dispatch(fetchOneOffer(offerId)); | dispatch(fetchOneOffer(offerId)); |
| // baseURL: "http://192.168.88.175:3005/", | // baseURL: "http://192.168.88.175:3005/", | ||||
| // baseURL: "http://192.168.88.143:3001/", // DULE | // baseURL: "http://192.168.88.143:3001/", // DULE | ||||
| // baseURL: "https://trampa-api.dilig.net/", | // baseURL: "https://trampa-api.dilig.net/", | ||||
| baseURL: "https://trampa-api-test.dilig.net/", | |||||
| // baseURL: "https://trampa-api-test.dilig.net/", | |||||
| baseURL: "https://trampa-qa-api.dilig.net/", | |||||
| // baseURL: "http://localhost:3001/", | // baseURL: "http://localhost:3001/", | ||||
| // baseURL: process.env.REACT_APP_BASE_API_URL, | // baseURL: process.env.REACT_APP_BASE_API_URL, | ||||
| headers: { | headers: { |
| // const baseURL = "http://192.168.88.143:3001/"; // DULE | // const baseURL = "http://192.168.88.143:3001/"; // DULE | ||||
| // const baseURL = "http://192.168.88.175:3005/"; | // const baseURL = "http://192.168.88.175:3005/"; | ||||
| // const baseURL = "https://trampa-api.dilig.net/"; | // 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 = "https://trampa-qa-api.dilig.net/"; | |||||
| // const baseURL = "http://192.168.88.150:3001/"; // DJOLE | // 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 | // const baseURL = process.env.REACT_APP_BASE_API_URL |
| try { | try { | ||||
| const data = yield call(attemptFetchLocations); | const data = yield call(attemptFetchLocations); | ||||
| if (!data?.data) throw new Error(); | if (!data?.data) throw new Error(); | ||||
| yield put(setLocations(data.data.value)); | |||||
| yield put(setLocations(data.data)); | |||||
| yield put(fetchLocationsSuccess()); | yield put(fetchLocationsSuccess()); | ||||
| } catch (e) { | } catch (e) { | ||||
| yield put(fetchLocationsError()); | yield put(fetchLocationsError()); |
| try { | try { | ||||
| const userId = yield select(selectUserId); | const userId = yield select(selectUserId); | ||||
| const data = yield call(attemptFetchProfileOffers, userId); | const data = yield call(attemptFetchProfileOffers, userId); | ||||
| console.log(userId, data); | |||||
| yield put(setMineOffers(data.data.offers)); | yield put(setMineOffers(data.data.offers)); | ||||
| yield put(fetchMineOffersSuccess()); | yield put(fetchMineOffersSuccess()); | ||||
| } catch (e) { | } catch (e) { | ||||
| function* fetchProfileOffers(payload) { | function* fetchProfileOffers(payload) { | ||||
| try { | try { | ||||
| console.log(payload.payload); | |||||
| console.log(payload); | |||||
| let userId; | let userId; | ||||
| if (typeof payload.payload === "object") { | if (typeof payload.payload === "object") { | ||||
| userId = payload.payload.idProfile; | userId = payload.payload.idProfile; | ||||
| queryString = yield select(selectQueryString); | queryString = yield select(selectQueryString); | ||||
| } | } | ||||
| console.log(queryString.toString()); | console.log(queryString.toString()); | ||||
| console.log(userId); | |||||
| const data = yield call( | const data = yield call( | ||||
| attemptFetchProfileOffers, | attemptFetchProfileOffers, | ||||
| userId, | userId, | ||||
| convertQueryStringForBackend(queryString) | convertQueryStringForBackend(queryString) | ||||
| ); | ); | ||||
| console.log(data); | |||||
| if (payload.payload.append) { | if (payload.payload.append) { | ||||
| yield put(addProfileOffers(data.data.offers)); | yield put(addProfileOffers(data.data.offers)); | ||||
| } else { | } else { | ||||
| function* removeOffer(payload) { | function* removeOffer(payload) { | ||||
| try { | try { | ||||
| const userId = yield select(selectUserId); | const userId = yield select(selectUserId); | ||||
| console.log(userId); | |||||
| const offerId = payload.payload.offerId; | const offerId = payload.payload.offerId; | ||||
| if (payload.payload.isAdmin) yield call(attemptRemoveOfferAsAdmin, offerId); | if (payload.payload.isAdmin) yield call(attemptRemoveOfferAsAdmin, offerId); | ||||
| else yield call(attemptRemoveOffer, userId, offerId); | else yield call(attemptRemoveOffer, userId, offerId); | ||||
| const offerId = payload.payload.offerId; | const offerId = payload.payload.offerId; | ||||
| // const editedData = payload.payload.offerData; | // const editedData = payload.payload.offerData; | ||||
| const offerData = payload.payload.offerData; | const offerData = payload.payload.offerData; | ||||
| console.log(userId, offerId, payload); | |||||
| const formData = new FormData(); | const formData = new FormData(); | ||||
| formData.append("category[name]", offerData.category.name); | formData.append("category[name]", offerData.category.name); | ||||
| formData.append("condition", offerData.condition); | formData.append("condition", offerData.condition); |
| function* fetchProfile(payload) { | function* fetchProfile(payload) { | ||||
| try { | try { | ||||
| console.log("JOHAN", payload); | |||||
| const data = yield call(attemptFetchProfile, payload.payload); | const data = yield call(attemptFetchProfile, payload.payload); | ||||
| if (data) yield put(setProfile(data.data)); | if (data) yield put(setProfile(data.data)); | ||||
| yield put(fetchProfileSuccess()); | yield put(fetchProfileSuccess()); |
| function* fetchReviews(payload) { | function* fetchReviews(payload) { | ||||
| try { | try { | ||||
| console.log(payload); | |||||
| console.log("JOHAN", payload); | |||||
| const data = yield call(attemptFetchReview, payload.payload); | const data = yield call(attemptFetchReview, payload.payload); | ||||
| yield put(setReviews([...data.data].reverse())); | yield put(setReviews([...data.data].reverse())); | ||||
| yield put(fetchReviewsSuccess()); | yield put(fetchReviewsSuccess()); |
| ); | ); | ||||
| export const selectTotalProfiles = createSelector( | export const selectTotalProfiles = createSelector( | ||||
| profileSelector, | profileSelector, | ||||
| state => state.allProfiles?.total | |||||
| ) | |||||
| (state) => state.allProfiles?.total | |||||
| ); | |||||
| export const selectAmIBlocked = createSelector( | export const selectAmIBlocked = createSelector( | ||||
| profileSelector, | profileSelector, | ||||
| state => state?.mineProfile?._blocked | |||||
| ) | |||||
| (state) => state?.mineProfile?._blocked | |||||
| ); |