2018-09-12 02:32:37 +02:00
|
|
|
import React, { PureComponent } from 'react'
|
|
|
|
import PropTypes from 'prop-types'
|
2020-01-24 20:12:49 +01:00
|
|
|
import { Switch, Route, matchPath } from 'react-router-dom'
|
2020-03-01 11:14:16 +01:00
|
|
|
import classnames from 'classnames'
|
2020-08-18 21:18:25 +02:00
|
|
|
import TabBar from '../../components/app/tab-bar'
|
2019-03-25 17:13:23 +01:00
|
|
|
import {
|
2020-05-08 21:45:52 +02:00
|
|
|
ALERTS_ROUTE,
|
2019-03-25 17:13:23 +01:00
|
|
|
ADVANCED_ROUTE,
|
|
|
|
SECURITY_ROUTE,
|
|
|
|
GENERAL_ROUTE,
|
|
|
|
ABOUT_US_ROUTE,
|
|
|
|
SETTINGS_ROUTE,
|
2019-05-09 19:27:14 +02:00
|
|
|
NETWORKS_ROUTE,
|
2020-10-28 20:42:42 +01:00
|
|
|
NETWORKS_FORM_ROUTE,
|
2019-07-31 21:56:44 +02:00
|
|
|
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,
|
2019-03-25 17:13:23 +01:00
|
|
|
} from '../../helpers/constants/routes'
|
2020-08-18 21:18:25 +02:00
|
|
|
import SettingsTab from './settings-tab'
|
|
|
|
import AlertsTab from './alerts-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'
|
2019-03-25 17:13:23 +01:00
|
|
|
|
2019-04-29 08:18:03 +02:00
|
|
|
class SettingsPage extends PureComponent {
|
2018-09-12 02:32:37 +02:00
|
|
|
static propTypes = {
|
2019-07-31 21:56:44 +02:00
|
|
|
addressName: PropTypes.string,
|
|
|
|
backRoute: PropTypes.string,
|
|
|
|
currentPath: PropTypes.string,
|
2018-09-12 02:32:37 +02:00
|
|
|
history: PropTypes.object,
|
2019-07-31 21:56:44 +02:00
|
|
|
isAddressEntryPage: PropTypes.bool,
|
|
|
|
isPopupView: PropTypes.bool,
|
|
|
|
pathnameI18nKey: PropTypes.string,
|
|
|
|
initialBreadCrumbRoute: PropTypes.string,
|
|
|
|
breadCrumbTextKey: PropTypes.string,
|
|
|
|
initialBreadCrumbKey: PropTypes.string,
|
2020-06-01 19:54:32 +02:00
|
|
|
mostRecentOverviewPage: PropTypes.string.isRequired,
|
2018-09-12 02:32:37 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static contextTypes = {
|
|
|
|
t: PropTypes.func,
|
|
|
|
}
|
|
|
|
|
|
|
|
render () {
|
2020-06-01 19:54:32 +02:00
|
|
|
const { history, backRoute, currentPath, mostRecentOverviewPage } = this.props
|
2019-03-25 17:13:23 +01:00
|
|
|
|
2018-09-12 02:32:37 +02:00
|
|
|
return (
|
2019-03-25 17:13:23 +01:00
|
|
|
<div
|
2020-03-01 11:14:16 +01:00
|
|
|
className={classnames('main-container settings-page', {
|
2019-07-31 21:56:44 +02:00
|
|
|
'settings-page--selected': currentPath !== SETTINGS_ROUTE,
|
2019-03-25 17:13:23 +01:00
|
|
|
})}
|
|
|
|
>
|
2018-09-12 02:32:37 +02:00
|
|
|
<div className="settings-page__header">
|
2019-03-25 17:13:23 +01:00
|
|
|
{
|
2020-10-27 22:55:09 +01:00
|
|
|
currentPath !== SETTINGS_ROUTE && (
|
2019-03-25 17:13:23 +01:00
|
|
|
<div
|
|
|
|
className="settings-page__back-button"
|
2019-07-31 21:56:44 +02:00
|
|
|
onClick={() => history.push(backRoute)}
|
2019-03-25 17:13:23 +01:00
|
|
|
/>
|
|
|
|
)
|
|
|
|
}
|
2019-07-31 21:56:44 +02:00
|
|
|
{ this.renderTitle() }
|
2018-09-12 02:32:37 +02:00
|
|
|
<div
|
|
|
|
className="settings-page__close-button"
|
2020-06-01 19:54:32 +02:00
|
|
|
onClick={() => history.push(mostRecentOverviewPage)}
|
2018-09-12 02:32:37 +02:00
|
|
|
/>
|
|
|
|
</div>
|
2019-03-25 17:13:23 +01:00
|
|
|
<div className="settings-page__content">
|
|
|
|
<div className="settings-page__content__tabs">
|
|
|
|
{ this.renderTabs() }
|
|
|
|
</div>
|
|
|
|
<div className="settings-page__content__modules">
|
2019-04-29 08:18:03 +02:00
|
|
|
{ this.renderSubHeader() }
|
2019-03-25 17:13:23 +01:00
|
|
|
{ this.renderContent() }
|
|
|
|
</div>
|
|
|
|
</div>
|
2018-09-12 02:32:37 +02:00
|
|
|
</div>
|
|
|
|
)
|
|
|
|
}
|
2019-03-25 17:13:23 +01:00
|
|
|
|
2019-07-31 21:56:44 +02:00
|
|
|
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>
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
2019-04-29 08:18:03 +02:00
|
|
|
renderSubHeader () {
|
|
|
|
const { t } = this.context
|
2019-07-31 21:56:44 +02:00
|
|
|
const {
|
|
|
|
currentPath,
|
|
|
|
isPopupView,
|
|
|
|
isAddressEntryPage,
|
|
|
|
pathnameI18nKey,
|
|
|
|
addressName,
|
|
|
|
initialBreadCrumbRoute,
|
|
|
|
breadCrumbTextKey,
|
|
|
|
history,
|
|
|
|
initialBreadCrumbKey,
|
|
|
|
} = this.props
|
|
|
|
|
|
|
|
let subheaderText
|
2019-04-29 08:18:03 +02:00
|
|
|
|
2019-07-31 21:56:44 +02:00
|
|
|
if (isPopupView && isAddressEntryPage) {
|
|
|
|
subheaderText = t('settings')
|
|
|
|
} else if (initialBreadCrumbKey) {
|
|
|
|
subheaderText = t(initialBreadCrumbKey)
|
|
|
|
} else {
|
|
|
|
subheaderText = t(pathnameI18nKey || 'general')
|
|
|
|
}
|
|
|
|
|
|
|
|
return currentPath !== NETWORKS_ROUTE && (
|
2019-04-29 08:18:03 +02:00
|
|
|
<div className="settings-page__subheader">
|
2019-07-31 21:56:44 +02:00
|
|
|
<div
|
2020-03-01 11:14:16 +01:00
|
|
|
className={classnames({ 'settings-page__subheader--link': initialBreadCrumbRoute })}
|
2019-07-31 21:56:44 +02:00
|
|
|
onClick={() => initialBreadCrumbRoute && history.push(initialBreadCrumbRoute)}
|
2019-12-03 17:35:44 +01:00
|
|
|
>
|
|
|
|
{subheaderText}
|
|
|
|
</div>
|
|
|
|
{breadCrumbTextKey && (
|
|
|
|
<div className="settings-page__subheader--break">
|
|
|
|
<span>{' > '}</span>{t(breadCrumbTextKey)}
|
|
|
|
</div>
|
|
|
|
)}
|
|
|
|
{isAddressEntryPage && (
|
|
|
|
<div className="settings-page__subheader--break">
|
|
|
|
<span>{' > '}</span>{addressName}
|
|
|
|
</div>
|
|
|
|
)}
|
2019-04-29 08:18:03 +02:00
|
|
|
</div>
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
2019-03-25 17:13:23 +01:00
|
|
|
renderTabs () {
|
2019-07-31 21:56:44 +02:00
|
|
|
const { history, currentPath } = this.props
|
2019-03-25 17:13:23 +01:00
|
|
|
const { t } = this.context
|
|
|
|
|
|
|
|
return (
|
|
|
|
<TabBar
|
|
|
|
tabs={[
|
|
|
|
{ content: t('general'), description: t('generalSettingsDescription'), key: GENERAL_ROUTE },
|
|
|
|
{ content: t('advanced'), description: t('advancedSettingsDescription'), key: ADVANCED_ROUTE },
|
2019-08-15 15:03:36 +02:00
|
|
|
{ content: t('contacts'), description: t('contactsSettingsDescription'), key: CONTACT_LIST_ROUTE },
|
2019-03-25 17:13:23 +01:00
|
|
|
{ content: t('securityAndPrivacy'), description: t('securitySettingsDescription'), key: SECURITY_ROUTE },
|
2020-05-08 21:45:52 +02:00
|
|
|
{ content: t('alerts'), description: t('alertsSettingsDescription'), key: ALERTS_ROUTE },
|
2019-05-09 19:27:14 +02:00
|
|
|
{ content: t('networks'), description: t('networkSettingsDescription'), key: NETWORKS_ROUTE },
|
2019-03-29 17:24:03 +01:00
|
|
|
{ content: t('about'), description: t('aboutSettingsDescription'), key: ABOUT_US_ROUTE },
|
2019-03-25 17:13:23 +01:00
|
|
|
]}
|
2020-02-15 21:34:12 +01:00
|
|
|
isActive={(key) => {
|
2019-07-31 21:56:44 +02:00
|
|
|
if (key === GENERAL_ROUTE && currentPath === SETTINGS_ROUTE) {
|
2019-03-25 17:13:23 +01:00
|
|
|
return true
|
|
|
|
}
|
2019-07-31 21:56:44 +02:00
|
|
|
return matchPath(currentPath, { path: key, exact: true })
|
2019-03-25 17:13:23 +01:00
|
|
|
}}
|
2020-02-15 21:34:12 +01:00
|
|
|
onSelect={(key) => history.push(key)}
|
2019-03-25 17:13:23 +01:00
|
|
|
/>
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
renderContent () {
|
|
|
|
return (
|
|
|
|
<Switch>
|
|
|
|
<Route
|
|
|
|
exact
|
|
|
|
path={GENERAL_ROUTE}
|
|
|
|
component={SettingsTab}
|
|
|
|
/>
|
|
|
|
<Route
|
|
|
|
exact
|
|
|
|
path={ABOUT_US_ROUTE}
|
|
|
|
component={InfoTab}
|
|
|
|
/>
|
|
|
|
<Route
|
|
|
|
exact
|
|
|
|
path={ADVANCED_ROUTE}
|
|
|
|
component={AdvancedTab}
|
|
|
|
/>
|
2020-05-08 21:45:52 +02:00
|
|
|
<Route
|
|
|
|
exact
|
|
|
|
path={ALERTS_ROUTE}
|
|
|
|
component={AlertsTab}
|
|
|
|
/>
|
2019-05-09 19:27:14 +02:00
|
|
|
<Route
|
|
|
|
exact
|
|
|
|
path={NETWORKS_ROUTE}
|
|
|
|
component={NetworksTab}
|
|
|
|
/>
|
2020-10-28 20:42:42 +01:00
|
|
|
<Route
|
|
|
|
exact
|
|
|
|
path={NETWORKS_FORM_ROUTE}
|
|
|
|
component={NetworksTab}
|
|
|
|
/>
|
2019-03-25 17:13:23 +01:00
|
|
|
<Route
|
|
|
|
exact
|
|
|
|
path={SECURITY_ROUTE}
|
|
|
|
component={SecurityTab}
|
|
|
|
/>
|
2019-07-31 21:56:44 +02:00
|
|
|
<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}
|
|
|
|
/>
|
2019-03-25 17:13:23 +01:00
|
|
|
<Route
|
|
|
|
component={SettingsTab}
|
|
|
|
/>
|
|
|
|
</Switch>
|
|
|
|
)
|
|
|
|
}
|
2018-09-12 02:32:37 +02:00
|
|
|
}
|
2019-04-29 08:18:03 +02:00
|
|
|
|
2020-01-24 20:12:49 +01:00
|
|
|
export default SettingsPage
|