From c5783896ad78c7629a4ca6e9315016f14c4f5f6a Mon Sep 17 00:00:00 2001 From: elforjani13 <39470382+elforjani13@users.noreply.github.com> Date: Sun, 24 Oct 2021 14:34:30 +0200 Subject: [PATCH 1/2] feat: delete transaction. --- src/common/cashflowOptions.js | 9 +++ .../CashFlow/AccountDeleteTransactionAlert.js | 80 +++++++++++++++++++ .../AccountTransactionsAlerts.js | 14 ++++ .../AccountTransactionsDataTable.js | 20 ++++- .../AccountTransactionsList.js | 3 +- .../AccountTransactions/components.js | 29 +++++-- 6 files changed, 147 insertions(+), 8 deletions(-) create mode 100644 src/containers/Alerts/CashFlow/AccountDeleteTransactionAlert.js create mode 100644 src/containers/CashFlow/AccountTransactions/AccountTransactionsAlerts.js diff --git a/src/common/cashflowOptions.js b/src/common/cashflowOptions.js index 480b71162..dd14899ab 100644 --- a/src/common/cashflowOptions.js +++ b/src/common/cashflowOptions.js @@ -30,3 +30,12 @@ export const addMoneyOut = [ value: 'transfer_to_account', }, ]; + +export const TRANSACRIONS_TYPE = [ + 'OwnerContribution', + 'OtherIncome', + 'TransferFromAccount', + 'OnwersDrawing', + 'OtherExpense', + 'TransferToAccount', +]; diff --git a/src/containers/Alerts/CashFlow/AccountDeleteTransactionAlert.js b/src/containers/Alerts/CashFlow/AccountDeleteTransactionAlert.js new file mode 100644 index 000000000..da757392a --- /dev/null +++ b/src/containers/Alerts/CashFlow/AccountDeleteTransactionAlert.js @@ -0,0 +1,80 @@ +import React from 'react'; +import intl from 'react-intl-universal'; +import { FormattedMessage as T, FormattedHTMLMessage } from 'components'; +import { Intent, Alert } from '@blueprintjs/core'; +import { AppToaster } from 'components'; +import { useDeleteCashflowTransaction } from 'hooks/query'; + +import withAlertStoreConnect from 'containers/Alert/withAlertStoreConnect'; +import withAlertActions from 'containers/Alert/withAlertActions'; + +import { compose } from 'utils'; + +/** + * Account delete transaction alert. + */ +function AccountDeleteTransactionAlert({ + name, + + // #withAlertStoreConnect + isOpen, + payload: { referenceId }, + + // #withAlertActions + closeAlert, +}) { + const { mutateAsync: deleteTransactionMutate, isLoading } = + useDeleteCashflowTransaction(); + + // handle cancel delete alert + const handleCancelDeleteAlert = () => { + closeAlert(name); + }; + + // handleConfirm delete transaction. + const handleConfirmTransactioneDelete = () => { + deleteTransactionMutate(referenceId) + .then(() => { + AppToaster.show({ + message: intl.get('cash_flow_transaction.delete.alert_message'), + intent: Intent.SUCCESS, + }); + }) + .catch( + ({ + response: { + data: { errors }, + }, + }) => {}, + ) + .finally(() => { + closeAlert(name); + }); + }; + + return ( + } + confirmButtonText={} + icon="trash" + intent={Intent.DANGER} + isOpen={isOpen} + onCancel={handleCancelDeleteAlert} + onConfirm={handleConfirmTransactioneDelete} + loading={isLoading} + > +

+ +

+
+ ); +} + +export default compose( + withAlertStoreConnect(), + withAlertActions, +)(AccountDeleteTransactionAlert); diff --git a/src/containers/CashFlow/AccountTransactions/AccountTransactionsAlerts.js b/src/containers/CashFlow/AccountTransactions/AccountTransactionsAlerts.js new file mode 100644 index 000000000..5b3a88ab3 --- /dev/null +++ b/src/containers/CashFlow/AccountTransactions/AccountTransactionsAlerts.js @@ -0,0 +1,14 @@ +import React from 'react'; + +import AccountDeleteTransactionAlert from '../../Alerts/CashFlow/AccountDeleteTransactionAlert'; + +/** + * Account transaction alert. + */ +export default function AccountTransactionsAlerts() { + return ( +
+ +
+ ); +} diff --git a/src/containers/CashFlow/AccountTransactions/AccountTransactionsDataTable.js b/src/containers/CashFlow/AccountTransactions/AccountTransactionsDataTable.js index 5b0f8e9aa..8ff95651b 100644 --- a/src/containers/CashFlow/AccountTransactions/AccountTransactionsDataTable.js +++ b/src/containers/CashFlow/AccountTransactions/AccountTransactionsDataTable.js @@ -8,9 +8,10 @@ import TableSkeletonRows from 'components/Datatable/TableSkeletonRows'; import TableSkeletonHeader from 'components/Datatable/TableHeaderSkeleton'; import withSettings from '../../Settings/withSettings'; +import withAlertsActions from 'containers/Alert/withAlertActions'; import { useMemorizedColumnsWidths } from '../../../hooks'; -import { useAccountTransactionsColumns } from './components'; +import { useAccountTransactionsColumns, ActionsMenu } from './components'; import { useAccountTransactionsContext } from './AccountTransactionsProvider'; import { compose } from 'utils'; @@ -20,6 +21,9 @@ import { compose } from 'utils'; function AccountTransactionsDataTable({ // #withSettings cashflowTansactionsTableSize, + + // #withAlertsActions + openAlert, }) { // Retrieve table columns. const columns = useAccountTransactionsColumns(); @@ -35,6 +39,11 @@ function AccountTransactionsDataTable({ const [initialColumnsWidths, , handleColumnResizing] = useMemorizedColumnsWidths(TABLES.CASHFLOW_Transactions); + // handle delete transaction + const handleDeleteTransaction = ({ reference_id }) => { + openAlert('account-transaction-delete', { referenceId: reference_id }); + }; + return ( ); } @@ -68,4 +83,5 @@ export default compose( withSettings(({ cashflowTransactionsSettings }) => ({ cashflowTansactionsTableSize: cashflowTransactionsSettings?.tableSize, })), + withAlertsActions, )(AccountTransactionsDataTable); diff --git a/src/containers/CashFlow/AccountTransactions/AccountTransactionsList.js b/src/containers/CashFlow/AccountTransactions/AccountTransactionsList.js index 40869934d..a627bc2f5 100644 --- a/src/containers/CashFlow/AccountTransactions/AccountTransactionsList.js +++ b/src/containers/CashFlow/AccountTransactions/AccountTransactionsList.js @@ -8,7 +8,7 @@ import { AccountTransactionsProvider } from './AccountTransactionsProvider'; import AccountTransactionsActionsBar from './AccountTransactionsActionsBar'; import AccountTransactionsDataTable from './AccountTransactionsDataTable'; import { AccountTransactionsDetailsBar } from './AccountTransactionsDetailsBar'; - +import AccountTransactionsAlerts from './AccountTransactionsAlerts'; import { AccountTransactionsProgressBar } from './components'; /** @@ -26,6 +26,7 @@ function AccountTransactionsList() { + ); } diff --git a/src/containers/CashFlow/AccountTransactions/components.js b/src/containers/CashFlow/AccountTransactions/components.js index a08aa905c..ad4dda8c6 100644 --- a/src/containers/CashFlow/AccountTransactions/components.js +++ b/src/containers/CashFlow/AccountTransactions/components.js @@ -1,9 +1,28 @@ import React from 'react'; import intl from 'react-intl-universal'; -import { MaterialProgressBar } from 'components'; -import { FormatDateCell } from 'components'; -import { useAccountTransactionsContext } from './AccountTransactionsProvider'; +import { Intent, Menu, MenuItem } from '@blueprintjs/core'; + +import { MaterialProgressBar } from 'components'; +import { FormatDateCell, If, Icon } from 'components'; +import { useAccountTransactionsContext } from './AccountTransactionsProvider'; +import { TRANSACRIONS_TYPE } from 'common/cashflowOptions'; +import { safeCallback } from 'utils'; + +export function ActionsMenu({ payload: { onDelete }, row: { original } }) { + return ( + + + } + /> + + + ); +} /** * Retrieve account transctions table columns. */ @@ -47,7 +66,7 @@ export function useAccountTransactionsColumns() { width: 110, className: 'deposit', textOverview: true, - align: 'right' + align: 'right', }, { id: 'withdrawal', @@ -65,7 +84,7 @@ export function useAccountTransactionsColumns() { className: 'running_balance', width: 150, textOverview: true, - align: 'right' + align: 'right', }, ], [], From 68f8140007dfa389f006a23fa1c2a0216c2556f0 Mon Sep 17 00:00:00 2001 From: elforjani13 <39470382+elforjani13@users.noreply.github.com> Date: Sun, 24 Oct 2021 14:35:39 +0200 Subject: [PATCH 2/2] feat: add money in & out to keyboardshortcuts. --- src/common/keyboardShortcutsOptions.js | 8 ++++++++ src/components/Dashboard/GlobalHotkeys.js | 4 ++-- src/lang/en/index.json | 9 ++++++--- 3 files changed, 16 insertions(+), 5 deletions(-) diff --git a/src/common/keyboardShortcutsOptions.js b/src/common/keyboardShortcutsOptions.js index c33e5a705..9a904e09b 100644 --- a/src/common/keyboardShortcutsOptions.js +++ b/src/common/keyboardShortcutsOptions.js @@ -42,6 +42,14 @@ export default [ shortcut_key: 'Shift + W', description: intl.get('jump_to_the_items'), }, + { + shortcut_key: 'Shift + D', + description: intl.get('jump_to_the_add_money_in'), + }, + { + shortcut_key: 'Shift + Q', + description: intl.get('jump_to_the_add_money_out'), + }, { shortcut_key: 'Shift + 1', description: intl.get('jump_to_the_balance_sheet'), diff --git a/src/components/Dashboard/GlobalHotkeys.js b/src/components/Dashboard/GlobalHotkeys.js index 2bf734b9e..7daddca87 100644 --- a/src/components/Dashboard/GlobalHotkeys.js +++ b/src/components/Dashboard/GlobalHotkeys.js @@ -37,8 +37,8 @@ function GlobalHotkeys({ [history], ); useHotkeys('ctrl+/', (event, handle) => handleSidebarToggleBtn()); - useHotkeys('shift+q', (event, handle) => openDialog('money-in', {})); - useHotkeys('shift+d', (event, handle) => openDialog('money-out', {})); + useHotkeys('shift+d', (event, handle) => openDialog('money-in', {})); + useHotkeys('shift+q', (event, handle) => openDialog('money-out', {})); return
; } diff --git a/src/lang/en/index.json b/src/lang/en/index.json index 41a8cc2b6..2d2636e07 100644 --- a/src/lang/en/index.json +++ b/src/lang/en/index.json @@ -1003,6 +1003,8 @@ "jump_to_the_bills": "Jump to the bills.", "jump_to_the_manual_journals": "Jump to the Manual Journals.", "jump_to_the_items": "Jump to the items.", + "jump_to_the_add_money_in": "Jump to the cash flow add money in.", + "jump_to_the_add_money_out": "Jump to the cash flow add money out.", "jump_to_the_balance_sheet": "Jump to the Balance Sheet.", "jump_to_the_profit_loss_sheet": "Jump to the Profit Loss Sheet.", "jump_to_the_journal_sheet": "Jump to the Journal Sheet.", @@ -1012,7 +1014,7 @@ "create_a_new_estimate": "Create a new estimate.", "create_a_new_receipt": "Create a new receipt.", "create_a_new_expense": "Create a new expense.", - "create_a_new_customer": "create_a_new_customer", + "create_a_new_customer": "Create a new customer", "create_a_new_vendor": "Create a new vendor.", "create_a_new_bill": "Create a new bill.", "create_a_new_journal": "Create a new journal.", @@ -1389,8 +1391,9 @@ "save_and_publish": "Save & Publish", "cash_flow_transaction.label_transfer_from_account":"Transfer from account", "cash_flow_transaction.label_transfer_to_account":"Transfer to account", - "cash_flow_transaction.label_current_account":"Current account" - + "cash_flow_transaction.label_current_account":"Current account", + "cash_flow_transaction.delete.alert_message":"The cashflow transaction has been deleted successfully", + "cash_flow_transaction_once_delete_this_transaction_you_will_able_to_restore_it": "Once you delete this transaction, you won't be able to restore it later. Are you sure you want to delete this transaction?" }