Header.jsx 3.9KB

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