aboutsummaryrefslogtreecommitdiffstats
path: root/ui/app/components/pages/settings/index.js
blob: aee17e0e8ffc7bedd2afc43d2c430437cdd98878 (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
const { Component } = require('react')
const { Switch, Route, matchPath } = require('react-router-dom')
const PropTypes = require('prop-types')
const h = require('react-hyperscript')
const TabBar = require('../../tab-bar')
const Settings = require('./settings')
const Info = require('./info')
const { DEFAULT_ROUTE, SETTINGS_ROUTE, INFO_ROUTE } = require('../../../routes')

class Config extends Component {
  renderTabs () {
    const { history, location } = this.props

    return h('div.settings__tabs', [
      h(TabBar, {
        tabs: [
          { content: this.context.t('settings'), key: SETTINGS_ROUTE },
          { content: this.context.t('info'), key: INFO_ROUTE },
        ],
        isActive: key => matchPath(location.pathname, { path: key, exact: true }),
        onSelect: key => history.push(key),
      }),
    ])
  }

  render () {
    const { history } = this.props

    return (
      h('.main-container.settings', {}, [
        h('.settings__header', [
          h('div.settings__close-button', {
            onClick: () => history.push(DEFAULT_ROUTE),
          }),
          this.renderTabs(),
        ]),
        h(Switch, [
          h(Route, {
            exact: true,
            path: INFO_ROUTE,
            component: Info,
          }),
          h(Route, {
            exact: true,
            path: SETTINGS_ROUTE,
            component: Settings,
          }),
        ]),
      ])
    )
  }
}

Config.propTypes = {
  location: PropTypes.object,
  history: PropTypes.object,
  t: PropTypes.func,
}

Config.contextTypes = {
  t: PropTypes.func,
}

module.exports = Config