import React, { Component } from 'react'; import PropTypes from 'prop-types'; import { observer } from 'mobx-react'; import injectSheet from 'react-jss'; import { defineMessages, intlShape } from 'react-intl'; import { H1, Icon } from '@meetfranz/ui'; import ReactTooltip from 'react-tooltip'; import { workspacesState } from '../state'; import WorkspaceDrawerItem from './WorkspaceDrawerItem'; import { workspaceActions } from '../actions'; const messages = defineMessages({ headline: { id: 'workspaceDrawer.headline', defaultMessage: '!!!Workspaces', }, allServices: { id: 'workspaceDrawer.allServices', defaultMessage: '!!!All services', }, addWorkspaceTooltip: { id: 'workspaceDrawer.addWorkspaceTooltip', defaultMessage: '!!!Add workspace', }, }); const styles = theme => ({ drawer: { backgroundColor: theme.workspaceDrawerBackground, width: `${theme.workspaceDrawerWidth}px`, }, headline: { fontSize: '24px', marginTop: '38px', marginBottom: '25px', marginLeft: `${theme.workspaceDrawerPadding}px`, }, addWorkspaceButton: { float: 'right', marginRight: `${theme.workspaceDrawerPadding}px`, marginTop: '2px', }, addWorkspaceButtonIcon: { fill: theme.workspaceDrawerAddButtonColor, '&:hover': { fill: theme.workspaceDrawerAddButtonHoverColor, }, }, }); @injectSheet(styles) @observer class WorkspaceDrawer extends Component { static propTypes = { classes: PropTypes.object.isRequired, getServicesForWorkspace: PropTypes.func.isRequired, }; static contextTypes = { intl: intlShape, }; componentDidMount() { ReactTooltip.rebuild(); } render() { const { classes, getServicesForWorkspace, } = this.props; const { intl } = this.context; const { activeWorkspace, isSwitchingWorkspace, nextWorkspace } = workspacesState; const actualWorkspace = isSwitchingWorkspace ? nextWorkspace : activeWorkspace; return (

{intl.formatMessage(messages.headline)}

workspaceActions.deactivate()} services={getServicesForWorkspace(null)} isActive={actualWorkspace == null} /> {workspacesState.workspaces.map(workspace => ( workspaceActions.activate({ workspace })} services={getServicesForWorkspace(workspace)} /> ))}
); } } export default WorkspaceDrawer;