mirror of
https://github.com/bigcapitalhq/bigcapital.git
synced 2026-02-18 13:50:31 +00:00
feat(webapp): add activate/inactivate tax rate buttons on details drawer
This commit is contained in:
@@ -4,17 +4,26 @@ import {
|
|||||||
Button,
|
Button,
|
||||||
Classes,
|
Classes,
|
||||||
Intent,
|
Intent,
|
||||||
|
Menu,
|
||||||
|
MenuItem,
|
||||||
NavbarDivider,
|
NavbarDivider,
|
||||||
NavbarGroup,
|
NavbarGroup,
|
||||||
|
Popover,
|
||||||
|
PopoverInteractionKind,
|
||||||
|
Position,
|
||||||
} from '@blueprintjs/core';
|
} from '@blueprintjs/core';
|
||||||
import * as R from 'ramda';
|
import * as R from 'ramda';
|
||||||
import { Can, DashboardActionsBar, Icon } from '@/components';
|
import { AppToaster, Can, DashboardActionsBar, Icon } from '@/components';
|
||||||
import { AbilitySubject, TaxRateAction } from '@/constants/abilityOption';
|
import { AbilitySubject, TaxRateAction } from '@/constants/abilityOption';
|
||||||
import withDrawerActions from '@/containers/Drawer/withDrawerActions';
|
import withDrawerActions from '@/containers/Drawer/withDrawerActions';
|
||||||
import withAlertsActions from '@/containers/Alert/withAlertActions';
|
import withAlertsActions from '@/containers/Alert/withAlertActions';
|
||||||
import withDialogActions from '@/containers/Dialog/withDialogActions';
|
import withDialogActions from '@/containers/Dialog/withDialogActions';
|
||||||
import { useTaxRateDetailsContext } from './TaxRateDetailsContentBoot';
|
import { useTaxRateDetailsContext } from './TaxRateDetailsContentBoot';
|
||||||
import { DialogsName } from '@/constants/dialogs';
|
import { DialogsName } from '@/constants/dialogs';
|
||||||
|
import {
|
||||||
|
useActivateTaxRate,
|
||||||
|
useInactivateTaxRate,
|
||||||
|
} from '@/hooks/query/taxRates';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Tax rate details content actions bar.
|
* Tax rate details content actions bar.
|
||||||
@@ -27,7 +36,10 @@ function TaxRateDetailsContentActionsBar({
|
|||||||
// #withAlertsActions
|
// #withAlertsActions
|
||||||
openAlert,
|
openAlert,
|
||||||
}) {
|
}) {
|
||||||
const { taxRateId } = useTaxRateDetailsContext();
|
const { taxRateId, taxRate } = useTaxRateDetailsContext();
|
||||||
|
|
||||||
|
const { mutateAsync: activateTaxRateMutate } = useActivateTaxRate();
|
||||||
|
const { mutateAsync: inactivateTaxRateMutate } = useInactivateTaxRate();
|
||||||
|
|
||||||
// Handle edit tax rate.
|
// Handle edit tax rate.
|
||||||
const handleEditTaxRate = () => {
|
const handleEditTaxRate = () => {
|
||||||
@@ -37,6 +49,38 @@ function TaxRateDetailsContentActionsBar({
|
|||||||
const handleDeleteTaxRate = () => {
|
const handleDeleteTaxRate = () => {
|
||||||
openAlert('tax-rate-delete', { taxRateId });
|
openAlert('tax-rate-delete', { taxRateId });
|
||||||
};
|
};
|
||||||
|
// Handle activate tax rate.
|
||||||
|
const handleActivateTaxRate = () => {
|
||||||
|
activateTaxRateMutate(taxRateId)
|
||||||
|
.then(() => {
|
||||||
|
AppToaster.show({
|
||||||
|
message: 'The tax rate has been activated successfully.',
|
||||||
|
intent: Intent.SUCCESS,
|
||||||
|
});
|
||||||
|
})
|
||||||
|
.catch(() => {
|
||||||
|
AppToaster.show({
|
||||||
|
message: 'Something went wrong.',
|
||||||
|
intent: Intent.DANGER,
|
||||||
|
});
|
||||||
|
});
|
||||||
|
};
|
||||||
|
// Handle inactivate tax rate.
|
||||||
|
const handleInactivateTaxRate = () => {
|
||||||
|
inactivateTaxRateMutate(taxRateId)
|
||||||
|
.then(() => {
|
||||||
|
AppToaster.show({
|
||||||
|
message: 'The tax rate has been inactivated successfully.',
|
||||||
|
intent: Intent.SUCCESS,
|
||||||
|
});
|
||||||
|
})
|
||||||
|
.catch(() => {
|
||||||
|
AppToaster.show({
|
||||||
|
message: 'Something went wrong.',
|
||||||
|
intent: Intent.DANGER,
|
||||||
|
});
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<DashboardActionsBar>
|
<DashboardActionsBar>
|
||||||
@@ -59,6 +103,39 @@ function TaxRateDetailsContentActionsBar({
|
|||||||
onClick={handleDeleteTaxRate}
|
onClick={handleDeleteTaxRate}
|
||||||
/>
|
/>
|
||||||
</Can>
|
</Can>
|
||||||
|
|
||||||
|
<Can I={TaxRateAction.Edit} a={AbilitySubject.TaxRate}>
|
||||||
|
<NavbarDivider />
|
||||||
|
<Popover
|
||||||
|
minimal={true}
|
||||||
|
interactionKind={PopoverInteractionKind.CLICK}
|
||||||
|
position={Position.BOTTOM_LEFT}
|
||||||
|
modifiers={{
|
||||||
|
offset: { offset: '0, 4' },
|
||||||
|
}}
|
||||||
|
content={
|
||||||
|
<Menu>
|
||||||
|
{!taxRate.active && (
|
||||||
|
<MenuItem
|
||||||
|
text={'Activate Tax Rate'}
|
||||||
|
onClick={handleActivateTaxRate}
|
||||||
|
/>
|
||||||
|
)}
|
||||||
|
{!!taxRate.active && (
|
||||||
|
<MenuItem
|
||||||
|
text={'Inactivate Tax Rate'}
|
||||||
|
onClick={handleInactivateTaxRate}
|
||||||
|
/>
|
||||||
|
)}
|
||||||
|
</Menu>
|
||||||
|
}
|
||||||
|
>
|
||||||
|
<Button
|
||||||
|
icon={<Icon icon="more-vert" iconSize={16} />}
|
||||||
|
minimal={true}
|
||||||
|
/>
|
||||||
|
</Popover>
|
||||||
|
</Can>
|
||||||
</NavbarGroup>
|
</NavbarGroup>
|
||||||
</DashboardActionsBar>
|
</DashboardActionsBar>
|
||||||
);
|
);
|
||||||
@@ -67,5 +144,5 @@ function TaxRateDetailsContentActionsBar({
|
|||||||
export default R.compose(
|
export default R.compose(
|
||||||
withDrawerActions,
|
withDrawerActions,
|
||||||
withDialogActions,
|
withDialogActions,
|
||||||
withAlertsActions
|
withAlertsActions,
|
||||||
)(TaxRateDetailsContentActionsBar);
|
)(TaxRateDetailsContentActionsBar);
|
||||||
|
|||||||
@@ -13,9 +13,15 @@ export default function TaxRateDetailsContentDetails() {
|
|||||||
<div>
|
<div>
|
||||||
<TaxRateHeader>
|
<TaxRateHeader>
|
||||||
<TaxRateAmount>{taxRate.rate}%</TaxRateAmount>
|
<TaxRateAmount>{taxRate.rate}%</TaxRateAmount>
|
||||||
<TaxRateActiveTag round={false} intent={Intent.SUCCESS} minimal>
|
{taxRate.active ? (
|
||||||
Active
|
<TaxRateActiveTag round={false} intent={Intent.SUCCESS} minimal>
|
||||||
</TaxRateActiveTag>
|
Active
|
||||||
|
</TaxRateActiveTag>
|
||||||
|
) : (
|
||||||
|
<TaxRateActiveTag round={false} intent={Intent.NONE} minimal>
|
||||||
|
Inactive
|
||||||
|
</TaxRateActiveTag>
|
||||||
|
)}
|
||||||
</TaxRateHeader>
|
</TaxRateHeader>
|
||||||
<DetailsMenu direction={'horizantal'} minLabelSize={200}>
|
<DetailsMenu direction={'horizantal'} minLabelSize={200}>
|
||||||
<DetailItem label={'Tax Rate Name'} children={taxRate.name} />
|
<DetailItem label={'Tax Rate Name'} children={taxRate.name} />
|
||||||
|
|||||||
Reference in New Issue
Block a user