AdminWorkspaceUser.jsx 2.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. import React from 'react'
  2. import { translate } from 'react-i18next'
  3. import i18n from '../i18n.js'
  4. import {
  5. addAllResourceI18n
  6. // handleFetchResult
  7. } from 'tracim_frontend_lib'
  8. import { debug } from '../helper.js'
  9. import {
  10. } from '../action.async.js'
  11. import AdminWorkspace from '../component/AdminWorkspace.jsx'
  12. require('../css/index.styl')
  13. class AdminWorkspaceUser extends React.Component {
  14. constructor (props) {
  15. super(props)
  16. this.state = {
  17. appName: 'admin_workspace_user',
  18. isVisible: true,
  19. config: props.data ? props.data.config : debug.config,
  20. loggedUser: props.data ? props.data.loggedUser : debug.loggedUser,
  21. content: props.data ? props.data.content : debug.content
  22. }
  23. // i18n has been init, add resources from frontend
  24. addAllResourceI18n(i18n, this.state.config.translation)
  25. i18n.changeLanguage(this.state.loggedUser.lang)
  26. document.addEventListener('appCustomEvent', this.customEventReducer)
  27. }
  28. customEventReducer = ({ detail: { type, data } }) => { // action: { type: '', data: {} }
  29. switch (type) {
  30. case 'admin_workspace_user_showApp':
  31. console.log('%c<AdminWorkspaceUser> Custom event', 'color: #28a745', type, data)
  32. this.setState({config: data.config})
  33. break
  34. default:
  35. break
  36. }
  37. }
  38. componentDidMount () {
  39. console.log('%c<AdminWorkspaceUser> did mount', `color: ${this.state.config.hexcolor}`)
  40. this.loadContent()
  41. }
  42. componentDidUpdate (prevProps, prevState) {
  43. const { state } = this
  44. console.log('%c<AdminWorkspaceUser> did update', `color: ${this.state.config.hexcolor}`, prevState, state)
  45. if (prevState.config.type !== state.config.type) this.loadContent()
  46. }
  47. componentWillUnmount () {
  48. console.log('%c<AdminWorkspaceUser> will Unmount', `color: ${this.state.config.hexcolor}`)
  49. document.removeEventListener('appCustomEvent', this.customEventReducer)
  50. }
  51. loadContent = () => {
  52. return null
  53. }
  54. render () {
  55. const { isVisible } = this.state
  56. // const { t } = this.props
  57. if (!isVisible) return null
  58. return (
  59. <div>
  60. {this.state.config.type === 'workspace' &&
  61. <AdminWorkspace />
  62. }
  63. {this.state.config.type === 'user' &&
  64. <div>not yet implemented</div>
  65. }
  66. </div>
  67. )
  68. }
  69. }
  70. export default translate()(AdminWorkspaceUser)