From fc67d56d45363beb5edc9af74ef51ec33dccdd54 Mon Sep 17 00:00:00 2001 From: "a.bouhuolia" Date: Sun, 24 Oct 2021 12:12:43 +0200 Subject: [PATCH] feat: Cashflow bank account context menu. --- src/components/BankAccounts/index.js | 31 +--- .../CashFlowAccounts/CashflowAccountsGrid.js | 161 ++++++++++++++++-- 2 files changed, 147 insertions(+), 45 deletions(-) diff --git a/src/components/BankAccounts/index.js b/src/components/BankAccounts/index.js index edd882a1a..13a3f928d 100644 --- a/src/components/BankAccounts/index.js +++ b/src/components/BankAccounts/index.js @@ -2,8 +2,6 @@ import React from 'react'; import styled from 'styled-components'; import { Classes } from '@blueprintjs/core'; import clsx from 'classnames'; -import useContextMenu from 'react-use-context-menu'; -import ContextMenu from '../ContextMenu'; import Icon from '../Icon'; const BankAccountWrap = styled.div` @@ -173,26 +171,10 @@ export function BankAccount({ balance, loading = false, updatedBeforeText, - to, - contextMenuContent, + ...restProps }) { - const [ - bindMenu, - bindMenuItem, - useContextTrigger, - { coords, setVisible, isVisible }, - ] = useContextMenu(); - - const [bindTrigger] = useContextTrigger({ - collect: () => 'Title', - }); - - const handleClose = React.useCallback(() => { - setVisible(false); - }, [setVisible]); - return ( - + {title} @@ -216,15 +198,6 @@ export function BankAccount({ - - - - ); } diff --git a/src/containers/CashFlow/CashFlowAccounts/CashflowAccountsGrid.js b/src/containers/CashFlow/CashFlowAccounts/CashflowAccountsGrid.js index f378f6331..6f8271b92 100644 --- a/src/containers/CashFlow/CashFlowAccounts/CashflowAccountsGrid.js +++ b/src/containers/CashFlow/CashFlowAccounts/CashflowAccountsGrid.js @@ -1,17 +1,34 @@ import React from 'react'; import { isNull } from 'lodash'; +import { compose } from 'lodash/fp'; import styled from 'styled-components'; import { Link } from 'react-router-dom'; import { Menu, MenuItem, MenuDivider, Intent } from '@blueprintjs/core'; import intl from 'react-intl-universal'; -import { BankAccountsList, BankAccount, If, Icon } from '../../../components'; +import useContextMenu from 'react-use-context-menu'; + +import { + ContextMenu, + BankAccountsList, + BankAccount, + If, + Icon, +} from '../../../components'; +import AccountsAlerts from './../../Accounts/AccountsAlerts'; + import { useCashFlowAccountsContext } from './CashFlowAccountsProvider'; -const CashflowAccountsGridWrap = styled.div` - margin: 30px; -`; +import withDrawerActions from '../../Drawer/withDrawerActions'; +import withAlertsActions from '../../Alert/withAlertActions'; +import withDialogActions from '../../Dialog/withDialogActions'; + +import { safeCallback } from 'utils'; + const CASHFLOW_SKELETON_N = 4; +/** + * Cashflow accounts skeleton for loading state. + */ function CashflowAccountsSkeleton() { return [...Array(CASHFLOW_SKELETON_N)].map((e, i) => ( 'Title', + }); + + const handleClose = React.useCallback(() => { + setVisible(false); + }, [setVisible]); + + // Handle view detail account. + const handleViewClick = () => { + openDrawer('account-drawer', { accountId: account.id }); + }; + // Handle delete action account. + const handleDeleteClick = () => { + openAlert('account-delete', { accountId: account.id }); + }; + // Handle inactivate action account. + const handleInactivateClick = () => { + openAlert('account-inactivate', { accountId: account.id }); + }; + // Handle activate action account. + const handleActivateClick = () => { + openAlert('account-activate', { accountId: account.id }); + }; + // Handle edit account action. + const handleEditAccount = () => { + openDialog('account-form', { action: 'edit', id: account.id }); + }; + + return ( + + + + + + + + + + ); +} + +const CashflowBankAccountEnhanced = compose( + withAlertsActions, + withDrawerActions, + withDialogActions, +)(CashflowBankAccount); + function getUpdatedBeforeText(createdAt) { return 'Updated before 2 years.'; } +/** + * Cashflow accounts grid items. + */ function CashflowAccountsGridItems({ accounts }) { return accounts.map((account) => ( - - - + )); } +/** + * Cashflow accounts grid. + */ export default function CashflowAccountsGrid() { // Retrieve list context. const { cashflowAccounts, isCashFlowAccountsLoading } = @@ -57,36 +161,55 @@ export default function CashflowAccountsGrid() { )} + + ); } -function CashflowAccountContextMenu() { +/** + * Cashflow account context menu. + */ +function CashflowAccountContextMenu({ + onViewClick, + onEditClick, + onInactivateClick, + onActivateClick, + onDeleteClick, +}) { return ( } text={intl.get('view_details')} + onClick={safeCallback(onViewClick)} /> - } text={intl.get('edit_account')} /> + } + text={intl.get('edit_account')} + onClick={safeCallback(onEditClick)} + /> } + onClick={safeCallback(onInactivateClick)} /> } + onClick={safeCallback(onActivateClick)} /> } intent={Intent.DANGER} + onClick={safeCallback(onDeleteClick)} /> ); @@ -101,3 +224,9 @@ const CashflowAccountAnchor = styled(Link)` text-decoration: none; } `; + +const CashflowAccountsGridWrap = styled.div` + margin: 30px; +`; + +const CashflowBankAccountWrap = styled.div``;