Header.jsx 3.7KB

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