// @flow import moment from 'moment'; import * as React from 'react'; import { Component, Text, View } from 'reactxp'; import { Button, CellButton, RedButton, Label, SubText } from './styled'; import { Layout, Container } from './Layout'; import CustomScrollbars from './CustomScrollbars'; import styles from './SettingsStyles'; import Img from './Img'; import type { AccountReduxState } from '../redux/account/reducers'; import type { SettingsReduxState } from '../redux/settings/reducers'; export type SettingsProps = { account: AccountReduxState, settings: SettingsReduxState, version: string, onQuit: () => void, onClose: () => void, onViewAccount: () => void, onViewSupport: () => void, onViewPreferences: () => void, onViewAdvancedSettings: () => void, onExternalLink: (type: string) => void, }; export default class Settings extends Component { render() { return ( Settings {this._renderTopButtons()} {this._renderMiddleButtons()} {this._renderBottomButtons()} {this._renderQuitButton()} ); } _renderTopButtons() { const isLoggedIn = this.props.account.status === 'ok'; if (!isLoggedIn) { return null; } let isOutOfTime = false, formattedExpiry = ''; const expiryIso = this.props.account.expiry; if (isLoggedIn && expiryIso) { const expiry = moment(this.props.account.expiry); isOutOfTime = expiry.isSameOrBefore(moment()); formattedExpiry = (expiry.fromNow(true) + ' left').toUpperCase(); } return ( {isOutOfTime ? ( OUT OF TIME ) : ( {formattedExpiry} )} ); } _renderMiddleButtons() { return ( {this._formattedVersion()} ); } _formattedVersion() { // the version in package.json has to be semver, but we use a YEAR.release-channel // version scheme. in package.json we thus have to write YEAR.release.X-channel and // this function is responsible for removing .X part. return this.props.version .replace('.0-', '-') // remove the .0 in 2018.1.0-beta9 .replace(/\.0$/, ''); // remove the .0 in 2018.1.0 } _renderBottomButtons() { return ( ); } _renderQuitButton() { return ( ); } }