Header.jsx 3.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  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 Logo from '../component/Header/Logo.jsx'
  6. import NavbarToggler from '../component/Header/NavbarToggler.jsx'
  7. import MenuLinkList from '../component/Header/MenuLinkList.jsx'
  8. // import MenuActionList from '../component/Header/MenuActionList.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. class Header extends React.Component {
  24. handleClickLogo = () => {}
  25. handleClickFeature = () => {}
  26. handleClickExplore = () => {}
  27. handleClickAbout = () => {}
  28. handleChangeInput = e => this.setState({inputSearchValue: e.target.value})
  29. handleClickSubmit = () => {}
  30. handleChangeLang = langId => {
  31. this.props.dispatch(setLangActive(langId))
  32. i18n.changeLanguage(langId)
  33. }
  34. handleClickHelp = () => {}
  35. handleClickLogout = async () => {
  36. const { dispatch, t } = this.props
  37. const fetchPostUserLogout = await dispatch(postUserLogout())
  38. if (fetchPostUserLogout.status === 204) dispatch(setUserDisconnected())
  39. else dispatch(newFlashMessage(t('Login.logout_error', 'danger')))
  40. }
  41. render () {
  42. const { lang, user } = this.props
  43. return (
  44. <header className='header'>
  45. <nav className='navbar navbar-expand-md navbar-light bg-light'>
  46. <Logo logoSrc={logoHeader} onClickImg={this.handleClickLogo} />
  47. <div className='header__breadcrumb d-none d-lg-block ml-4'>
  48. Dev Tracim - liste des contenus
  49. </div>
  50. <NavbarToggler />
  51. <div className='header__menu collapse navbar-collapse justify-content-end' id='navbarSupportedContent'>
  52. <MenuLinkList
  53. onClickFeature={this.handleClickFeature}
  54. onClickExplore={this.handleClickExplore}
  55. onClickAbout={this.handleClickAbout}
  56. />
  57. <ul className='header__menu__rightside'>
  58. <MenuActionListItemSearch
  59. onChangeInput={this.handleChangeInput}
  60. onClickSubmit={this.handleClickSubmit}
  61. />
  62. <MenuActionListItemDropdownLang
  63. langList={lang}
  64. onChangeLang={this.handleChangeLang}
  65. />
  66. <MenuActionListItemHelp
  67. onClickHelp={this.handleClickHelp}
  68. />
  69. <MenuActionListItemNotification />
  70. <MenuActionListItemMenuProfil
  71. user={user}
  72. onClickLogout={this.handleClickLogout}
  73. />
  74. </ul>
  75. </div>
  76. </nav>
  77. </header>
  78. )
  79. }
  80. }
  81. const mapStateToProps = ({ lang, user }) => ({ lang, user })
  82. export default connect(mapStateToProps)(translate()(Header))