|
@ -7,11 +7,9 @@ import { push } from 'react-router-redux' |
|
|
|
|
|
|
|
|
import { MODAL_SETTINGS_ACCOUNT } from 'constants' |
|
|
import { MODAL_SETTINGS_ACCOUNT } from 'constants' |
|
|
|
|
|
|
|
|
import type { MapStateToProps } from 'react-redux' |
|
|
|
|
|
import type { Account } from 'types/common' |
|
|
import type { Account } from 'types/common' |
|
|
|
|
|
|
|
|
import { updateOrderAccounts, updateAccount, removeAccount } from 'actions/accounts' |
|
|
import { updateAccount, removeAccount } from 'actions/accounts' |
|
|
import { getOrderAccounts } from 'reducers/settings' |
|
|
|
|
|
import { setDataModal, closeModal } from 'reducers/modals' |
|
|
import { setDataModal, closeModal } from 'reducers/modals' |
|
|
|
|
|
|
|
|
import Box from 'components/base/Box' |
|
|
import Box from 'components/base/Box' |
|
@ -22,37 +20,30 @@ import Text from 'components/base/Text' |
|
|
import Icon from 'components/base/Icon' |
|
|
import Icon from 'components/base/Icon' |
|
|
|
|
|
|
|
|
type State = { |
|
|
type State = { |
|
|
accountName: string, |
|
|
accountName: string | null, |
|
|
editName: boolean, |
|
|
editName: boolean, |
|
|
nameHovered: boolean, |
|
|
nameHovered: boolean, |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
type Props = { |
|
|
type Props = { |
|
|
closeModal: Function, |
|
|
closeModal: Function, |
|
|
orderAccounts: string, |
|
|
|
|
|
push: Function, |
|
|
push: Function, |
|
|
removeAccount: Function, |
|
|
removeAccount: Function, |
|
|
setDataModal: Function, |
|
|
setDataModal: Function, |
|
|
updateAccount: Function, |
|
|
updateAccount: Function, |
|
|
updateOrderAccounts: Function, |
|
|
|
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
const mapStateToProps: MapStateToProps<*, *, *> = state => ({ |
|
|
|
|
|
orderAccounts: getOrderAccounts(state), |
|
|
|
|
|
}) |
|
|
|
|
|
|
|
|
|
|
|
const mapDispatchToProps = { |
|
|
const mapDispatchToProps = { |
|
|
closeModal, |
|
|
closeModal, |
|
|
push, |
|
|
push, |
|
|
removeAccount, |
|
|
removeAccount, |
|
|
setDataModal, |
|
|
setDataModal, |
|
|
updateAccount, |
|
|
updateAccount, |
|
|
updateOrderAccounts, |
|
|
|
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
const defaultState = { |
|
|
const defaultState = { |
|
|
editName: false, |
|
|
editName: false, |
|
|
accountName: '', |
|
|
accountName: null, |
|
|
nameHovered: false, |
|
|
nameHovered: false, |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
@ -72,7 +63,7 @@ class SettingsAccount extends PureComponent<Props, State> { |
|
|
|
|
|
|
|
|
return { |
|
|
return { |
|
|
...account, |
|
|
...account, |
|
|
...(accountName !== '' |
|
|
...(accountName !== null |
|
|
? { |
|
|
? { |
|
|
name: accountName, |
|
|
name: accountName, |
|
|
} |
|
|
} |
|
@ -107,15 +98,17 @@ class SettingsAccount extends PureComponent<Props, State> { |
|
|
e.preventDefault() |
|
|
e.preventDefault() |
|
|
|
|
|
|
|
|
const { updateAccount, setDataModal } = this.props |
|
|
const { updateAccount, setDataModal } = this.props |
|
|
|
|
|
const { accountName } = this.state |
|
|
|
|
|
|
|
|
|
|
|
if (accountName !== '') { |
|
|
updateAccount(account) |
|
|
updateAccount(account) |
|
|
setDataModal(MODAL_SETTINGS_ACCOUNT, { account }) |
|
|
setDataModal(MODAL_SETTINGS_ACCOUNT, { account }) |
|
|
this.updateOrderAccounts() |
|
|
|
|
|
|
|
|
|
|
|
this.setState({ |
|
|
this.setState({ |
|
|
editName: false, |
|
|
editName: false, |
|
|
}) |
|
|
}) |
|
|
} |
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
handleArchiveAccount = (account: Account) => () => { |
|
|
handleArchiveAccount = (account: Account) => () => { |
|
|
const { push, closeModal, updateAccount, removeAccount } = this.props |
|
|
const { push, closeModal, updateAccount, removeAccount } = this.props |
|
@ -127,7 +120,6 @@ class SettingsAccount extends PureComponent<Props, State> { |
|
|
updateAccount({ ...account, archived: true }) |
|
|
updateAccount({ ...account, archived: true }) |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
this.updateOrderAccounts() |
|
|
|
|
|
closeModal(MODAL_SETTINGS_ACCOUNT) |
|
|
closeModal(MODAL_SETTINGS_ACCOUNT) |
|
|
push('/') |
|
|
push('/') |
|
|
} |
|
|
} |
|
@ -137,12 +129,6 @@ class SettingsAccount extends PureComponent<Props, State> { |
|
|
...defaultState, |
|
|
...defaultState, |
|
|
}) |
|
|
}) |
|
|
|
|
|
|
|
|
updateOrderAccounts() { |
|
|
|
|
|
const { updateOrderAccounts, orderAccounts } = this.props |
|
|
|
|
|
|
|
|
|
|
|
updateOrderAccounts(orderAccounts) |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
render() { |
|
|
render() { |
|
|
const { editName, nameHovered } = this.state |
|
|
const { editName, nameHovered } = this.state |
|
|
|
|
|
|
|
@ -211,4 +197,4 @@ class SettingsAccount extends PureComponent<Props, State> { |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
export default connect(mapStateToProps, mapDispatchToProps)(SettingsAccount) |
|
|
export default connect(null, mapDispatchToProps)(SettingsAccount) |
|
|