aboutsummaryrefslogtreecommitdiffstats
path: root/src/features/workspaces/components/WorkspaceSwitchingIndicator.js
blob: c012ab0082c32bb5ab9c73ae618f128cb77ae97e (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
import React, { Component } from 'react';
import PropTypes from 'prop-types';
import { observer } from 'mobx-react';
import injectSheet from 'react-jss';
import classnames from 'classnames';
import { defineMessages, intlShape } from 'react-intl';

import LoaderComponent from '../../../components/ui/Loader';
import { workspaceStore } from '../index';

const messages = defineMessages({
  switchingTo: {
    id: 'workspaces.switchingIndicator.switchingTo',
    defaultMessage: '!!!Switching to',
  },
});

const styles = theme => ({
  wrapper: {
    display: 'flex',
    alignItems: 'flex-start',
    position: 'absolute',
    transition: 'width 0.5s ease',
    width: '100%',
    marginTop: '20px',
  },
  wrapperWhenDrawerIsOpen: {
    width: `calc(100% - ${theme.workspaceDrawerWidth}px)`,
  },
  component: {
    background: 'rgba(20, 20, 20, 0.4)',
    padding: 20,
    width: 'auto',
    height: 'auto',
    margin: [0, 'auto'],
    borderRadius: 6,
    alignItems: 'flex-start',
    zIndex: 200,
  },
  name: {
    fontSize: 35,
    marginBottom: '10px',
  },
});

@injectSheet(styles) @observer
class WorkspaceSwitchingIndicator extends Component {
  static propTypes = {
    classes: PropTypes.object.isRequired,
  };

  static contextTypes = {
    intl: intlShape,
  };

  render() {
    const { classes } = this.props;
    const { intl } = this.context;
    const { isSwitchingWorkspace, isWorkspaceDrawerOpen, nextWorkspace } = workspaceStore;
    if (!isSwitchingWorkspace) return null;
    const nextWorkspaceName = nextWorkspace ? nextWorkspace.name : 'All services';
    return (
      <div
        className={classnames([
          classes.wrapper,
          isWorkspaceDrawerOpen ? classes.wrapperWhenDrawerIsOpen : null,
        ])}
      >
        <div className={classes.component}>
          <h1 className={classes.name}>
            {`${intl.formatMessage(messages.switchingTo)} ${nextWorkspaceName}`}
          </h1>
          <LoaderComponent />
        </div>
      </div>
    );
  }
}

export default WorkspaceSwitchingIndicator;