diff --git a/src/components/SettingsPage/Display.js b/src/components/SettingsPage/Display.js deleted file mode 100644 index db3f7dc6..00000000 --- a/src/components/SettingsPage/Display.js +++ /dev/null @@ -1,98 +0,0 @@ -// @flow - -import React, { PureComponent } from 'react' - -import type { SettingsDisplay, T } from 'types/common' - -import Box, { Card } from 'components/base/Box' -import Button from 'components/base/Button' -import Label from 'components/base/Label' -import Select from 'components/base/Select' - -type InputValue = SettingsDisplay - -type Props = { - t: T, - settings: SettingsDisplay, - onSaveSettings: Function, -} - -type State = { - inputValue: InputValue, -} - -class TabProfile extends PureComponent { - state = { - inputValue: { - language: this.props.settings.language, - }, - } - - getDatas() { - const { t } = this.props - - return { - languages: [ - { - key: 'en', - name: t('language:en'), - }, - { - key: 'fr', - name: t('language:fr'), - }, - ], - } - } - - handleChangeInput = (key: $Keys) => (value: $Values) => - this.setState(prev => ({ - inputValue: { - ...prev.inputValue, - [key]: value, - }, - })) - - handleSubmit = (e: SyntheticEvent) => { - e.preventDefault() - - const { onSaveSettings } = this.props - const { inputValue } = this.state - - onSaveSettings({ - ...inputValue, - }) - } - - render() { - const { t } = this.props - const { inputValue } = this.state - - const { languages } = this.getDatas() - - const currentLanguage = languages.find(l => l.key === inputValue.language) - - return ( -
- - - - this.handleChangeInput('counterValue')(item.key)} - renderSelected={item => item && item.name} - value={currentCounterValues} - items={counterValues} - /> - - - - - -
- ) - } -} - -export default TabProfile diff --git a/src/components/SettingsPage/Profile.js b/src/components/SettingsPage/Profile.js deleted file mode 100644 index 1b7b50fe..00000000 --- a/src/components/SettingsPage/Profile.js +++ /dev/null @@ -1,124 +0,0 @@ -// @flow - -import React, { PureComponent } from 'react' -import { connect } from 'react-redux' -import bcrypt from 'bcryptjs' - -import get from 'lodash/get' -import set from 'lodash/set' - -import { setEncryptionKey } from 'helpers/db' - -import type { SettingsProfile, T } from 'types/common' - -import { unlock } from 'reducers/application' - -import Box, { Card } from 'components/base/Box' -import Input from 'components/base/Input' -import CheckBox from 'components/base/CheckBox' -import Button from 'components/base/Button' -import Label from 'components/base/Label' - -type InputValue = SettingsProfile - -type Props = { - t: T, - settings: SettingsProfile, - onSaveSettings: Function, - unlock: Function, -} -type State = { - inputValue: InputValue, -} - -const mapDispatchToProps = { - unlock, -} - -class TabProfile extends PureComponent { - state = { - inputValue: { - password: { - ...this.props.settings.password, - value: undefined, - }, - }, - } - - handleChangeInput = (key: string) => (value: $Values) => - this.setState(prev => ({ - inputValue: { - ...set(prev.inputValue, key, value), - }, - })) - - handleSubmit = (e: SyntheticEvent) => { - e.preventDefault() - - const { onSaveSettings, unlock } = this.props - const { inputValue } = this.state - - const settings = { - ...inputValue, - password: { - ...inputValue.password, - value: '', - }, - } - - const password = get(inputValue, 'password', {}) - - if (password.state === true && password.value.trim() !== '') { - settings.password.value = bcrypt.hashSync(password.value, 8) - setEncryptionKey('accounts', password.value) - } else { - setEncryptionKey('accounts', undefined) - } - - unlock() - - onSaveSettings(settings) - } - - render() { - const { t } = this.props - const { inputValue } = this.state - - const isPasswordChecked = get(inputValue, 'password.state', false) - return ( -
- - - {get(inputValue, 'password.state') === true && ( - - - - - )} - - - - -
- ) - } -} - -export default connect(null, mapDispatchToProps)(TabProfile) diff --git a/src/components/SettingsPage/SettingsSection.js b/src/components/SettingsPage/SettingsSection.js new file mode 100644 index 00000000..d555dc5a --- /dev/null +++ b/src/components/SettingsPage/SettingsSection.js @@ -0,0 +1,95 @@ +// @flow + +import React from 'react' +import styled from 'styled-components' + +import { rgba } from 'styles/helpers' + +import Box, { Card } from 'components/base/Box' + +export const SettingsSection = styled(Card).attrs({ p: 0 })`` + +const SettingsSectionHeaderContainer = styled(Box).attrs({ + p: 4, + horizontal: true, + align: 'center', +})` + border-bottom: 1px solid ${p => p.theme.colors.lightFog}; + line-height: normal; +` + +const RoundIconContainer = styled(Box).attrs({ + align: 'center', + justify: 'center', + bg: p => rgba(p.theme.colors.wallet, 0.2), + color: 'wallet', +})` + height: 30px; + width: 30px; + border-radius: 50%; +` + +export const SettingsSectionBody = styled(Box)` + > * + * { + border-top: 1px solid ${p => p.theme.colors.lightFog}; + } +` + +export function SettingsSectionHeader({ + title, + desc, + icon, +}: { + title: string, + desc: string, + icon: any, +}) { + return ( + + {icon} + + + {title} + + + {desc} + + + + ) +} + +const SettingsSectionRowContainer = styled(Box).attrs({ p: 4, horizontal: true, align: 'center' })` + cursor: ${p => (p.onClick ? 'pointer' : '')}; +` + +export function SettingsSectionRow({ + title, + desc, + children, + onClick, +}: { + title: string, + desc: string, + children?: any, + onClick?: ?Function, +}) { + return ( + + + + {title} + + + {desc} + + + {children} + + ) +} + +SettingsSectionRow.defaultProps = { + children: null, + onClick: null, +} diff --git a/src/components/SettingsPage/index.js b/src/components/SettingsPage/index.js index cfcc4bbf..3c8bd4b6 100644 --- a/src/components/SettingsPage/index.js +++ b/src/components/SettingsPage/index.js @@ -4,7 +4,6 @@ import React, { PureComponent } from 'react' import { compose } from 'redux' import { connect } from 'react-redux' import { translate } from 'react-i18next' -import moment from 'moment' import type { Settings, T } from 'types/common' import type { SaveSettings } from 'actions/settings' @@ -16,10 +15,10 @@ import { fetchCounterValues } from 'actions/counterValues' import Pills from 'components/base/Pills' import Box from 'components/base/Box' -import TabDisplay from './Display' -import TabProfile from './Profile' -import TabTools from './Tools' -import TabMoney from './Money' +import SectionDisplay from './sections/Display' +import SectionCurrencies from './sections/Currencies' +import SectionProfile from './sections/Profile' +import SectionAbout from './sections/About' const mapStateToProps = state => ({ settings: state.settings, @@ -55,68 +54,45 @@ class SettingsPage extends PureComponent { } handleSaveSettings = newSettings => { - const { fetchCounterValues, saveSettings, i18n, settings } = this.props + const { fetchCounterValues, saveSettings, settings } = this.props saveSettings(newSettings) - if (newSettings.language !== settings.language) { - i18n.changeLanguage(newSettings.language) - moment.locale(newSettings.language) - } - if (newSettings.counterValue !== settings.counterValue) { fetchCounterValues() } } render() { - const { settings, t } = this.props + const { settings, t, i18n, saveSettings } = this.props const { tab } = this.state const props = { t, settings, - onSaveSettings: this.handleSaveSettings, + saveSettings, } this._items = [ { key: 'display', label: t('settings:tabs.display'), - value: () => , - }, - { - key: 'money', - label: t('settings:tabs.money'), - value: () => , - }, - { - key: 'material', - isDisabled: true, - label: t('settings:tabs.material'), - value: () =>
{'Matériel'}
, + value: () => , }, { - key: 'app', - isDisabled: true, - label: t('settings:tabs.app'), - value: () =>
{'App (beta)'}
, - }, - { - key: 'tools', - label: t('settings:tabs.tools'), - value: () => , - }, - { - key: 'blockchain', - isDisabled: true, - label: t('settings:tabs.blockchain'), - value: () =>
{'Blockchain'}
, + key: 'currencies', + label: t('settings:tabs.currencies'), + value: () => , }, { key: 'profile', label: t('settings:tabs.profile'), - value: () => , + value: () => , + }, + { + key: 'about', + label: t('settings:tabs.about'), + value: () => , }, ] @@ -124,10 +100,10 @@ class SettingsPage extends PureComponent { return ( - + {t('settings:title')} - + {item.value && item.value()} ) diff --git a/src/components/SettingsPage/sections/About.js b/src/components/SettingsPage/sections/About.js new file mode 100644 index 00000000..e8fba224 --- /dev/null +++ b/src/components/SettingsPage/sections/About.js @@ -0,0 +1,62 @@ +// @flow + +import React, { PureComponent } from 'react' +import { shell } from 'electron' + +import type { T } from 'types/common' + +import IconHelp from 'icons/Help' +import IconChevronRight from 'icons/ChevronRight' + +import { + SettingsSection as Section, + SettingsSectionHeader as Header, + SettingsSectionBody as Body, + SettingsSectionRow as Row, +} from '../SettingsSection' + +type Props = { + t: T, +} + +class SectionAbout extends PureComponent { + handleOpenLink = (url: string) => () => shell.openExternal(url) + + render() { + const { t } = this.props + return ( +
+
} + title={t('settings:tabs.about')} + desc="Lorem ipsum dolor sit amet" + /> + + + + + + + + + + + +
+ ) + } +} + +export default SectionAbout diff --git a/src/components/SettingsPage/sections/Currencies.js b/src/components/SettingsPage/sections/Currencies.js new file mode 100644 index 00000000..4a6590a4 --- /dev/null +++ b/src/components/SettingsPage/sections/Currencies.js @@ -0,0 +1,53 @@ +// @flow + +import React, { PureComponent } from 'react' + +import type { T } from 'types/common' + +import IconCurrencies from 'icons/Currencies' + +import { + SettingsSection as Section, + SettingsSectionHeader as Header, + SettingsSectionBody as Body, + SettingsSectionRow as Row, +} from '../SettingsSection' + +type Props = { + t: T, +} + +class TabCurrencies extends PureComponent { + render() { + const { t } = this.props + return ( +
+
} + title={t('settings:tabs.currencies')} + desc="Lorem ipsum dolor sit amet" + /> + + + + + + +
+ ) + } +} + +export default TabCurrencies diff --git a/src/components/SettingsPage/sections/Display.js b/src/components/SettingsPage/sections/Display.js new file mode 100644 index 00000000..d2373463 --- /dev/null +++ b/src/components/SettingsPage/sections/Display.js @@ -0,0 +1,93 @@ +// @flow + +import React, { PureComponent } from 'react' +import moment from 'moment' + +import type { Settings, T } from 'types/common' + +import Select from 'components/base/Select' +import IconDisplay from 'icons/Display' + +import { + SettingsSection as Section, + SettingsSectionHeader as Header, + SettingsSectionBody as Body, + SettingsSectionRow as Row, +} from '../SettingsSection' + +type Props = { + t: T, + settings: Settings, + saveSettings: Function, + i18n: Object, +} + +type State = { + cachedLanguageKey: string, +} + +class TabProfile extends PureComponent { + state = { + cachedLanguageKey: this.props.settings.language, + } + + getDatas() { + const { t } = this.props + return { + languages: [{ key: 'en', name: t('language:en') }, { key: 'fr', name: t('language:fr') }], + } + } + + handleChangeLanguage = (languageKey: string) => { + const { i18n, saveSettings } = this.props + this.setState({ cachedLanguageKey: languageKey }) + window.requestIdleCallback(() => { + i18n.changeLanguage(languageKey) + moment.locale(languageKey) + saveSettings({ language: languageKey }) + }) + } + + render() { + const { t } = this.props + const { cachedLanguageKey } = this.state + const { languages } = this.getDatas() + const currentLanguage = languages.find(l => l.key === cachedLanguageKey) + + return ( +
+
} + title={t('settings:tabs.display')} + desc="Lorem ipsum dolor sit amet" + /> + + + {'-'} + + +