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 { MODAL_SETTINGS_ACCOUNT } from 'constants'
import type { MapStateToProps } from 'react-redux'
import type { Account } from 'types/common' 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 { setDataModal, closeModal } from 'reducers/modals'
import Box from 'components/base/Box' import Box from 'components/base/Box'
@ -27,18 +29,25 @@ type State = {
type Props = { type Props = {
closeModal: Function, closeModal: Function,
updateAccount: Function, orderAccounts: string,
push: Function,
removeAccount: Function, removeAccount: Function,
setDataModal: Function, setDataModal: Function,
push: Function, updateAccount: Function,
updateOrderAccounts: Function,
} }
const mapStateToProps: MapStateToProps<*, *, *> = state => ({
orderAccounts: getOrderAccounts(state),
})
const mapDispatchToProps = { const mapDispatchToProps = {
closeModal, closeModal,
updateAccount, push,
removeAccount, removeAccount,
setDataModal, setDataModal,
push, updateAccount,
updateOrderAccounts,
} }
const defaultState = { const defaultState = {
@ -101,6 +110,7 @@ class SettingsAccount extends PureComponent<Props, State> {
updateAccount(account) updateAccount(account)
setDataModal(MODAL_SETTINGS_ACCOUNT, { account }) setDataModal(MODAL_SETTINGS_ACCOUNT, { account })
this.updateOrderAccounts()
this.setState({ this.setState({
editName: false, editName: false,
@ -117,8 +127,8 @@ 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('/')
} }
@ -127,6 +137,12 @@ 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
@ -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 hasPassword = (state: Object) => get(state.settings, 'password.state', false)
export const getLanguage = (state: Object) => get(state.settings, 'language', 'en') 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) export default handleActions(handlers, state)

Loading…
Cancel
Save