feat(webapp): wip tax rates management

This commit is contained in:
Ahmed Bouhuolia
2023-09-14 23:35:54 +02:00
parent b98b73ad98
commit 8a64198433
34 changed files with 1205 additions and 14 deletions

View File

@@ -0,0 +1,97 @@
// @ts-nocheck
import React from 'react';
import intl from 'react-intl-universal';
import { Intent, Alert } from '@blueprintjs/core';
import {
AppToaster,
FormattedMessage as T,
FormattedHTMLMessage,
} from '@/components';
import { useDeleteTaxRate } from '@/hooks/query/taxRates';
import withAlertStoreConnect from '@/containers/Alert/withAlertStoreConnect';
import withAlertActions from '@/containers/Alert/withAlertActions';
import withItemsActions from '@/containers/Items/withItemsActions';
import withDrawerActions from '@/containers/Drawer/withDrawerActions';
import { compose } from '@/utils';
import { DRAWERS } from '@/constants/drawers';
/**
* Item delete alerts.
*/
function TaxRateDeleteAlert({
name,
// #withAlertStoreConnect
isOpen,
payload: { taxRateId },
// #withAlertActions
closeAlert,
// #withDrawerActions
closeDrawer,
}) {
const { mutateAsync: deleteTaxRate, isLoading } = useDeleteTaxRate();
// Handle cancel delete item alert.
const handleCancelItemDelete = () => {
closeAlert(name);
};
// Handle confirm delete item.
const handleConfirmDeleteItem = () => {
deleteTaxRate(taxRateId)
.then(() => {
AppToaster.show({
message: 'The tax rate has been deleted successfully.',
intent: Intent.SUCCESS,
});
closeDrawer(DRAWERS.TAX_RATE_DETAILS);
})
.catch(
({
response: {
data: { errors },
},
}) => {
// handleDeleteErrors(errors);
},
)
.finally(() => {
closeAlert(name);
});
};
return (
<Alert
cancelButtonText={<T id={'cancel'} />}
confirmButtonText={<T id={'delete'} />}
icon="trash"
intent={Intent.DANGER}
isOpen={isOpen}
onCancel={handleCancelItemDelete}
onConfirm={handleConfirmDeleteItem}
loading={isLoading}
>
<p>
Once you delete this tax rate, you won't be able to restore the item
later.
</p>
<p>
Are you sure you want to delete ? If you're not sure, you can inactivate
it instead.
</p>
</Alert>
);
}
export default compose(
withAlertStoreConnect(),
withAlertActions,
withItemsActions,
withDrawerActions,
)(TaxRateDeleteAlert);

View File

@@ -0,0 +1,11 @@
// @ts-nocheck
import React from 'react';
const TaxRateDeleteAlert = React.lazy(() => import('./TaxRateDeleteAlert'));
/**
* Project alerts.
*/
export default [
{ name: 'tax-rate-delete', component: TaxRateDeleteAlert },
];