Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238
  1. import React, { useMemo } from "react";
  2. import PropTypes from "prop-types";
  3. import {
  4. ButtonContainer,
  5. // ButtonContainer,
  6. CategoryHeaderIcon,
  7. HeaderAltLocation,
  8. HeaderButton,
  9. HeaderButtons,
  10. HeaderCategoryString,
  11. HeaderContainer,
  12. HeaderLocation,
  13. HeaderLocationsMainString,
  14. HeaderLocationsString,
  15. HeaderOptions,
  16. HeaderSelect,
  17. HeaderSubcategoryString,
  18. HeaderText,
  19. // HeaderText,
  20. HeaderTitleContainer,
  21. HeaderTitleText,
  22. HeaderWrapperContainer,
  23. IconStyled,
  24. PageTitleContainer,
  25. SelectOption,
  26. SwapsHeaderIcon,
  27. SwapsIcon,
  28. SwapsTitle,
  29. TooltipInnerContainer,
  30. UserIcon,
  31. } from "./Header.styled";
  32. import { ReactComponent as GridSquare } from "../../../assets/images/svg/offer-grid-square.svg";
  33. import { ReactComponent as GridLine } from "../../../assets/images/svg/offer-grid-line.svg";
  34. import { ReactComponent as Down } from "../../../assets/images/svg/down-arrow.svg";
  35. import selectedTheme from "../../../themes";
  36. import { sortEnum } from "../../../enums/sortEnum";
  37. import { useTranslation } from "react-i18next";
  38. import { Tooltip } from "@mui/material";
  39. import SkeletonHeader from "./SkeletonHeader/SkeletonHeader";
  40. import { useSelector } from "react-redux";
  41. import { selectHeaderString } from "../../../store/selectors/filtersSelectors";
  42. import useIsMobile from "../../../hooks/useIsMobile";
  43. import { ArrowButton } from "../../Buttons/ArrowButton/ArrowButton";
  44. // import { ArrowButton } from "../../Buttons/ArrowButton/ArrowButton";
  45. import history from "../../../store/utils/history";
  46. const DownArrow = (props) => (
  47. <IconStyled {...props}>
  48. <Down />
  49. </IconStyled>
  50. );
  51. const Header = (props) => {
  52. const { t } = useTranslation();
  53. const sorting = props?.sorting;
  54. const headerString = useSelector(selectHeaderString);
  55. const { isMobile } = useIsMobile();
  56. // Changing header string on refresh or on load
  57. const altString = useMemo(() => {
  58. if (!props?.users) {
  59. if (sorting?.selectedSortOption === sortEnum.OLD) {
  60. return `: ${t("header.oldOffers")}`;
  61. }
  62. if (sorting?.selectedSortOption === sortEnum.POPULAR) {
  63. return `: ${t("header.popularOffers")}`;
  64. }
  65. }
  66. return `: ${t("header.newOffers")}`;
  67. }, [sorting?.selectedSortOption]);
  68. const handleChangeSelect = (event) => {
  69. if (!props.users) sorting?.changeSorting(event.target.value);
  70. };
  71. const handleClickCategory = () => {
  72. props?.offers?.filters?.locations.clear();
  73. props?.offers?.filters?.subcategory.clear();
  74. props?.offers?.applyFilters();
  75. };
  76. const handleClickSubcategory = () => {
  77. props?.offers?.filters?.locations.clear();
  78. props?.offers?.applyFilters();
  79. };
  80. const goBack = () => {
  81. history.goBack();
  82. };
  83. return (
  84. <>
  85. <SkeletonHeader skeleton={props?.skeleton} myOffers={props?.myOffers} />
  86. <HeaderWrapperContainer
  87. skeleton={props?.skeleton}
  88. isAdmin={props?.isAdmin}
  89. >
  90. <HeaderContainer>
  91. {/* Setting appropriate header title if page is market place or my offers */}
  92. <Tooltip title={headerString.text}>
  93. <TooltipInnerContainer>
  94. {!props?.myOffers ? (
  95. <>
  96. <CategoryHeaderIcon />
  97. <HeaderLocation>
  98. {/* {headerString} */}
  99. <HeaderCategoryString
  100. component="span"
  101. onClick={handleClickCategory}
  102. >
  103. {headerString.categoryString}
  104. {/* {headerString.subcategoryString && <>&nbsp;</>} */}
  105. </HeaderCategoryString>
  106. <HeaderSubcategoryString
  107. component="span"
  108. onClick={handleClickSubcategory}
  109. >
  110. {headerString.subcategoryString}
  111. {/* {headerString.locationsString && <>&nbsp;</>} */}
  112. </HeaderSubcategoryString>
  113. <HeaderLocationsString component="span">
  114. <HeaderLocationsMainString component="span">
  115. {headerString.locationsString}
  116. </HeaderLocationsMainString>
  117. <HeaderAltLocation component="span">
  118. {altString}
  119. </HeaderAltLocation>
  120. </HeaderLocationsString>
  121. </HeaderLocation>
  122. </>
  123. ) : (
  124. <>
  125. {!isMobile ? (
  126. <HeaderTitleContainer>
  127. {props.users ? <UserIcon /> : <SwapsHeaderIcon />}
  128. <HeaderTitleText>
  129. {props.users
  130. ? t("admin.users.headerTitle")
  131. : t("header.myOffers")}
  132. </HeaderTitleText>
  133. </HeaderTitleContainer>
  134. ) : (
  135. <ButtonContainer onClick={goBack}>
  136. <ArrowButton side={"left"}></ArrowButton>
  137. <HeaderText>{t("messages.goBack")}</HeaderText>
  138. </ButtonContainer>
  139. )}
  140. </>
  141. )}
  142. </TooltipInnerContainer>
  143. </Tooltip>
  144. {/* ^^^^^^ */}
  145. <HeaderOptions>
  146. <HeaderButtons>
  147. {/* Setting display of offer cards to full width */}
  148. <HeaderButton
  149. iconColor={
  150. props?.isGrid
  151. ? selectedTheme.colors.iconStrokeColor
  152. : selectedTheme.colors.primaryPurple
  153. }
  154. onClick={() => props?.setIsGrid(false)}
  155. >
  156. <GridLine />
  157. </HeaderButton>
  158. {/* ^^^^^^ */}
  159. {/* Setting display of offer cards to half width (Grid) */}
  160. <HeaderButton
  161. iconColor={
  162. props?.isGrid
  163. ? selectedTheme.colors.primaryPurple
  164. : selectedTheme.colors.iconStrokeColor
  165. }
  166. onClick={() => props?.setIsGrid(true)}
  167. >
  168. <GridSquare />
  169. </HeaderButton>
  170. {/* ^^^^^^ */}
  171. </HeaderButtons>
  172. {/* Select option to choose sorting */}
  173. <HeaderSelect
  174. value={
  175. sorting?.selectedSortOption?.value
  176. ? sorting?.selectedSortOption
  177. : "default"
  178. }
  179. IconComponent={DownArrow}
  180. onChange={handleChangeSelect}
  181. myOffers={props?.myOffers}
  182. >
  183. <SelectOption style={{ display: "none" }} value="default">
  184. {t("reviews.sortBy")}
  185. </SelectOption>
  186. {Object.keys(sortEnum).map((property) => {
  187. if (sortEnum[property].value === 0) return;
  188. return (
  189. <SelectOption
  190. value={sortEnum[property]}
  191. key={sortEnum[property].value}
  192. >
  193. {sortEnum[property].mainText}
  194. </SelectOption>
  195. );
  196. })}
  197. </HeaderSelect>
  198. {/* ^^^^^^ */}
  199. </HeaderOptions>
  200. </HeaderContainer>
  201. {isMobile && (
  202. <PageTitleContainer>
  203. <SwapsIcon />
  204. <SwapsTitle>
  205. {props?.myOffers ? t("header.myOffers") : t("offer.offers")}
  206. </SwapsTitle>
  207. </PageTitleContainer>
  208. )}
  209. </HeaderWrapperContainer>
  210. </>
  211. );
  212. };
  213. Header.propTypes = {
  214. children: PropTypes.node,
  215. setIsGrid: PropTypes.func,
  216. isGrid: PropTypes.bool,
  217. offers: PropTypes.any,
  218. category: PropTypes.string,
  219. myOffers: PropTypes.bool,
  220. skeleton: PropTypes.bool,
  221. sorting: PropTypes.any,
  222. isAdmin: PropTypes.bool,
  223. users: PropTypes.bool,
  224. };
  225. Header.defaultProps = {
  226. isGrid: false,
  227. };
  228. export default Header;