header.js 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151
  1. import {Footer, Links} from "./index"
  2. import {BrowserRouter as Router, Route, Link, Switch, Redirect, useHistory} from 'react-router-dom';
  3. import {Provider, connect} from 'react-redux';
  4. import React, {Component, useState, useEffect} from 'react';
  5. // import createHistory from "history/createBrowserHistory";
  6. import {actionAuthLogout, actionUserFindOne} from "../reducers"
  7. import {createStore, combineReducers, applyMiddleware} from 'redux';
  8. import thunk from 'redux-thunk';
  9. const StandartMenu = ({className = "standartMenu", getCat = null}) => {
  10. return (
  11. <>
  12. <ul className = {className}>
  13. <Links url = {"/catalog"} text = {"Каталог"}/>
  14. <Links url = {"/about"} text = {"Про нас"}/>
  15. {/* <Links url = {"/post"} text = {"Оплата і доставка"}/> */}
  16. <Links url = {"/contacts"} text = {"Контакти"}></Links>
  17. </ul>
  18. </>
  19. )
  20. }
  21. const TabletMenu = ({}) => {
  22. const [show, setShow] = useState(false)
  23. const divStyle = "mobileMenu"
  24. function onClick() {
  25. setShow(!show)
  26. }
  27. return (
  28. <>
  29. <svg onClick = {onClick} xmlns="http://www.w3.org/2000/svg" width="50" height="50" fill="currentColor" className="bi bi-justify-left" viewBox="0 0 16 16">
  30. <path fillRule="evenodd" d="M2 12.5a.5.5 0 0 1 .5-.5h7a.5.5 0 0 1 0 1h-7a.5.5 0 0 1-.5-.5zm0-3a.5.5 0 0 1 .5-.5h11a.5.5 0 0 1 0 1h-11a.5.5 0 0 1-.5-.5zm0-3a.5.5 0 0 1 .5-.5h11a.5.5 0 0 1 0 1h-11a.5.5 0 0 1-.5-.5zm0-3a.5.5 0 0 1 .5-.5h11a.5.5 0 0 1 0 1h-11a.5.5 0 0 1-.5-.5z"/>
  31. </svg>
  32. {show && <StandartMenu className = {divStyle}/>}
  33. </>
  34. )
  35. }
  36. const ToLoginPage = ({login, onLogout, getData, NickName = "User", loginId}) => {
  37. // useEffect(() => login && getData(loginId),[login])
  38. const history = useHistory();
  39. useEffect(() => history.location.pathname.includes(`/profile/`) && (login ? history.push(`/profile/`) : history.push(`/login`)),[login])
  40. return(
  41. <>
  42. <svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" fill="currentColor" className="bi bi-person" viewBox="0 0 16 16">
  43. <path d="M8 8a3 3 0 1 0 0-6 3 3 0 0 0 0 6zm2-3a2 2 0 1 1-4 0 2 2 0 0 1 4 0zm4 8c0 1-1 1-1 1H3s-1 0-1-1 1-4 6-4 6 3 6 4zm-1-.004c-.001-.246-.154-.986-.832-1.664C11.516 10.68 10.289 10 8 10c-2.29 0-3.516.68-4.168 1.332-.678.678-.83 1.418-.832 1.664h10z"/>
  44. </svg>
  45. <Link to = {login ? "/profile/": "/login"} >
  46. <span className = "link">{login ? login : "Вхід"}</span>
  47. {login && <button onClick = {() => onLogout()}>Вихід</button>}
  48. </Link>
  49. </>
  50. )
  51. }
  52. const CToLoginPage = connect(s => ({
  53. login: s.auth.payload && s.auth.payload.sub.login,
  54. loginId: s.auth.payload && s.auth.payload.sub._id,
  55. NickName: s.promiseRed && s.promiseRed.user &&
  56. s.promiseRed.user.payload && s.promiseRed.user.payload.data &&
  57. s.promiseRed.user.payload.data.UserFindOne &&
  58. s.promiseRed.user.payload.data.UserFindOne.login,
  59. }), {onLogout: actionAuthLogout,
  60. getData: actionUserFindOne,
  61. }) (ToLoginPage);
  62. const Wishes = ({wishesCount}) => {
  63. return(
  64. <div>
  65. <Link to = "/wishes">
  66. <svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" fill="currentColor" className="bi bi-heart" viewBox="0 0 16 16">
  67. <path d="M8 2.748l-.717-.737C5.6.281 2.514.878 1.4 3.053c-.523 1.023-.641 2.5.314 4.385.92 1.815 2.834 3.989 6.286 6.357 3.452-2.368 5.365-4.542 6.286-6.357.955-1.886.838-3.362.314-4.385C13.486.878 10.4.28 8.717 2.01L8 2.748zM8 15C-7.333 4.868 3.279-3.04 7.824 1.143c.06.055.119.112.176.171a3.12 3.12 0 0 1 .176-.17C12.72-3.042 23.333 4.867 8 15z"/>
  68. </svg>
  69. <span>Хочу({wishesCount})</span>
  70. </Link>
  71. </div>
  72. )
  73. }
  74. const CWishes = connect(s => ({wishesCount: s.wishListReducer.count}), {})(Wishes)
  75. const Basket = ({basketCount, className = "basket"}) => {
  76. return(
  77. <div className = {className}>
  78. <Link to = "/basket">
  79. <svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" fill="currentColor" className="bi bi-bag" viewBox="0 0 16 16">
  80. <path d="M8 1a2.5 2.5 0 0 1 2.5 2.5V4h-5v-.5A2.5 2.5 0 0 1 8 1zm3.5 3v-.5a3.5 3.5 0 1 0-7 0V4H1v10a2 2 0 0 0 2 2h10a2 2 0 0 0 2-2V4h-3.5zM2 5h12v9a1 1 0 0 1-1 1H3a1 1 0 0 1-1-1V5z"/>
  81. </svg>
  82. <span>{basketCount || "0"}грн</span>
  83. </Link>
  84. </div>
  85. )
  86. }
  87. const CBasket = connect(s => ({data: s.basket, basketCount: s.basket.price}), {})(Basket)
  88. const Header = ({}) => {
  89. // const [wishes, wishesCount] = useState(0);
  90. console.log(connect((s) => ({isLoggedIn: s.auth.payload})))
  91. return(
  92. <>
  93. <div className = "header">
  94. <div className = "tabletMenu">
  95. <TabletMenu/>
  96. </div>
  97. <StandartMenu/>
  98. <div className = "rightSide">
  99. <CWishes/>
  100. {/* <div>
  101. <svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" fill="currentColor" className="bi bi-heart" viewBox="0 0 16 16">
  102. <path d="M8 2.748l-.717-.737C5.6.281 2.514.878 1.4 3.053c-.523 1.023-.641 2.5.314 4.385.92 1.815 2.834 3.989 6.286 6.357 3.452-2.368 5.365-4.542 6.286-6.357.955-1.886.838-3.362.314-4.385C13.486.878 10.4.28 8.717 2.01L8 2.748zM8 15C-7.333 4.868 3.279-3.04 7.824 1.143c.06.055.119.112.176.171a3.12 3.12 0 0 1 .176-.17C12.72-3.042 23.333 4.867 8 15z"/>
  103. </svg>
  104. <span>Хочу({wishes})</span>
  105. </div> */}
  106. <div>
  107. <CToLoginPage/>
  108. </div>
  109. <CBasket/>
  110. </div>
  111. </div>
  112. </>
  113. )
  114. }
  115. export default Header;