Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.

MyProfile.js 2.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. import React, { useEffect, useState } from "react";
  2. import {
  3. DollarIcon,
  4. GrayButtonsContainer,
  5. ProfileImgPIB,
  6. } from "./MyProfile.styled";
  7. import HeaderPopover from "../HeaderPopover/HeaderPopover";
  8. import { useTranslation } from "react-i18next";
  9. import { useDispatch, useSelector } from "react-redux";
  10. import { selectMineProfile } from "../../../store/selectors/profileSelectors";
  11. import { selectUserId } from "../../../store/selectors/loginSelectors";
  12. import { fetchMineProfile } from "../../../store/actions/profile/profileActions";
  13. import selectedTheme from "../../../themes";
  14. import { EyeIcon } from "../HeaderPopover/HeaderPopover.styled";
  15. import { useHistory } from "react-router-dom";
  16. import PropTypes from "prop-types";
  17. import { ABOUT_PAGE } from "../../../constants/pages";
  18. import LogoutButton from "./LogoutButton/LogoutButton";
  19. import AboutButton from "./AboutButton/AboutButton";
  20. import PrivacyPolicyButton from "./PrivacyPolicyButton/PrivacyPolicyButton";
  21. import scrollConstants from "../../../constants/scrollConstants";
  22. export const MyProfile = (props) => {
  23. const { t } = useTranslation();
  24. const profile = useSelector(selectMineProfile);
  25. const userId = useSelector(selectUserId);
  26. const dispatch = useDispatch();
  27. const history = useHistory();
  28. const [profileAsArray, setProfileAsArray] = useState([]);
  29. useEffect(() => {
  30. if (userId?.length > 1) {
  31. dispatch(fetchMineProfile());
  32. }
  33. }, [userId]);
  34. useEffect(() => {
  35. if (profile?.statistics) {
  36. setProfileAsArray([
  37. {
  38. src: profile.image,
  39. title: profile.company.name,
  40. onClick: () => seeMyProfile(),
  41. text: (
  42. <React.Fragment>
  43. <ProfileImgPIB />
  44. {`${t("itemDetailsCard.PIB")}${profile.company.PIB}`}
  45. </React.Fragment>
  46. ),
  47. },
  48. ]);
  49. }
  50. }, [profile]);
  51. const seeMyProfile = () => {
  52. history.push(`/profile/${userId}`);
  53. props.closePopover();
  54. };
  55. const seePrices = () => {
  56. history.push({
  57. pathname: ABOUT_PAGE,
  58. state: {
  59. clicked: true,
  60. navigation: scrollConstants.about.pricesPage,
  61. },
  62. });
  63. props.closePopover();
  64. };
  65. return (
  66. <HeaderPopover
  67. title={t("header.myProfile")}
  68. items={profileAsArray}
  69. buttonText={t("header.checkProfile")}
  70. buttonIcon={<EyeIcon color={selectedTheme.colors.iconYellowColor} />}
  71. isProfile
  72. buttonOnClick={() => seeMyProfile()}
  73. secondButtonIcon={<DollarIcon />}
  74. secondButtonText={t("header.prices")}
  75. secondButtonOnClick={seePrices}
  76. >
  77. <GrayButtonsContainer>
  78. <AboutButton closePopover={props.closePopover} />
  79. <PrivacyPolicyButton closePopover={props.closePopover} />
  80. </GrayButtonsContainer>
  81. <LogoutButton />
  82. </HeaderPopover>
  83. );
  84. };
  85. MyProfile.propTypes = {
  86. closePopover: PropTypes.func,
  87. };