mirror of
https://github.com/bigcapitalhq/bigcapital.git
synced 2026-02-20 23:00:34 +00:00
feat: bank rules table
This commit is contained in:
@@ -26,6 +26,7 @@ import BranchesAlerts from '@/containers/Preferences/Branches/BranchesAlerts';
|
|||||||
import ProjectAlerts from '@/containers/Projects/containers/ProjectAlerts';
|
import ProjectAlerts from '@/containers/Projects/containers/ProjectAlerts';
|
||||||
import TaxRatesAlerts from '@/containers/TaxRates/alerts';
|
import TaxRatesAlerts from '@/containers/TaxRates/alerts';
|
||||||
import { CashflowAlerts } from '../CashFlow/CashflowAlerts';
|
import { CashflowAlerts } from '../CashFlow/CashflowAlerts';
|
||||||
|
import { BankRulesAlerts } from '../Banking/Rules/RulesList/BankRulesAlerts';
|
||||||
|
|
||||||
export default [
|
export default [
|
||||||
...AccountsAlerts,
|
...AccountsAlerts,
|
||||||
@@ -55,4 +56,5 @@ export default [
|
|||||||
...ProjectAlerts,
|
...ProjectAlerts,
|
||||||
...TaxRatesAlerts,
|
...TaxRatesAlerts,
|
||||||
...CashflowAlerts,
|
...CashflowAlerts,
|
||||||
|
...BankRulesAlerts
|
||||||
];
|
];
|
||||||
|
|||||||
@@ -0,0 +1,16 @@
|
|||||||
|
// @ts-nocheck
|
||||||
|
import React from 'react';
|
||||||
|
|
||||||
|
const DeleteBankRuleAlert = React.lazy(
|
||||||
|
() => import('./alerts/DeleteBankRuleAlert'),
|
||||||
|
);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Cashflow alerts.
|
||||||
|
*/
|
||||||
|
export const BankRulesAlerts = [
|
||||||
|
{
|
||||||
|
name: 'bank-rule-delete',
|
||||||
|
component: DeleteBankRuleAlert,
|
||||||
|
},
|
||||||
|
];
|
||||||
@@ -4,6 +4,7 @@ import { useBankRules } from '@/hooks/query/bank-rules';
|
|||||||
|
|
||||||
interface RulesListBootValues {
|
interface RulesListBootValues {
|
||||||
bankRules: any;
|
bankRules: any;
|
||||||
|
isBankRulesLoading: boolean;
|
||||||
}
|
}
|
||||||
|
|
||||||
const RulesListBootContext = createContext<RulesListBootValues>(
|
const RulesListBootContext = createContext<RulesListBootValues>(
|
||||||
@@ -18,10 +19,11 @@ function RulesListBoot({ ...props }: RulesListBootProps) {
|
|||||||
const { data: bankRules, isLoading: isBankRulesLoading } = useBankRules();
|
const { data: bankRules, isLoading: isBankRulesLoading } = useBankRules();
|
||||||
|
|
||||||
const provider = { bankRules, isBankRulesLoading } as RulesListBootValues;
|
const provider = { bankRules, isBankRulesLoading } as RulesListBootValues;
|
||||||
|
const isLoading = isBankRulesLoading;
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<DialogContent isLoading={false}>
|
<DialogContent isLoading={isLoading}>
|
||||||
<RulesListBootContext.Provider value={provider} {...props} />
|
<RulesListBootContext.Provider {...props} value={provider} />
|
||||||
</DialogContent>
|
</DialogContent>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -15,6 +15,7 @@ import withDashboardActions from '@/containers/Dashboard/withDashboardActions';
|
|||||||
import { useBankRulesTableColumns } from './hooks';
|
import { useBankRulesTableColumns } from './hooks';
|
||||||
import { BankRulesTableActionsMenu } from './_components';
|
import { BankRulesTableActionsMenu } from './_components';
|
||||||
import { BankRulesLandingEmptyState } from './BankRulesLandingEmptyState';
|
import { BankRulesLandingEmptyState } from './BankRulesLandingEmptyState';
|
||||||
|
import { useRulesListBoot } from './RulesListBoot';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Invoices datatable.
|
* Invoices datatable.
|
||||||
@@ -32,8 +33,12 @@ function RulesTable({
|
|||||||
// Invoices table columns.
|
// Invoices table columns.
|
||||||
const columns = useBankRulesTableColumns();
|
const columns = useBankRulesTableColumns();
|
||||||
|
|
||||||
|
const { bankRules } = useRulesListBoot();
|
||||||
|
|
||||||
// Handle edit bank rule.
|
// Handle edit bank rule.
|
||||||
const handleDeleteBankRule = ({ id }) => {};
|
const handleDeleteBankRule = ({ id }) => {
|
||||||
|
openAlert('bank-rule-delete', { id });
|
||||||
|
};
|
||||||
|
|
||||||
// Handle delete bank rule.
|
// Handle delete bank rule.
|
||||||
const handleEditBankRule = () => {};
|
const handleEditBankRule = () => {};
|
||||||
@@ -49,7 +54,7 @@ function RulesTable({
|
|||||||
<DashboardContentTable>
|
<DashboardContentTable>
|
||||||
<DataTable
|
<DataTable
|
||||||
columns={columns}
|
columns={columns}
|
||||||
data={[]}
|
data={bankRules}
|
||||||
loading={false}
|
loading={false}
|
||||||
headerLoading={false}
|
headerLoading={false}
|
||||||
progressBarLoading={false}
|
progressBarLoading={false}
|
||||||
|
|||||||
@@ -16,14 +16,12 @@ export function BankRulesTableActionsMenu({
|
|||||||
return (
|
return (
|
||||||
<Menu>
|
<Menu>
|
||||||
<Can I={BankRuleAction.Edit} a={AbilitySubject.BankRule}>
|
<Can I={BankRuleAction.Edit} a={AbilitySubject.BankRule}>
|
||||||
<MenuDivider />
|
|
||||||
<MenuItem
|
<MenuItem
|
||||||
icon={<Icon icon="pen-18" />}
|
icon={<Icon icon="pen-18" />}
|
||||||
text={'Edit Rule'}
|
text={'Edit Rule'}
|
||||||
onClick={safeCallback(onEdit, original)}
|
onClick={safeCallback(onEdit, original)}
|
||||||
/>
|
/>
|
||||||
</Can>
|
</Can>
|
||||||
<MenuDivider />
|
|
||||||
<Can I={BankRuleAction.Delete} a={AbilitySubject.BankRule}>
|
<Can I={BankRuleAction.Delete} a={AbilitySubject.BankRule}>
|
||||||
<MenuDivider />
|
<MenuDivider />
|
||||||
<MenuItem
|
<MenuItem
|
||||||
|
|||||||
@@ -0,0 +1,80 @@
|
|||||||
|
// @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 { useDeleteBankRule } from '@/hooks/query/bank-rules';
|
||||||
|
import { compose } from '@/utils';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Project delete alert.
|
||||||
|
*/
|
||||||
|
function BankRuleDeleteAlert({
|
||||||
|
name,
|
||||||
|
|
||||||
|
// #withAlertStoreConnect
|
||||||
|
isOpen,
|
||||||
|
payload: { id },
|
||||||
|
|
||||||
|
// #withAlertActions
|
||||||
|
closeAlert,
|
||||||
|
|
||||||
|
// #withDrawerActions
|
||||||
|
closeDrawer,
|
||||||
|
}) {
|
||||||
|
const { mutateAsync: deleteBankRule, isLoading } = useDeleteBankRule();
|
||||||
|
|
||||||
|
// handle cancel delete project alert.
|
||||||
|
const handleCancelDeleteAlert = () => {
|
||||||
|
closeAlert(name);
|
||||||
|
};
|
||||||
|
|
||||||
|
// handleConfirm delete project
|
||||||
|
const handleConfirmBtnClick = () => {
|
||||||
|
deleteBankRule(id)
|
||||||
|
.then(() => {
|
||||||
|
AppToaster.show({
|
||||||
|
message: 'The bank rule has deleted successfully.',
|
||||||
|
intent: Intent.SUCCESS,
|
||||||
|
});
|
||||||
|
closeAlert(name);
|
||||||
|
})
|
||||||
|
.catch(
|
||||||
|
({
|
||||||
|
response: {
|
||||||
|
data: { errors },
|
||||||
|
},
|
||||||
|
}) => {
|
||||||
|
AppToaster.show({
|
||||||
|
message: 'Something went wrong.',
|
||||||
|
intent: Intent.DANGER,
|
||||||
|
});
|
||||||
|
},
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
return (
|
||||||
|
<Alert
|
||||||
|
cancelButtonText={<T id={'cancel'} />}
|
||||||
|
confirmButtonText={'Delete'}
|
||||||
|
intent={Intent.DANGER}
|
||||||
|
isOpen={isOpen}
|
||||||
|
onCancel={handleCancelDeleteAlert}
|
||||||
|
onConfirm={handleConfirmBtnClick}
|
||||||
|
loading={isLoading}
|
||||||
|
>
|
||||||
|
<p>Are you sure want to delete the bank rule?</p>
|
||||||
|
</Alert>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
export default compose(
|
||||||
|
withAlertStoreConnect(),
|
||||||
|
withAlertActions,
|
||||||
|
withDrawerActions,
|
||||||
|
)(BankRuleDeleteAlert);
|
||||||
@@ -1,3 +0,0 @@
|
|||||||
export const useBankRulesTableColumns = () => {
|
|
||||||
return [];
|
|
||||||
};
|
|
||||||
@@ -0,0 +1,36 @@
|
|||||||
|
// @ts-nocheck
|
||||||
|
import { useMemo } from 'react';
|
||||||
|
import { Intent, Tag } from '@blueprintjs/core';
|
||||||
|
|
||||||
|
export const useBankRulesTableColumns = () => {
|
||||||
|
return useMemo(
|
||||||
|
() => [
|
||||||
|
{
|
||||||
|
Header: 'Apply to',
|
||||||
|
accessor: (rule) =>
|
||||||
|
rule.apply_if_transaction_type === 'deposit' ? (
|
||||||
|
<Tag round intent={Intent.SUCCESS}>Deposits</Tag>
|
||||||
|
) : (
|
||||||
|
<Tag round intent={Intent.DANGER}>Withdrawals</Tag>
|
||||||
|
),
|
||||||
|
},
|
||||||
|
{
|
||||||
|
Header: 'Rule Name',
|
||||||
|
accessor: 'name',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
Header: 'Categorize As',
|
||||||
|
accessor: () => 'Expense',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
Header: 'Apply To',
|
||||||
|
accessor: () => <Tag intent={Intent.NONE} minimal>All Accounts</Tag>,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
Header: 'Conditions',
|
||||||
|
accessor: () => '',
|
||||||
|
},
|
||||||
|
],
|
||||||
|
[],
|
||||||
|
);
|
||||||
|
};
|
||||||
@@ -33,12 +33,15 @@ export function useDeleteBankRule(props) {
|
|||||||
const queryClient = useQueryClient();
|
const queryClient = useQueryClient();
|
||||||
const apiRequest = useApiRequest();
|
const apiRequest = useApiRequest();
|
||||||
|
|
||||||
return useMutation((id: number) => apiRequest.delete(`/bank-rules/${id}`), {
|
return useMutation(
|
||||||
onSuccess: (res, id) => {
|
(id: number) => apiRequest.delete(`/banking/rules/${id}`),
|
||||||
// Invalidate queries.
|
{
|
||||||
|
onSuccess: (res, id) => {
|
||||||
|
// Invalidate queries.
|
||||||
|
},
|
||||||
|
...props,
|
||||||
},
|
},
|
||||||
...props,
|
);
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
Reference in New Issue
Block a user