import React, { PureComponent } from 'react' import PropTypes from 'prop-types' import { Switch, Route, matchPath, withRouter } from 'react-router-dom' import { ENVIRONMENT_TYPE_POPUP } from '../../../../app/scripts/lib/enums' import { getEnvironmentType } from '../../../../app/scripts/lib/util' import TabBar from '../../components/app/tab-bar' import c from 'classnames' import SettingsTab from './settings-tab' import AdvancedTab from './advanced-tab' import InfoTab from './info-tab' import SecurityTab from './security-tab' import { DEFAULT_ROUTE, ADVANCED_ROUTE, SECURITY_ROUTE, GENERAL_ROUTE, ABOUT_US_ROUTE, SETTINGS_ROUTE, } from '../../helpers/constants/routes' const ROUTES_TO_I18N_KEYS = { [GENERAL_ROUTE]: 'general', [ADVANCED_ROUTE]: 'advanced', [SECURITY_ROUTE]: 'securityAndPrivacy', [ABOUT_US_ROUTE]: 'about', } class SettingsPage extends PureComponent { static propTypes = { location: PropTypes.object, history: PropTypes.object, t: PropTypes.func, } static contextTypes = { t: PropTypes.func, } isCurrentPath (pathname) { return this.props.location.pathname === pathname } render () { const { t } = this.context const { history, location } = this.props const pathnameI18nKey = ROUTES_TO_I18N_KEYS[location.pathname] const isPopupView = getEnvironmentType(location.href) === ENVIRONMENT_TYPE_POPUP return (
{ !this.isCurrentPath(SETTINGS_ROUTE) && (
history.push(SETTINGS_ROUTE)} /> ) }
{t(pathnameI18nKey && isPopupView ? pathnameI18nKey : 'settings')}
history.push(DEFAULT_ROUTE)} />
{ this.renderTabs() }
{ this.renderSubHeader() } { this.renderContent() }
) } renderSubHeader () { const { t } = this.context const { location: { pathname } } = this.props return (
{t(ROUTES_TO_I18N_KEYS[pathname] || 'general')}
) } renderTabs () { const { history, location } = this.props const { t } = this.context return ( { if (key === GENERAL_ROUTE && this.isCurrentPath(SETTINGS_ROUTE)) { return true } return matchPath(location.pathname, { path: key, exact: true }) }} onSelect={key => history.push(key)} /> ) } renderContent () { return ( ) } } export default withRouter(SettingsPage)