diff --git a/src/components/DashboardPage/index.js b/src/components/DashboardPage/index.js index 05278af2..48d8d3b5 100644 --- a/src/components/DashboardPage/index.js +++ b/src/components/DashboardPage/index.js @@ -13,32 +13,44 @@ import sortBy from 'lodash/sortBy' import takeRight from 'lodash/takeRight' import type { MapStateToProps } from 'react-redux' -import type { Accounts } from 'types/common' +import type { Accounts, T } from 'types/common' import { space } from 'styles/theme' import { getVisibleAccounts } from 'reducers/accounts' +import { getOrderAccounts } from 'reducers/settings' + +import { updateOrderAccounts } from 'actions/accounts' +import { saveSettings } from 'actions/settings' import { AreaChart } from 'components/base/Chart' import Box, { Card } from 'components/base/Box' import Pills from 'components/base/Pills' import Text from 'components/base/Text' import TransactionsList from 'components/TransactionsList' +import DropDown from 'components/base/DropDown' import AccountCard from './AccountCard' import BalanceInfos from './BalanceInfos' const mapStateToProps: MapStateToProps<*, *, *> = state => ({ accounts: getVisibleAccounts(state), + orderAccounts: getOrderAccounts(state), }) const mapDispatchToProps = { push, + updateOrderAccounts, + saveSettings, } type Props = { accounts: Accounts, push: Function, + t: T, + updateOrderAccounts: Function, + saveSettings: Function, + orderAccounts: string, } type State = { @@ -108,6 +120,12 @@ class DashboardPage extends PureComponent { return chunk(listAccounts, ACCOUNTS_BY_LINE) } + setAccountOrder = order => { + const { updateOrderAccounts, saveSettings } = this.props + updateOrderAccounts(order) + saveSettings({ orderAccounts: order }) + } + generateFakeDatas() { const { accounts } = this.props return accounts.map(() => [...Array(25).keys()].map(v => generateFakeData(v + 1))) @@ -136,11 +154,26 @@ class DashboardPage extends PureComponent { _timeout = undefined render() { - const { push, accounts } = this.props + const { push, accounts, t, orderAccounts } = this.props const { selectedTime, fakeDatas } = this.state const totalAccounts = accounts.length + const sortItems = [ + { + key: 'name', + label: t('orderAccounts.name'), + }, + { + key: 'balance', + label: t('orderAccounts.balance'), + }, + { + key: 'type', + label: t('orderAccounts.type'), + }, + ] + return ( @@ -195,9 +228,24 @@ class DashboardPage extends PureComponent { - - {'Accounts'} - + + + {'Accounts'} + + + + {'Sort by'} + + this.setAccountOrder(item.key)} + items={sortItems} + ff="Open Sans|SemiBold" + fontSize={4} + > + {t(`orderAccounts.${orderAccounts}`)} + + + {this.getAccountsChunk().map((accountsByLine, i) => ( { state = { inputValue: { language: this.props.settings.language, - orderAccounts: this.props.settings.orderAccounts, + orderAccounts: '', }, } @@ -43,20 +44,6 @@ class TabProfile extends PureComponent { name: t('language.fr'), }, ], - orderAccounts: [ - { - key: 'name', - name: t('orderAccounts.name'), - }, - { - key: 'balance', - name: t('orderAccounts.balance'), - }, - { - key: 'type', - name: t('orderAccounts.type'), - }, - ], } } @@ -83,10 +70,9 @@ class TabProfile extends PureComponent { const { t } = this.props const { inputValue } = this.state - const { languages, orderAccounts } = this.getDatas() + const { languages } = this.getDatas() const currentLanguage = languages.find(l => l.key === inputValue.language) - const currentOrderAccounts = orderAccounts.find(l => l.key === inputValue.orderAccounts) return (
@@ -100,15 +86,6 @@ class TabProfile extends PureComponent { items={languages} /> - - -