aboutsummaryrefslogtreecommitdiffstats
path: root/ui/app/pages/settings/settings.component.js
blob: 781b38effe5405bebeea13ffe1d21bc787670ad9 (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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
import React, { PureComponent } from 'react'
import PropTypes from 'prop-types'
import { Switch, Route, matchPath, withRouter } from 'react-router-dom'
import TabBar from '../../components/app/tab-bar'
import c from 'classnames'
import SettingsTab from './settings-tab'
import ConnectionsTab from './connections-tab'
import NetworksTab from './networks-tab'
import AdvancedTab from './advanced-tab'
import InfoTab from './info-tab'
import SecurityTab from './security-tab'
import ContactListTab from './contact-list-tab'
import {
  DEFAULT_ROUTE,
  ADVANCED_ROUTE,
  SECURITY_ROUTE,
  GENERAL_ROUTE,
  CONNECTIONS_ROUTE,
  ABOUT_US_ROUTE,
  SETTINGS_ROUTE,
  NETWORKS_ROUTE,
  CONTACT_LIST_ROUTE,
  CONTACT_ADD_ROUTE,
  CONTACT_EDIT_ROUTE,
  CONTACT_VIEW_ROUTE,
  CONTACT_MY_ACCOUNTS_ROUTE,
  CONTACT_MY_ACCOUNTS_VIEW_ROUTE,
  CONTACT_MY_ACCOUNTS_EDIT_ROUTE,
} from '../../helpers/constants/routes'

class SettingsPage extends PureComponent {
  static propTypes = {
    addressName: PropTypes.string,
    backRoute: PropTypes.string,
    currentPath: PropTypes.string,
    history: PropTypes.object,
    isAddressEntryPage: PropTypes.bool,
    isPopupView: PropTypes.bool,
    location: PropTypes.object,
    pathnameI18nKey: PropTypes.string,
    initialBreadCrumbRoute: PropTypes.string,
    breadCrumbTextKey: PropTypes.string,
    initialBreadCrumbKey: PropTypes.string,
    t: PropTypes.func,
  }

  static contextTypes = {
    t: PropTypes.func,
  }

  render () {
    const { history, backRoute, currentPath } = this.props

    return (
      <div
        className={c('main-container settings-page', {
          'settings-page--selected': currentPath !== SETTINGS_ROUTE,
        })}
      >
        <div className="settings-page__header">
          {
            currentPath !== SETTINGS_ROUTE && currentPath !== NETWORKS_ROUTE && (
              <div
                className="settings-page__back-button"
                onClick={() => history.push(backRoute)}
              />
            )
          }
          { this.renderTitle() }
          <div
            className="settings-page__close-button"
            onClick={() => history.push(DEFAULT_ROUTE)}
          />
        </div>
        <div className="settings-page__content">
          <div className="settings-page__content__tabs">
            { this.renderTabs() }
          </div>
          <div className="settings-page__content__modules">
            { this.renderSubHeader() }
            { this.renderContent() }
          </div>
        </div>
      </div>
    )
  }

  renderTitle () {
    const { t } = this.context
    const { isPopupView, pathnameI18nKey, addressName } = this.props

    let titleText

    if (isPopupView && addressName) {
      titleText = addressName
    } else if (pathnameI18nKey && isPopupView) {
      titleText = t(pathnameI18nKey)
    } else {
      titleText = t('settings')
    }

    return (
      <div className="settings-page__header__title">
        {titleText}
      </div>
    )
  }

  renderSubHeader () {
    const { t } = this.context
    const {
      currentPath,
      isPopupView,
      isAddressEntryPage,
      pathnameI18nKey,
      addressName,
      initialBreadCrumbRoute,
      breadCrumbTextKey,
      history,
      initialBreadCrumbKey,
    } = this.props

    let subheaderText

    if (isPopupView && isAddressEntryPage) {
      subheaderText = t('settings')
    } else if (initialBreadCrumbKey) {
      subheaderText = t(initialBreadCrumbKey)
    } else {
      subheaderText = t(pathnameI18nKey || 'general')
    }

    return currentPath !== NETWORKS_ROUTE && (
      <div className="settings-page__subheader">
        <div
          className={c({ 'settings-page__subheader--link': initialBreadCrumbRoute })}
          onClick={() => initialBreadCrumbRoute && history.push(initialBreadCrumbRoute)}
        >{subheaderText}</div>
        {breadCrumbTextKey && <div><span>{'> '}</span>{t(breadCrumbTextKey)}</div>}
        {isAddressEntryPage && <div><span>{' > '}</span>{addressName}</div>}
      </div>
    )
  }

  renderTabs () {
    const { history, currentPath } = this.props
    const { t } = this.context

    return (
      <TabBar
        tabs={[
          { content: t('general'), description: t('generalSettingsDescription'), key: GENERAL_ROUTE },
          { content: t('connections'), description: t('connectionsSettingsDescription'), key: CONNECTIONS_ROUTE },
          { content: t('advanced'), description: t('advancedSettingsDescription'), key: ADVANCED_ROUTE },
          { content: t('contacts'), description: t('contactsSettingsDescription'), key: CONTACT_LIST_ROUTE },
          { content: t('securityAndPrivacy'), description: t('securitySettingsDescription'), key: SECURITY_ROUTE },
          { content: t('networks'), description: t('networkSettingsDescription'), key: NETWORKS_ROUTE },
          { content: t('about'), description: t('aboutSettingsDescription'), key: ABOUT_US_ROUTE },
        ]}
        isActive={key => {
          if (key === GENERAL_ROUTE && currentPath === SETTINGS_ROUTE) {
            return true
          }
          return matchPath(currentPath, { path: key, exact: true })
        }}
        onSelect={key => history.push(key)}
      />
    )
  }

  renderContent () {
    return (
      <Switch>
        <Route
          exact
          path={GENERAL_ROUTE}
          component={SettingsTab}
        />
        <Route
          exact
          path={CONNECTIONS_ROUTE}
          component={ConnectionsTab}
        />
        <Route
          exact
          path={ABOUT_US_ROUTE}
          component={InfoTab}
        />
        <Route
          exact
          path={ADVANCED_ROUTE}
          component={AdvancedTab}
        />
        <Route
          exact
          path={NETWORKS_ROUTE}
          component={NetworksTab}
        />
        <Route
          exact
          path={SECURITY_ROUTE}
          component={SecurityTab}
        />
        <Route
          exact
          path={CONTACT_LIST_ROUTE}
          component={ContactListTab}
        />
        <Route
          exact
          path={CONTACT_ADD_ROUTE}
          component={ContactListTab}
        />
        <Route
          exact
          path={CONTACT_MY_ACCOUNTS_ROUTE}
          component={ContactListTab}
        />
        <Route
          exact
          path={`${CONTACT_EDIT_ROUTE}/:id`}
          component={ContactListTab}
        />
        <Route
          exact
          path={`${CONTACT_VIEW_ROUTE}/:id`}
          component={ContactListTab}
        />
        <Route
          exact
          path={`${CONTACT_MY_ACCOUNTS_VIEW_ROUTE}/:id`}
          component={ContactListTab}
        />
        <Route
          exact
          path={`${CONTACT_MY_ACCOUNTS_EDIT_ROUTE}/:id`}
          component={ContactListTab}
        />
        <Route
          component={SettingsTab}
        />
      </Switch>
    )
  }
}

export default withRouter(SettingsPage)