mirror of
https://github.com/bigcapitalhq/bigcapital.git
synced 2026-02-19 22:30:31 +00:00
feat: Cashflow bank account context menu.
This commit is contained in:
@@ -2,8 +2,6 @@ import React from 'react';
|
|||||||
import styled from 'styled-components';
|
import styled from 'styled-components';
|
||||||
import { Classes } from '@blueprintjs/core';
|
import { Classes } from '@blueprintjs/core';
|
||||||
import clsx from 'classnames';
|
import clsx from 'classnames';
|
||||||
import useContextMenu from 'react-use-context-menu';
|
|
||||||
import ContextMenu from '../ContextMenu';
|
|
||||||
import Icon from '../Icon';
|
import Icon from '../Icon';
|
||||||
|
|
||||||
const BankAccountWrap = styled.div`
|
const BankAccountWrap = styled.div`
|
||||||
@@ -173,26 +171,10 @@ export function BankAccount({
|
|||||||
balance,
|
balance,
|
||||||
loading = false,
|
loading = false,
|
||||||
updatedBeforeText,
|
updatedBeforeText,
|
||||||
to,
|
...restProps
|
||||||
contextMenuContent,
|
|
||||||
}) {
|
}) {
|
||||||
const [
|
|
||||||
bindMenu,
|
|
||||||
bindMenuItem,
|
|
||||||
useContextTrigger,
|
|
||||||
{ coords, setVisible, isVisible },
|
|
||||||
] = useContextMenu();
|
|
||||||
|
|
||||||
const [bindTrigger] = useContextTrigger({
|
|
||||||
collect: () => 'Title',
|
|
||||||
});
|
|
||||||
|
|
||||||
const handleClose = React.useCallback(() => {
|
|
||||||
setVisible(false);
|
|
||||||
}, [setVisible]);
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<BankAccountWrap {...bindTrigger}>
|
<BankAccountWrap {...restProps}>
|
||||||
<BankAccountHeader>
|
<BankAccountHeader>
|
||||||
<BankAccountTitle className={clsx({ [Classes.SKELETON]: loading })}>
|
<BankAccountTitle className={clsx({ [Classes.SKELETON]: loading })}>
|
||||||
{title}
|
{title}
|
||||||
@@ -216,15 +198,6 @@ export function BankAccount({
|
|||||||
</BankAccountMeta>
|
</BankAccountMeta>
|
||||||
|
|
||||||
<BankAccountBalance amount={balance} loading={loading} />
|
<BankAccountBalance amount={balance} loading={loading} />
|
||||||
|
|
||||||
<ContextMenu
|
|
||||||
bindMenu={bindMenu}
|
|
||||||
isOpen={isVisible}
|
|
||||||
coords={coords}
|
|
||||||
onClosed={handleClose}
|
|
||||||
>
|
|
||||||
<contextMenuContent />
|
|
||||||
</ContextMenu>
|
|
||||||
</BankAccountWrap>
|
</BankAccountWrap>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,17 +1,34 @@
|
|||||||
import React from 'react';
|
import React from 'react';
|
||||||
import { isNull } from 'lodash';
|
import { isNull } from 'lodash';
|
||||||
|
import { compose } from 'lodash/fp';
|
||||||
import styled from 'styled-components';
|
import styled from 'styled-components';
|
||||||
import { Link } from 'react-router-dom';
|
import { Link } from 'react-router-dom';
|
||||||
import { Menu, MenuItem, MenuDivider, Intent } from '@blueprintjs/core';
|
import { Menu, MenuItem, MenuDivider, Intent } from '@blueprintjs/core';
|
||||||
import intl from 'react-intl-universal';
|
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';
|
import { useCashFlowAccountsContext } from './CashFlowAccountsProvider';
|
||||||
|
|
||||||
const CashflowAccountsGridWrap = styled.div`
|
import withDrawerActions from '../../Drawer/withDrawerActions';
|
||||||
margin: 30px;
|
import withAlertsActions from '../../Alert/withAlertActions';
|
||||||
`;
|
import withDialogActions from '../../Dialog/withDialogActions';
|
||||||
|
|
||||||
|
import { safeCallback } from 'utils';
|
||||||
|
|
||||||
const CASHFLOW_SKELETON_N = 4;
|
const CASHFLOW_SKELETON_N = 4;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Cashflow accounts skeleton for loading state.
|
||||||
|
*/
|
||||||
function CashflowAccountsSkeleton() {
|
function CashflowAccountsSkeleton() {
|
||||||
return [...Array(CASHFLOW_SKELETON_N)].map((e, i) => (
|
return [...Array(CASHFLOW_SKELETON_N)].map((e, i) => (
|
||||||
<BankAccount
|
<BankAccount
|
||||||
@@ -24,25 +41,112 @@ function CashflowAccountsSkeleton() {
|
|||||||
));
|
));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Cashflow bank account.
|
||||||
|
*/
|
||||||
|
function CashflowBankAccount({
|
||||||
|
// #withAlertsDialog
|
||||||
|
openAlert,
|
||||||
|
|
||||||
|
// #withDial
|
||||||
|
openDialog,
|
||||||
|
|
||||||
|
// #withDrawerActions
|
||||||
|
openDrawer,
|
||||||
|
|
||||||
|
account,
|
||||||
|
}) {
|
||||||
|
const [
|
||||||
|
bindMenu,
|
||||||
|
bindMenuItem,
|
||||||
|
useContextTrigger,
|
||||||
|
{ coords, setVisible, isVisible },
|
||||||
|
] = useContextMenu();
|
||||||
|
|
||||||
|
const [bindTrigger] = useContextTrigger({
|
||||||
|
collect: () => '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 (
|
||||||
|
<CashflowBankAccountWrap>
|
||||||
|
<CashflowAccountAnchor
|
||||||
|
to={`/cashflow-accounts/${account.id}/transactions`}
|
||||||
|
>
|
||||||
|
<BankAccount
|
||||||
|
{...bindTrigger}
|
||||||
|
title={account.name}
|
||||||
|
code={account.code}
|
||||||
|
balance={!isNull(account.amount) ? account.formatted_amount : '-'}
|
||||||
|
type={'cash'}
|
||||||
|
updatedBeforeText={getUpdatedBeforeText(account.createdAt)}
|
||||||
|
/>
|
||||||
|
</CashflowAccountAnchor>
|
||||||
|
|
||||||
|
<ContextMenu
|
||||||
|
bindMenu={bindMenu}
|
||||||
|
isOpen={isVisible}
|
||||||
|
coords={coords}
|
||||||
|
onClosed={handleClose}
|
||||||
|
>
|
||||||
|
<CashflowAccountContextMenu
|
||||||
|
onViewClick={handleViewClick}
|
||||||
|
onDeleteClick={handleDeleteClick}
|
||||||
|
onActivateClick={handleActivateClick}
|
||||||
|
onInactivateClick={handleInactivateClick}
|
||||||
|
onEditClick={handleEditAccount}
|
||||||
|
/>
|
||||||
|
</ContextMenu>
|
||||||
|
</CashflowBankAccountWrap>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
const CashflowBankAccountEnhanced = compose(
|
||||||
|
withAlertsActions,
|
||||||
|
withDrawerActions,
|
||||||
|
withDialogActions,
|
||||||
|
)(CashflowBankAccount);
|
||||||
|
|
||||||
function getUpdatedBeforeText(createdAt) {
|
function getUpdatedBeforeText(createdAt) {
|
||||||
return 'Updated before 2 years.';
|
return 'Updated before 2 years.';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Cashflow accounts grid items.
|
||||||
|
*/
|
||||||
function CashflowAccountsGridItems({ accounts }) {
|
function CashflowAccountsGridItems({ accounts }) {
|
||||||
return accounts.map((account) => (
|
return accounts.map((account) => (
|
||||||
<CashflowAccountAnchor to={`/cashflow-accounts/${account.id}/transactions`}>
|
<CashflowBankAccountEnhanced account={account} />
|
||||||
<BankAccount
|
|
||||||
title={account.name}
|
|
||||||
code={account.code}
|
|
||||||
balance={!isNull(account.amount) ? account.formatted_amount : '-'}
|
|
||||||
type={'cash'}
|
|
||||||
contextMenuContent={CashflowAccountContextMenu}
|
|
||||||
updatedBeforeText={getUpdatedBeforeText(account.createdAt)}
|
|
||||||
/>
|
|
||||||
</CashflowAccountAnchor>
|
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Cashflow accounts grid.
|
||||||
|
*/
|
||||||
export default function CashflowAccountsGrid() {
|
export default function CashflowAccountsGrid() {
|
||||||
// Retrieve list context.
|
// Retrieve list context.
|
||||||
const { cashflowAccounts, isCashFlowAccountsLoading } =
|
const { cashflowAccounts, isCashFlowAccountsLoading } =
|
||||||
@@ -57,36 +161,55 @@ export default function CashflowAccountsGrid() {
|
|||||||
<CashflowAccountsGridItems accounts={cashflowAccounts} />
|
<CashflowAccountsGridItems accounts={cashflowAccounts} />
|
||||||
)}
|
)}
|
||||||
</BankAccountsList>
|
</BankAccountsList>
|
||||||
|
|
||||||
|
<AccountsAlerts />
|
||||||
</CashflowAccountsGridWrap>
|
</CashflowAccountsGridWrap>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
function CashflowAccountContextMenu() {
|
/**
|
||||||
|
* Cashflow account context menu.
|
||||||
|
*/
|
||||||
|
function CashflowAccountContextMenu({
|
||||||
|
onViewClick,
|
||||||
|
onEditClick,
|
||||||
|
onInactivateClick,
|
||||||
|
onActivateClick,
|
||||||
|
onDeleteClick,
|
||||||
|
}) {
|
||||||
return (
|
return (
|
||||||
<Menu>
|
<Menu>
|
||||||
<MenuItem
|
<MenuItem
|
||||||
icon={<Icon icon="reader-18" />}
|
icon={<Icon icon="reader-18" />}
|
||||||
text={intl.get('view_details')}
|
text={intl.get('view_details')}
|
||||||
|
onClick={safeCallback(onViewClick)}
|
||||||
/>
|
/>
|
||||||
<MenuDivider />
|
<MenuDivider />
|
||||||
<MenuItem icon={<Icon icon="pen-18" />} text={intl.get('edit_account')} />
|
<MenuItem
|
||||||
|
icon={<Icon icon="pen-18" />}
|
||||||
|
text={intl.get('edit_account')}
|
||||||
|
onClick={safeCallback(onEditClick)}
|
||||||
|
/>
|
||||||
<MenuDivider />
|
<MenuDivider />
|
||||||
<If condition={false}>
|
<If condition={false}>
|
||||||
<MenuItem
|
<MenuItem
|
||||||
text={intl.get('inactivate_account')}
|
text={intl.get('inactivate_account')}
|
||||||
icon={<Icon icon="pause-16" iconSize={16} />}
|
icon={<Icon icon="pause-16" iconSize={16} />}
|
||||||
|
onClick={safeCallback(onInactivateClick)}
|
||||||
/>
|
/>
|
||||||
</If>
|
</If>
|
||||||
<If condition={!false}>
|
<If condition={!false}>
|
||||||
<MenuItem
|
<MenuItem
|
||||||
text={intl.get('activate_account')}
|
text={intl.get('activate_account')}
|
||||||
icon={<Icon icon="play-16" iconSize={16} />}
|
icon={<Icon icon="play-16" iconSize={16} />}
|
||||||
|
onClick={safeCallback(onActivateClick)}
|
||||||
/>
|
/>
|
||||||
</If>
|
</If>
|
||||||
<MenuItem
|
<MenuItem
|
||||||
text={intl.get('delete_account')}
|
text={intl.get('delete_account')}
|
||||||
icon={<Icon icon="trash-16" iconSize={16} />}
|
icon={<Icon icon="trash-16" iconSize={16} />}
|
||||||
intent={Intent.DANGER}
|
intent={Intent.DANGER}
|
||||||
|
onClick={safeCallback(onDeleteClick)}
|
||||||
/>
|
/>
|
||||||
</Menu>
|
</Menu>
|
||||||
);
|
);
|
||||||
@@ -101,3 +224,9 @@ const CashflowAccountAnchor = styled(Link)`
|
|||||||
text-decoration: none;
|
text-decoration: none;
|
||||||
}
|
}
|
||||||
`;
|
`;
|
||||||
|
|
||||||
|
const CashflowAccountsGridWrap = styled.div`
|
||||||
|
margin: 30px;
|
||||||
|
`;
|
||||||
|
|
||||||
|
const CashflowBankAccountWrap = styled.div``;
|
||||||
|
|||||||
Reference in New Issue
Block a user