|
|
|
@@ -1,8 +1,6 @@ |
|
|
|
import React, { useState } from "react"; |
|
|
|
import PropTypes from "prop-types"; |
|
|
|
import { useDispatch, useSelector } from "react-redux"; |
|
|
|
import { useHistory } from "react-router-dom"; |
|
|
|
import { HOME_PAGE } from "../../../constants/pages"; |
|
|
|
import { |
|
|
|
CreateOfferContainer, |
|
|
|
CreateOfferTitle, |
|
|
|
@@ -17,6 +15,7 @@ import SecondPartCreateOffer from "./SecondPart/SecondPartCreateOffer"; |
|
|
|
import ThirdPartCreateOffer from "./ThirdPart/ThirdPartCreateOffer"; |
|
|
|
import { |
|
|
|
addOffer, |
|
|
|
fetchOffers, |
|
|
|
fetchProfileOffers, |
|
|
|
} from "../../../store/actions/offers/offersActions"; |
|
|
|
import { editOneOffer } from "../../../store/actions/offers/offersActions"; |
|
|
|
@@ -25,32 +24,19 @@ import { ReactComponent as ArrowBack } from "../../../assets/images/svg/arrow-ba |
|
|
|
import { useTranslation } from "react-i18next"; |
|
|
|
import BackdropComponent from "../../MUI/BackdropComponent"; |
|
|
|
import CloseButton from "./CloseButton/CloseButton"; |
|
|
|
import { selectUserId } from "../../../store/selectors/loginSelectors"; |
|
|
|
|
|
|
|
const CreateOffer = ({ history, closeCreateOfferModal, editOffer, offer }) => { |
|
|
|
const CreateOffer = ({ closeCreateOfferModal, editOffer, offer }) => { |
|
|
|
const dispatch = useDispatch(); |
|
|
|
const [informations, setInformations] = useState({}); |
|
|
|
const [currentStep, setCurrentStep] = useState(1); |
|
|
|
const categories = useSelector((state) => state.categories.categories); |
|
|
|
const historyRouter = useHistory(); |
|
|
|
// const categories = useSelector((state) => state.categories.categories); |
|
|
|
const { t } = useTranslation(); |
|
|
|
const userId = useSelector(selectUserId); |
|
|
|
|
|
|
|
const handleApiResponseSuccess = () => { |
|
|
|
if (editOffer === undefined) { |
|
|
|
const userId = historyRouter.location.pathname.slice( |
|
|
|
9, |
|
|
|
historyRouter.location.pathname.length |
|
|
|
); |
|
|
|
dispatch(fetchProfileOffers(userId)); |
|
|
|
historyRouter.push({ |
|
|
|
pathname: HOME_PAGE, |
|
|
|
state: { |
|
|
|
from: history.location.pathname, |
|
|
|
}, |
|
|
|
}); |
|
|
|
} else { |
|
|
|
const userId = offer.userId; |
|
|
|
dispatch(fetchProfileOffers(userId)); |
|
|
|
} |
|
|
|
dispatch(fetchOffers({ queryString: "" })); |
|
|
|
dispatch(fetchProfileOffers(userId)); |
|
|
|
}; |
|
|
|
|
|
|
|
const handleNext = (values) => { |
|
|
|
@@ -69,12 +55,12 @@ const CreateOffer = ({ history, closeCreateOfferModal, editOffer, offer }) => { |
|
|
|
.replace("data:image/png;base64,", "") |
|
|
|
); |
|
|
|
|
|
|
|
let subcategories = []; |
|
|
|
for (const element of categories) { |
|
|
|
if (element.name === informations.category) { |
|
|
|
subcategories = element.subcategories.map((item) => item.name); |
|
|
|
} |
|
|
|
} |
|
|
|
// let subcategories = []; |
|
|
|
// for (const element of categories) { |
|
|
|
// if (element.name === informations.category) { |
|
|
|
// subcategories = element.subcategories.map((item) => item.name); |
|
|
|
// } |
|
|
|
// } |
|
|
|
|
|
|
|
const offerData = { |
|
|
|
name: informations.nameOfProduct, |
|
|
|
@@ -85,7 +71,6 @@ const CreateOffer = ({ history, closeCreateOfferModal, editOffer, offer }) => { |
|
|
|
condition: informations.condition, |
|
|
|
category: { |
|
|
|
name: informations.category, |
|
|
|
subcategories: subcategories, |
|
|
|
}, |
|
|
|
subcategory: informations.subcategory, |
|
|
|
images: newImgs, |