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.

StatisticDetails.js 1.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. import React, { useMemo } from "react";
  2. import PropTypes from "prop-types";
  3. import {
  4. BottomDetails,
  5. HeaderDetails,
  6. StatusText,
  7. StatusValue,
  8. } from "./StatisticDetails.styled";
  9. import { useTranslation } from "react-i18next";
  10. const StatisticDetails = (props) => {
  11. const { t } = useTranslation();
  12. const offer = props.offer;
  13. const percentOfSucceededExchanges = useMemo(() => {
  14. if (offer?.user?.statistics?.exchanges?.succeeded === 0) {
  15. return 0 + "%";
  16. } else {
  17. return (
  18. Math.ceil(
  19. (offer?.user?.statistics?.exchanges?.total /
  20. offer?.user?.statistics?.exchanges?.succeeded) *
  21. 100
  22. ) + "%"
  23. );
  24. }
  25. });
  26. return (
  27. <HeaderDetails>
  28. <BottomDetails>
  29. <StatusText>
  30. <StatusValue>
  31. {offer?.user?.statistics?.publishes?.count}
  32. </StatusValue>
  33. {t("itemDetailsCard.offers")}
  34. </StatusText>
  35. <StatusText>
  36. <StatusValue>
  37. {offer?.user?.statistics?.views?.count}
  38. </StatusValue>
  39. {t("itemDetailsCard.totalViews")}
  40. </StatusText>
  41. <StatusText>
  42. <StatusValue>{percentOfSucceededExchanges}</StatusValue>
  43. {t("itemDetailsCard.successfulExchanges")}
  44. </StatusText>
  45. <StatusText>
  46. <StatusValue>{percentOfSucceededExchanges}</StatusValue>
  47. {t("itemDetailsCard.correctCommunications")}
  48. </StatusText>
  49. </BottomDetails>
  50. </HeaderDetails>
  51. );
  52. };
  53. StatisticDetails.propTypes = {
  54. offer: PropTypes.any,
  55. };
  56. export default StatisticDetails;