Browse Source

Re-order accounts when you change account name

master
Loëck Vézien 7 years ago
parent
commit
9df43a671d
No known key found for this signature in database GPG Key ID: CBCDCE384E853AC4
  1. 30
      src/components/modals/SettingsAccount.js
  2. 1
      src/reducers/settings.js

30
src/components/modals/SettingsAccount.js

@ -7,9 +7,11 @@ import { push } from 'react-router-redux'
import { MODAL_SETTINGS_ACCOUNT } from 'constants'
import type { MapStateToProps } from 'react-redux'
import type { Account } from 'types/common'
import { updateAccount, removeAccount } from 'actions/accounts'
import { updateOrderAccounts, updateAccount, removeAccount } from 'actions/accounts'
import { getOrderAccounts } from 'reducers/settings'
import { setDataModal, closeModal } from 'reducers/modals'
import Box from 'components/base/Box'
@ -27,18 +29,25 @@ type State = {
type Props = {
closeModal: Function,
updateAccount: Function,
orderAccounts: string,
push: Function,
removeAccount: Function,
setDataModal: Function,
push: Function,
updateAccount: Function,
updateOrderAccounts: Function,
}
const mapStateToProps: MapStateToProps<*, *, *> = state => ({
orderAccounts: getOrderAccounts(state),
})
const mapDispatchToProps = {
closeModal,
updateAccount,
push,
removeAccount,
setDataModal,
push,
updateAccount,
updateOrderAccounts,
}
const defaultState = {
@ -101,6 +110,7 @@ class SettingsAccount extends PureComponent<Props, State> {
updateAccount(account)
setDataModal(MODAL_SETTINGS_ACCOUNT, { account })
this.updateOrderAccounts()
this.setState({
editName: false,
@ -117,8 +127,8 @@ class SettingsAccount extends PureComponent<Props, State> {
updateAccount({ ...account, archived: true })
}
this.updateOrderAccounts()
closeModal(MODAL_SETTINGS_ACCOUNT)
push('/')
}
@ -127,6 +137,12 @@ class SettingsAccount extends PureComponent<Props, State> {
...defaultState,
})
updateOrderAccounts() {
const { updateOrderAccounts, orderAccounts } = this.props
updateOrderAccounts(orderAccounts)
}
render() {
const { editName, nameHovered } = this.state
@ -195,4 +211,4 @@ class SettingsAccount extends PureComponent<Props, State> {
}
}
export default connect(null, mapDispatchToProps)(SettingsAccount)
export default connect(mapStateToProps, mapDispatchToProps)(SettingsAccount)

1
src/reducers/settings.js

@ -29,5 +29,6 @@ const handlers: Object = {
export const hasPassword = (state: Object) => get(state.settings, 'password.state', false)
export const getLanguage = (state: Object) => get(state.settings, 'language', 'en')
export const getOrderAccounts = (state: Object) => get(state.settings, 'orderAccounts', 'balance')
export default handleActions(handlers, state)

Loading…
Cancel
Save