From 7dfa280bee47b4af1cd0b63f9ff71f865c385470 Mon Sep 17 00:00:00 2001 From: "a.bouhuolia" Date: Sun, 24 Oct 2021 17:34:00 +0200 Subject: [PATCH] feat: cashflow service. --- src/components/BankAccounts/index.js | 6 +- src/components/IntersectionObserver/index.js | 5 +- src/containers/Accounts/utils.js | 2 - .../AccountTransactionsDataTable.js | 37 +++++++- .../AccountTransactions/components.js | 8 +- .../withCashflowAccounts.js | 15 +++ .../withCashflowAccountsTableActions.js | 15 +++ .../CashFlowAccountsActionsBar.js | 31 +++--- .../CashFlowAccounts/CashFlowAccountsList.js | 34 +++++-- .../CashFlowAccountsProvider.js | 7 +- .../CashFlowAccounts/CashflowAccountsGrid.js | 94 ++++++++++++++++++- .../CashFlow/CashFlowAccounts/utils.js | 11 +++ .../CashflowAccounts.actions.js | 21 +++++ .../CashflowAccounts.reducer.js | 31 ++++++ .../CashflowAccounts.selectors.js | 19 ++++ .../CashflowAccounts.types.js | 5 + src/store/reducers.js | 2 + src/store/types.js | 2 + src/style/components/DataTable/DataTable.scss | 12 +-- 19 files changed, 307 insertions(+), 50 deletions(-) create mode 100644 src/containers/CashFlow/AccountTransactions/withCashflowAccounts.js create mode 100644 src/containers/CashFlow/AccountTransactions/withCashflowAccountsTableActions.js create mode 100644 src/containers/CashFlow/CashFlowAccounts/utils.js create mode 100644 src/store/CashflowAccounts/CashflowAccounts.actions.js create mode 100644 src/store/CashflowAccounts/CashflowAccounts.reducer.js create mode 100644 src/store/CashflowAccounts/CashflowAccounts.selectors.js create mode 100644 src/store/CashflowAccounts/CashflowAccounts.types.js diff --git a/src/components/BankAccounts/index.js b/src/components/BankAccounts/index.js index 13a3f928d..068456b3b 100644 --- a/src/components/BankAccounts/index.js +++ b/src/components/BankAccounts/index.js @@ -141,14 +141,14 @@ function BankAccountBalance({ amount, loading }) { const ACCOUNT_TYPE = { CASH: 'cash', + BANK: 'bank', CREDIT_CARD: 'credit-card', - BANK_ACCOUNT: 'bank-account', }; const ACCOUNT_TYPE_PAIR_ICON = { [ACCOUNT_TYPE.CASH]: 'payments', [ACCOUNT_TYPE.CREDIT_CARD]: 'credit-card', - [ACCOUNT_TYPE.BANK_ACCOUNT]: 'account-balance', + [ACCOUNT_TYPE.BANK]: 'account-balance', }; function BankAccountTypeIcon({ type }) { @@ -159,7 +159,7 @@ function BankAccountTypeIcon({ type }) { } return ( - + ); } diff --git a/src/components/IntersectionObserver/index.js b/src/components/IntersectionObserver/index.js index df91bc9a6..c1f01cc2e 100644 --- a/src/components/IntersectionObserver/index.js +++ b/src/components/IntersectionObserver/index.js @@ -16,7 +16,10 @@ export function IntersectionObserver({ onIntersect }) { }); return ( -
+
Load Newer
); diff --git a/src/containers/Accounts/utils.js b/src/containers/Accounts/utils.js index 0fa98ec84..926d99e69 100644 --- a/src/containers/Accounts/utils.js +++ b/src/containers/Accounts/utils.js @@ -1,9 +1,7 @@ import React from 'react'; import { Intent, Tag } from '@blueprintjs/core'; import intl from 'react-intl-universal'; -import clsx from 'classnames'; -import { CLASSES } from '../../common/classes'; import { If, AppToaster } from 'components'; import { NormalCell, BalanceCell } from './components'; import { transformTableStateToQuery, isBlank } from 'utils'; diff --git a/src/containers/CashFlow/AccountTransactions/AccountTransactionsDataTable.js b/src/containers/CashFlow/AccountTransactions/AccountTransactionsDataTable.js index 5b0f8e9aa..56e2a3d06 100644 --- a/src/containers/CashFlow/AccountTransactions/AccountTransactionsDataTable.js +++ b/src/containers/CashFlow/AccountTransactions/AccountTransactionsDataTable.js @@ -1,4 +1,5 @@ import React from 'react'; +import styled from 'styled-components'; import { DataTable, TableFastCell } from 'components'; import { TABLES } from 'common/tables'; @@ -36,14 +37,13 @@ function AccountTransactionsDataTable({ useMemorizedColumnsWidths(TABLES.CASHFLOW_Transactions); return ( - ); @@ -69,3 +69,30 @@ export default compose( cashflowTansactionsTableSize: cashflowTransactionsSettings?.tableSize, })), )(AccountTransactionsDataTable); + +const DashboardConstrantTable = styled(DataTable)` + .table .thead { + .th { + border-bottom-color: #666; + border-top-color: #666; + background: #fff; + } + } +`; + +const CashflowTransactionsTable = styled(DashboardConstrantTable)` + .table .tbody { + + .tbody-inner .tr.no-results { + .td { + padding: 3rem 0; + font-size: 16px; + color: #888; + font-weight: 400; + border-bottom: 0; + } + } + } +`; + +const DashboardRegularTable = styled(DataTable)``; diff --git a/src/containers/CashFlow/AccountTransactions/components.js b/src/containers/CashFlow/AccountTransactions/components.js index a08aa905c..2caa032ac 100644 --- a/src/containers/CashFlow/AccountTransactions/components.js +++ b/src/containers/CashFlow/AccountTransactions/components.js @@ -47,7 +47,7 @@ export function useAccountTransactionsColumns() { width: 110, className: 'deposit', textOverview: true, - align: 'right' + align: 'right', }, { id: 'withdrawal', @@ -65,7 +65,7 @@ export function useAccountTransactionsColumns() { className: 'running_balance', width: 150, textOverview: true, - align: 'right' + align: 'right', }, ], [], @@ -76,7 +76,7 @@ export function useAccountTransactionsColumns() { * Account transactions progress bar. */ export function AccountTransactionsProgressBar() { - const { isCashFlowTransactionsLoading } = useAccountTransactionsContext(); + const { isCashFlowTransactionsFetching } = useAccountTransactionsContext(); - return isCashFlowTransactionsLoading ? : null; + return isCashFlowTransactionsFetching ? : null; } diff --git a/src/containers/CashFlow/AccountTransactions/withCashflowAccounts.js b/src/containers/CashFlow/AccountTransactions/withCashflowAccounts.js new file mode 100644 index 000000000..df4d74c34 --- /dev/null +++ b/src/containers/CashFlow/AccountTransactions/withCashflowAccounts.js @@ -0,0 +1,15 @@ +import { connect } from 'react-redux'; +import { getCashflowAccountsTableStateFactory } from 'store/CashflowAccounts/CashflowAccounts.selectors'; + +export default (mapState) => { + const getCashflowAccountsTableState = getCashflowAccountsTableStateFactory(); + + const mapStateToProps = (state, props) => { + const mapped = { + cashflowAccountsTableState: getCashflowAccountsTableState(state, props), + }; + return mapState ? mapState(mapped, state, props) : mapped; + }; + + return connect(mapStateToProps); +}; diff --git a/src/containers/CashFlow/AccountTransactions/withCashflowAccountsTableActions.js b/src/containers/CashFlow/AccountTransactions/withCashflowAccountsTableActions.js new file mode 100644 index 000000000..c9770b367 --- /dev/null +++ b/src/containers/CashFlow/AccountTransactions/withCashflowAccountsTableActions.js @@ -0,0 +1,15 @@ +import { connect } from 'react-redux'; +import { + setCashflowAccountsTableState, + resetCashflowAccountsTableState, +} from 'store/CashflowAccounts/CashflowAccounts.actions'; + +const mapActionsToProps = (dispatch) => ({ + setCashflowAccountsTableState: (queries) => + dispatch(setCashflowAccountsTableState(queries)), + + resetCashflowAccountsTableState: () => + dispatch(resetCashflowAccountsTableState()), +}); + +export default connect(null, mapActionsToProps); diff --git a/src/containers/CashFlow/CashFlowAccounts/CashFlowAccountsActionsBar.js b/src/containers/CashFlow/CashFlowAccounts/CashFlowAccountsActionsBar.js index d250f7257..fbbb906fe 100644 --- a/src/containers/CashFlow/CashFlowAccounts/CashFlowAccountsActionsBar.js +++ b/src/containers/CashFlow/CashFlowAccounts/CashFlowAccountsActionsBar.js @@ -1,26 +1,22 @@ import React from 'react'; -import classNames from 'classnames'; - -import { isEmpty } from 'lodash'; import { Button, NavbarGroup, Classes, NavbarDivider, Alignment, + Switch, } from '@blueprintjs/core'; - import { Icon, - DashboardRowsHeightButton, FormattedMessage as T, } from 'components'; - import DashboardActionsBar from 'components/Dashboard/DashboardActionsBar'; -import { useCashFlowAccountsContext } from './CashFlowAccountsProvider'; + import withDialogActions from 'containers/Dialog/withDialogActions'; import withSettings from '../../Settings/withSettings'; import withSettingsActions from '../../Settings/withSettingsActions'; +import withCashflowAccountsTableActions from '../AccountTransactions/withCashflowAccountsTableActions'; import { compose } from 'utils'; @@ -36,12 +32,14 @@ function CashFlowAccountsActionsBar({ // #withSettingsActions addSetting, + + // # + setCashflowAccountsTableState }) { // Handle table row size change. const handleTableRowSizeChange = (size) => { addSetting('cashflowAccounts', 'tableSize', size); }; - // Handle click a refresh const handleRefreshBtnClick = () => {}; @@ -49,18 +47,21 @@ function CashFlowAccountsActionsBar({ const handleAddBankAccount = () => { openDialog('account-form', {}); }; - // Handle add cash account. const handleAddCashAccount = () => { openDialog('account-form', {}); }; + // Handle inactive switch changing. + const handleInactiveSwitchChange = (event) => { + const checked = event.target.checked; + setCashflowAccountsTableState({ inactiveMode: checked }); + }; return (