|  | @@ -3,6 +3,7 @@ import { connect } from 'react-redux'
 | 
	
		
			
			| 3 | 3 |  import { withRouter } from 'react-router'
 | 
	
		
			
			| 4 | 4 |  import classnames from 'classnames'
 | 
	
		
			
			| 5 | 5 |  import { translate } from 'react-i18next'
 | 
	
		
			
			|  | 6 | +import appFactory from '../appFactory.js'
 | 
	
		
			
			| 6 | 7 |  import WorkspaceListItem from '../component/Sidebar/WorkspaceListItem.jsx'
 | 
	
		
			
			| 7 | 8 |  import {
 | 
	
		
			
			| 8 | 9 |    setWorkspaceListIsOpenInSidebar,
 | 
	
	
		
			
			|  | @@ -12,7 +13,7 @@ import {
 | 
	
		
			
			| 12 | 13 |  import {
 | 
	
		
			
			| 13 | 14 |    getWorkspaceList
 | 
	
		
			
			| 14 | 15 |  } from '../action-creator.async.js'
 | 
	
		
			
			| 15 |  | -import { PAGE } from '../helper.js'
 | 
	
		
			
			|  | 16 | +import { PAGE, workspaceConfig } from '../helper.js'
 | 
	
		
			
			| 16 | 17 |  
 | 
	
		
			
			| 17 | 18 |  const qs = require('query-string')
 | 
	
		
			
			| 18 | 19 |  
 | 
	
	
		
			
			|  | @@ -23,22 +24,23 @@ class Sidebar extends React.Component {
 | 
	
		
			
			| 23 | 24 |        sidebarClose: false,
 | 
	
		
			
			| 24 | 25 |        workspaceIdInUrl: props.match.params.idws ? parseInt(props.match.params.idws) : null
 | 
	
		
			
			| 25 | 26 |      }
 | 
	
		
			
			| 26 |  | -  }
 | 
	
		
			
			| 27 |  | -
 | 
	
		
			
			| 28 |  | -  async componentDidMount () {
 | 
	
		
			
			| 29 |  | -    const { workspaceIdInUrl } = this.state
 | 
	
		
			
			| 30 |  | -    const { user, workspaceList, dispatch } = this.props
 | 
	
		
			
			| 31 | 27 |  
 | 
	
		
			
			| 32 |  | -    if (user.user_id !== -1 && workspaceList.length === 0) {
 | 
	
		
			
			| 33 |  | -      const fetchGetWorkspaceList = await dispatch(getWorkspaceList(user))
 | 
	
		
			
			|  | 28 | +    document.addEventListener('appCustomEvent', this.customEventReducer)
 | 
	
		
			
			|  | 29 | +  }
 | 
	
		
			
			| 34 | 30 |  
 | 
	
		
			
			| 35 |  | -      if (fetchGetWorkspaceList.status === 200) {
 | 
	
		
			
			| 36 |  | -        dispatch(updateWorkspaceListData(fetchGetWorkspaceList.json))
 | 
	
		
			
			| 37 |  | -        dispatch(setWorkspaceListIsOpenInSidebar(workspaceIdInUrl || fetchGetWorkspaceList.json[0].workspace_id, true))
 | 
	
		
			
			| 38 |  | -      }
 | 
	
		
			
			|  | 31 | +  customEventReducer = async ({ detail: { type, data } }) => {
 | 
	
		
			
			|  | 32 | +    switch (type) {
 | 
	
		
			
			|  | 33 | +      case 'refreshWorkspaceList':
 | 
	
		
			
			|  | 34 | +        console.log('%c<Sidebar> Custom event', 'color: #28a745', type, data)
 | 
	
		
			
			|  | 35 | +        this.loadWorkspaceList()
 | 
	
		
			
			|  | 36 | +        break
 | 
	
		
			
			| 39 | 37 |      }
 | 
	
		
			
			| 40 | 38 |    }
 | 
	
		
			
			| 41 | 39 |  
 | 
	
		
			
			|  | 40 | +  componentDidMount () {
 | 
	
		
			
			|  | 41 | +    this.loadWorkspaceList()
 | 
	
		
			
			|  | 42 | +  }
 | 
	
		
			
			|  | 43 | +
 | 
	
		
			
			| 42 | 44 |    componentDidUpdate (prevProps, prevState) {
 | 
	
		
			
			| 43 | 45 |      // console.log('%c<Sidebar> Did Update', 'color: #c17838')
 | 
	
		
			
			| 44 | 46 |      if (this.props.match.params.idws === undefined || isNaN(this.props.match.params.idws)) return
 | 
	
	
		
			
			|  | @@ -47,6 +49,20 @@ class Sidebar extends React.Component {
 | 
	
		
			
			| 47 | 49 |      if (prevState.workspaceIdInUrl !== newWorkspaceId) this.setState({workspaceIdInUrl: newWorkspaceId})
 | 
	
		
			
			| 48 | 50 |    }
 | 
	
		
			
			| 49 | 51 |  
 | 
	
		
			
			|  | 52 | +  loadWorkspaceList = async () => {
 | 
	
		
			
			|  | 53 | +    const { workspaceIdInUrl } = this.state
 | 
	
		
			
			|  | 54 | +    const { user, dispatch } = this.props
 | 
	
		
			
			|  | 55 | +
 | 
	
		
			
			|  | 56 | +    if (user.user_id !== -1) {
 | 
	
		
			
			|  | 57 | +      const fetchGetWorkspaceList = await dispatch(getWorkspaceList(user))
 | 
	
		
			
			|  | 58 | +
 | 
	
		
			
			|  | 59 | +      if (fetchGetWorkspaceList.status === 200) {
 | 
	
		
			
			|  | 60 | +        dispatch(updateWorkspaceListData(fetchGetWorkspaceList.json))
 | 
	
		
			
			|  | 61 | +        dispatch(setWorkspaceListIsOpenInSidebar(workspaceIdInUrl || fetchGetWorkspaceList.json[0].workspace_id, true))
 | 
	
		
			
			|  | 62 | +      }
 | 
	
		
			
			|  | 63 | +    }
 | 
	
		
			
			|  | 64 | +  }
 | 
	
		
			
			|  | 65 | +
 | 
	
		
			
			| 50 | 66 |    handleClickWorkspace = (idWs, newIsOpenInSidebar) => this.props.dispatch(setWorkspaceListIsOpenInSidebar(idWs, newIsOpenInSidebar))
 | 
	
		
			
			| 51 | 67 |  
 | 
	
		
			
			| 52 | 68 |    handleClickAllContent = idWs => {
 | 
	
	
		
			
			|  | @@ -70,6 +86,8 @@ class Sidebar extends React.Component {
 | 
	
		
			
			| 70 | 86 |  
 | 
	
		
			
			| 71 | 87 |    handleClickToggleSidebar = () => this.setState(prev => ({sidebarClose: !prev.sidebarClose}))
 | 
	
		
			
			| 72 | 88 |  
 | 
	
		
			
			|  | 89 | +  handleClickNewWorkspace = () => this.props.renderAppPopupCreation(workspaceConfig, this.props.user, null, null)
 | 
	
		
			
			|  | 90 | +
 | 
	
		
			
			| 73 | 91 |    render () {
 | 
	
		
			
			| 74 | 92 |      const { sidebarClose, workspaceIdInUrl } = this.state
 | 
	
		
			
			| 75 | 93 |      const { activeLang, workspaceList, t } = this.props
 | 
	
	
		
			
			|  | @@ -103,7 +121,10 @@ class Sidebar extends React.Component {
 | 
	
		
			
			| 103 | 121 |              </nav>
 | 
	
		
			
			| 104 | 122 |  
 | 
	
		
			
			| 105 | 123 |              <div className='sidebar__btnnewworkspace'>
 | 
	
		
			
			| 106 |  | -              <button className='sidebar__btnnewworkspace__btn btn btn-primary primaryColorBg primaryColorBorder primaryColorBorderDarkenHover mb-5'>
 | 
	
		
			
			|  | 124 | +              <button
 | 
	
		
			
			|  | 125 | +                className='sidebar__btnnewworkspace__btn btn btn-primary primaryColorBg primaryColorBorder primaryColorBorderDarkenHover mb-5'
 | 
	
		
			
			|  | 126 | +                onClick={this.handleClickNewWorkspace}
 | 
	
		
			
			|  | 127 | +              >
 | 
	
		
			
			| 107 | 128 |                  {t('Create a workspace')}
 | 
	
		
			
			| 108 | 129 |                </button>
 | 
	
		
			
			| 109 | 130 |              </div>
 | 
	
	
		
			
			|  | @@ -130,4 +151,4 @@ const mapStateToProps = ({ lang, user, workspace, workspaceList }) => ({
 | 
	
		
			
			| 130 | 151 |    workspace,
 | 
	
		
			
			| 131 | 152 |    workspaceList
 | 
	
		
			
			| 132 | 153 |  })
 | 
	
		
			
			| 133 |  | -export default withRouter(connect(mapStateToProps)(translate()(Sidebar)))
 | 
	
		
			
			|  | 154 | +export default withRouter(connect(mapStateToProps)(appFactory(translate()(Sidebar))))
 |