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.

Header.js 7.5KB

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