// @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)