You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

ItemDetailsPageMUI.js 1.9KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. import React, { useEffect, useState } from "react";
  2. import { PropTypes } from "prop-types";
  3. import { ItemDetailsPageContainer } from "./ItemDetailsPage.styled";
  4. import { useDispatch, useSelector } from "react-redux";
  5. import ItemDetails from "../../components/ItemDetails/ItemDetails";
  6. import ItemDetailsLayout from "../../layouts/ItemDetailsLayout/ItemDetailsLayout";
  7. import {
  8. clearSelectedOffer,
  9. fetchOneOffer,
  10. } from "../../store/actions/offers/offersActions";
  11. import UserReviews from "../../components/UserReviews/UserReviews";
  12. import { selectOffer } from "../../store/selectors/offersSelectors";
  13. import ProfileMini from "../../components/ProfileMini/ProfileMini";
  14. import history from "../../store/utils/history";
  15. const ItemDetailsPage = (props) => {
  16. const dispatch = useDispatch();
  17. const selectedOffer = useSelector(selectOffer);
  18. const [isInitiallyLoaded, setIsInitiallyLoaded] = useState(false);
  19. const offerId = props.match.params.offerId;
  20. useEffect(() => {
  21. const view = history?.location?.state?.view;
  22. console.log(view)
  23. dispatch(fetchOneOffer({ offerId, view }));
  24. () => dispatch(clearSelectedOffer());
  25. }, []);
  26. useEffect(() => {
  27. if (!selectedOffer?.offer && isInitiallyLoaded) {
  28. dispatch(fetchOneOffer(offerId));
  29. }
  30. if (selectedOffer?.offer) {
  31. setIsInitiallyLoaded(true);
  32. }
  33. }, [selectedOffer?.offer]);
  34. useEffect(() => {
  35. window.scrollTo({ top: 0, behaviour: "smooth" });
  36. }, []);
  37. return (
  38. <ItemDetailsPageContainer>
  39. <ItemDetailsLayout
  40. singleOffer
  41. content={<ItemDetails singleOffer />}
  42. rightCard={
  43. <>
  44. <ProfileMini /> <UserReviews rightReviews />
  45. </>
  46. }
  47. />
  48. </ItemDetailsPageContainer>
  49. );
  50. };
  51. ItemDetailsPage.propTypes = {
  52. match: PropTypes.shape({
  53. params: PropTypes.shape({
  54. offerId: PropTypes.string,
  55. }),
  56. }),
  57. };
  58. export default ItemDetailsPage;