mirror of
https://github.com/bigcapitalhq/bigcapital.git
synced 2026-02-15 12:20:31 +00:00
feat: uncategorize the cashflow transaction
This commit is contained in:
@@ -25,6 +25,7 @@ import WarehousesTransfersAlerts from '@/containers/WarehouseTransfers/Warehouse
|
||||
import BranchesAlerts from '@/containers/Preferences/Branches/BranchesAlerts';
|
||||
import ProjectAlerts from '@/containers/Projects/containers/ProjectAlerts';
|
||||
import TaxRatesAlerts from '@/containers/TaxRates/alerts';
|
||||
import { CashflowAlerts } from '../CashFlow/CashflowAlerts';
|
||||
|
||||
export default [
|
||||
...AccountsAlerts,
|
||||
@@ -53,4 +54,5 @@ export default [
|
||||
...BranchesAlerts,
|
||||
...ProjectAlerts,
|
||||
...TaxRatesAlerts,
|
||||
...CashflowAlerts,
|
||||
];
|
||||
|
||||
16
packages/webapp/src/containers/CashFlow/CashflowAlerts.ts
Normal file
16
packages/webapp/src/containers/CashFlow/CashflowAlerts.ts
Normal file
@@ -0,0 +1,16 @@
|
||||
// @ts-nocheck
|
||||
import React from 'react';
|
||||
|
||||
const UncategorizeTransactionAlert = React.lazy(
|
||||
() => import('./UncategorizeTransactionAlert/UncategorizeTransactionAlert'),
|
||||
);
|
||||
|
||||
/**
|
||||
* Cashflow alerts.
|
||||
*/
|
||||
export const CashflowAlerts = [
|
||||
{
|
||||
name: 'cashflow-tranaction-uncategorize',
|
||||
component: UncategorizeTransactionAlert,
|
||||
},
|
||||
];
|
||||
@@ -0,0 +1,83 @@
|
||||
// @ts-nocheck
|
||||
import React from 'react';
|
||||
import { Intent, Alert } from '@blueprintjs/core';
|
||||
import { FormattedMessage as T } from '@/components';
|
||||
import { AppToaster } from '@/components';
|
||||
|
||||
import withAlertStoreConnect from '@/containers/Alert/withAlertStoreConnect';
|
||||
import withAlertActions from '@/containers/Alert/withAlertActions';
|
||||
import withDrawerActions from '@/containers/Drawer/withDrawerActions';
|
||||
|
||||
import { useUncategorizeTransaction } from '@/hooks/query';
|
||||
import { compose } from '@/utils';
|
||||
import { DRAWERS } from '@/constants/drawers';
|
||||
|
||||
/**
|
||||
* Project delete alert.
|
||||
*/
|
||||
function UncategorizeTransactionAlert({
|
||||
name,
|
||||
|
||||
// #withAlertStoreConnect
|
||||
isOpen,
|
||||
payload: { uncategorizedTransactionId },
|
||||
|
||||
// #withAlertActions
|
||||
closeAlert,
|
||||
|
||||
// #withDrawerActions
|
||||
closeDrawer,
|
||||
}) {
|
||||
const { mutateAsync: uncategorizeTransaction, isLoading } =
|
||||
useUncategorizeTransaction();
|
||||
|
||||
// handle cancel delete project alert.
|
||||
const handleCancelDeleteAlert = () => {
|
||||
closeAlert(name);
|
||||
};
|
||||
|
||||
// handleConfirm delete project
|
||||
const handleConfirmBtnClick = () => {
|
||||
uncategorizeTransaction(uncategorizedTransactionId)
|
||||
.then(() => {
|
||||
AppToaster.show({
|
||||
message: 'The transaction has uncategorized successfully.',
|
||||
intent: Intent.SUCCESS,
|
||||
});
|
||||
closeAlert(name);
|
||||
closeDrawer(DRAWERS.CASHFLOW_TRNASACTION_DETAILS);
|
||||
})
|
||||
.catch(
|
||||
({
|
||||
response: {
|
||||
data: { errors },
|
||||
},
|
||||
}) => {
|
||||
AppToaster.show({
|
||||
message: 'Something went wrong.',
|
||||
intent: Intent.DANGER,
|
||||
});
|
||||
},
|
||||
);
|
||||
};
|
||||
|
||||
return (
|
||||
<Alert
|
||||
cancelButtonText={<T id={'cancel'} />}
|
||||
confirmButtonText={'Uncategorize'}
|
||||
intent={Intent.WARNING}
|
||||
isOpen={isOpen}
|
||||
onCancel={handleCancelDeleteAlert}
|
||||
onConfirm={handleConfirmBtnClick}
|
||||
loading={isLoading}
|
||||
>
|
||||
<p>Are you sure want to uncategorize the transaction?</p>
|
||||
</Alert>
|
||||
);
|
||||
}
|
||||
|
||||
export default compose(
|
||||
withAlertStoreConnect(),
|
||||
withAlertActions,
|
||||
withDrawerActions,
|
||||
)(UncategorizeTransactionAlert);
|
||||
@@ -0,0 +1 @@
|
||||
export * from './UncategorizeTransactionAlert';
|
||||
@@ -1,11 +1,18 @@
|
||||
// @ts-nocheck
|
||||
import React from 'react';
|
||||
import { Button, Classes, NavbarGroup, Intent } from '@blueprintjs/core';
|
||||
import {
|
||||
Button,
|
||||
Classes,
|
||||
NavbarGroup,
|
||||
Intent,
|
||||
NavbarDivider,
|
||||
} from '@blueprintjs/core';
|
||||
import {
|
||||
Can,
|
||||
FormattedMessage as T,
|
||||
DrawerActionsBar,
|
||||
Icon,
|
||||
If,
|
||||
} from '@/components';
|
||||
import withAlertsActions from '@/containers/Alert/withAlertActions';
|
||||
import { useCashflowTransactionDrawerContext } from './CashflowTransactionDrawerProvider';
|
||||
@@ -19,13 +26,22 @@ function CashflowTransactionDrawerActionBar({
|
||||
// #withAlertsDialog
|
||||
openAlert,
|
||||
}) {
|
||||
const { referenceId } = useCashflowTransactionDrawerContext();
|
||||
const { referenceId, cashflowTransaction } =
|
||||
useCashflowTransactionDrawerContext();
|
||||
|
||||
// Handle cashflow transaction delete action.
|
||||
const handleDeleteCashflowTransaction = () => {
|
||||
openAlert('account-transaction-delete', { referenceId });
|
||||
};
|
||||
|
||||
// Handles the uncategorize button click.
|
||||
const handleUncategorizeBtnClick = () => {
|
||||
openAlert('cashflow-tranaction-uncategorize', {
|
||||
uncategorizedTransactionId:
|
||||
cashflowTransaction.uncategorized_transaction_id,
|
||||
});
|
||||
};
|
||||
|
||||
return (
|
||||
<Can I={CashflowAction.Delete} a={AbilitySubject.Cashflow}>
|
||||
<DrawerActionsBar>
|
||||
@@ -37,6 +53,14 @@ function CashflowTransactionDrawerActionBar({
|
||||
intent={Intent.DANGER}
|
||||
onClick={handleDeleteCashflowTransaction}
|
||||
/>
|
||||
<If condition={cashflowTransaction.uncategorized_transaction_id}>
|
||||
<NavbarDivider />
|
||||
<Button
|
||||
text={'Uncategorize'}
|
||||
onClick={handleUncategorizeBtnClick}
|
||||
className={Classes.MINIMAL}
|
||||
/>
|
||||
</If>
|
||||
</NavbarGroup>
|
||||
</DrawerActionsBar>
|
||||
</Can>
|
||||
|
||||
@@ -256,3 +256,26 @@ export function useCategorizeTransaction(props) {
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Uncategorize the cashflow transaction.
|
||||
*/
|
||||
export function useUncategorizeTransaction(props) {
|
||||
const queryClient = useQueryClient();
|
||||
const apiRequest = useApiRequest();
|
||||
|
||||
return useMutation(
|
||||
(id: number) => apiRequest.post(`cashflow/transactions/${id}/uncategorize`),
|
||||
{
|
||||
onSuccess: (res, id) => {
|
||||
// Invalidate queries.
|
||||
commonInvalidateQueries(queryClient);
|
||||
queryClient.invalidateQueries(t.CASHFLOW_UNCAATEGORIZED_TRANSACTION);
|
||||
queryClient.invalidateQueries(
|
||||
t.CASHFLOW_ACCOUNT_UNCATEGORIZED_TRANSACTIONS_INFINITY,
|
||||
);
|
||||
},
|
||||
...props,
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user