Header.jsx 3.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. import React from 'react'
  2. import { connect } from 'react-redux'
  3. import i18n from '../i18n.js'
  4. import { translate } from 'react-i18next'
  5. import Cookies from 'js-cookie'
  6. import Logo from '../component/Header/Logo.jsx'
  7. import NavbarToggler from '../component/Header/NavbarToggler.jsx'
  8. import MenuLinkList from '../component/Header/MenuLinkList.jsx'
  9. import MenuActionListItemSearch from '../component/Header/MenuActionListItem/Search.jsx'
  10. import MenuActionListItemDropdownLang from '../component/Header/MenuActionListItem/DropdownLang.jsx'
  11. import MenuActionListItemHelp from '../component/Header/MenuActionListItem/Help.jsx'
  12. import MenuActionListItemMenuProfil from '../component/Header/MenuActionListItem/MenuProfil.jsx'
  13. import MenuActionListItemNotification from '../component/Header/MenuActionListItem/Notification.jsx'
  14. import logoHeader from '../img/logo-tracim.png'
  15. import {
  16. newFlashMessage,
  17. setLangActive,
  18. setUserDisconnected
  19. } from '../action-creator.sync.js'
  20. import {
  21. postUserLogout
  22. } from '../action-creator.async.js'
  23. import { COOKIE } from '../helper.js'
  24. class Header extends React.Component {
  25. handleClickLogo = () => {}
  26. handleClickFeature = () => {}
  27. handleClickExplore = () => {}
  28. handleClickAbout = () => {}
  29. handleChangeInput = e => this.setState({inputSearchValue: e.target.value})
  30. handleClickSubmit = () => {}
  31. handleChangeLang = langId => {
  32. this.props.dispatch(setLangActive(langId))
  33. i18n.changeLanguage(langId)
  34. }
  35. handleClickHelp = () => {}
  36. handleClickLogout = async () => {
  37. const { dispatch, t } = this.props
  38. const fetchPostUserLogout = await dispatch(postUserLogout())
  39. if (fetchPostUserLogout.status === 204) {
  40. Cookies.remove(COOKIE.USER_LOGIN)
  41. Cookies.remove(COOKIE.USER_AUTH)
  42. dispatch(setUserDisconnected())
  43. } else {
  44. dispatch(newFlashMessage(t('Disconnection error', 'danger')))
  45. }
  46. }
  47. render () {
  48. const { lang, user } = this.props
  49. return (
  50. <header className='header'>
  51. <nav className='navbar navbar-expand-md navbar-light bg-light'>
  52. <Logo logoSrc={logoHeader} onClickImg={this.handleClickLogo} />
  53. <div className='header__breadcrumb d-none d-lg-block ml-4'>
  54. Dev Tracim - liste des contenus
  55. </div>
  56. <NavbarToggler />
  57. <div className='header__menu collapse navbar-collapse justify-content-end' id='navbarSupportedContent'>
  58. <MenuLinkList
  59. onClickFeature={this.handleClickFeature}
  60. onClickExplore={this.handleClickExplore}
  61. onClickAbout={this.handleClickAbout}
  62. />
  63. <ul className='header__menu__rightside'>
  64. <MenuActionListItemSearch
  65. onChangeInput={this.handleChangeInput}
  66. onClickSubmit={this.handleClickSubmit}
  67. />
  68. <MenuActionListItemDropdownLang
  69. langList={lang}
  70. onChangeLang={this.handleChangeLang}
  71. />
  72. <MenuActionListItemHelp
  73. onClickHelp={this.handleClickHelp}
  74. />
  75. <MenuActionListItemNotification />
  76. <MenuActionListItemMenuProfil
  77. user={user}
  78. onClickLogout={this.handleClickLogout}
  79. />
  80. </ul>
  81. </div>
  82. </nav>
  83. </header>
  84. )
  85. }
  86. }
  87. const mapStateToProps = ({ lang, user }) => ({ lang, user })
  88. export default connect(mapStateToProps)(translate()(Header))