header.js 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  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} 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}) => {
  37. const history = useHistory();
  38. useEffect(() => history.location.pathname.includes(`/profile/`) && (login ? history.push(`/profile/` + login) : history.push(`/login`)),[login])
  39. return(
  40. <>
  41. <svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" fill="currentColor" className="bi bi-person" viewBox="0 0 16 16">
  42. <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"/>
  43. </svg>
  44. <Link to = {login ? "/profile/" + login: "/login"} >
  45. <span className = "link">{login ? login : "Вхід"}</span>
  46. {login && <button onClick = {onLogout}>Вихід</button>}
  47. </Link>
  48. </>
  49. )
  50. }
  51. const CToLoginPage = connect(s => ({login: s.auth.payload && s.auth.payload.sub.login}), {onLogout: actionAuthLogout}) (ToLoginPage);
  52. const Basket = ({basketCount, data, className = "basket"}) => {
  53. return(
  54. <div className = {className}>
  55. <Link to = "/basket">
  56. <svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" fill="currentColor" className="bi bi-bag" viewBox="0 0 16 16">
  57. <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"/>
  58. </svg>
  59. <span>{basketCount || "0"}грн</span>
  60. </Link>
  61. </div>
  62. )
  63. }
  64. const CBasket = connect(s => ({data: s.basket, basketCount: s.basket.price}), {})(Basket)
  65. const Header = ({}) => {
  66. const [wishes, wishesCount] = useState(0);
  67. console.log(connect((s) => ({isLoggedIn: s.auth.payload})))
  68. return(
  69. <>
  70. <div className = "header">
  71. <div className = "tabletMenu">
  72. <TabletMenu/>
  73. </div>
  74. <StandartMenu/>
  75. <div className = "rightSide">
  76. <div>
  77. <svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" fill="currentColor" className="bi bi-heart" viewBox="0 0 16 16">
  78. <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"/>
  79. </svg>
  80. <span>Хочу({wishes})</span>
  81. </div>
  82. <div>
  83. <CToLoginPage/>
  84. </div>
  85. <CBasket/>
  86. </div>
  87. </div>
  88. </>
  89. )
  90. }
  91. export default Header;