This commit is contained in:
Ahmed Bouhuolia
2025-11-17 22:26:33 +02:00
parent 2c64e1b8ab
commit 17bcc14231
11 changed files with 210 additions and 5 deletions

View File

@@ -0,0 +1,68 @@
// @ts-nocheck
import React from 'react';
import { FormattedMessage as T } from '@/components';
import intl from 'react-intl-universal';
import { Intent, Alert } from '@blueprintjs/core';
import { queryCache } from 'react-query';
import { AppToaster } from '@/components';
import { useBulkDeleteReceipts } from '@/hooks/query/receipts';
import withAlertStoreConnect from '@/containers/Alert/withAlertStoreConnect';
import withAlertActions from '@/containers/Alert/withAlertActions';
import { compose } from '@/utils';
/**
* Receipt bulk delete alert.
*/
function ReceiptBulkDeleteAlert({
name,
isOpen,
payload: { receiptsIds },
closeAlert,
}) {
const { mutateAsync: bulkDeleteReceipts, isLoading } = useBulkDeleteReceipts();
const handleCancel = () => {
closeAlert(name);
};
const handleConfirmBulkDelete = () => {
bulkDeleteReceipts(receiptsIds)
.then(() => {
AppToaster.show({
message: intl.get('the_receipts_has_been_deleted_successfully'),
intent: Intent.SUCCESS,
});
queryCache.invalidateQueries('sale-receipts-table');
closeAlert(name);
})
.catch((errors) => {
// Handle errors
});
};
return (
<Alert
cancelButtonText={<T id={'cancel'} />}
confirmButtonText={
<T id={'delete_count'} values={{ count: receiptsIds?.length || 0 }} />
}
icon="trash"
intent={Intent.DANGER}
isOpen={isOpen}
onCancel={handleCancel}
onConfirm={handleConfirmBulkDelete}
loading={isLoading}
>
<p>
<T id={'once_delete_these_receipts_you_will_not_able_restore_them'} />
</p>
</Alert>
);
}
export default compose(
withAlertStoreConnect(),
withAlertActions,
)(ReceiptBulkDeleteAlert);

View File

@@ -29,6 +29,7 @@ import withBillsActions from './withBillsActions';
import withSettings from '@/containers/Settings/withSettings';
import withSettingsActions from '@/containers/Settings/withSettingsActions';
import withDialogActions from '@/containers/Dialog/withDialogActions';
import withAlertActions from '@/containers/Alert/withAlertActions';
import { useBillsListContext } from './BillsListProvider';
import { useRefreshBills } from '@/hooks/query/bills';
@@ -57,6 +58,9 @@ function BillActionsBar({
// #withDialogActions
openDialog,
// #withAlertActions
openAlert,
}) {
const history = useHistory();
@@ -210,4 +214,5 @@ export default compose(
billsTableSize: billsettings?.tableSize,
})),
withDialogActions,
withAlertActions,
)(BillActionsBar);

View File

@@ -6,6 +6,7 @@ import {
NavbarDivider,
NavbarGroup,
Alignment,
Intent,
Menu,
MenuItem,
Popover,
@@ -13,6 +14,7 @@ import {
Position,
} from '@blueprintjs/core';
import { useHistory } from 'react-router-dom';
import { isEmpty } from 'lodash';
import {
Icon,
Can,
@@ -34,6 +36,7 @@ import withSettings from '@/containers/Settings/withSettings';
import withSettingsActions from '@/containers/Settings/withSettingsActions';
import withDialogActions from '@/containers/Dialog/withDialogActions';
import withDrawerActions from '@/containers/Drawer/withDrawerActions';
import withAlertActions from '@/containers/Alert/withAlertActions';
import { DialogsName } from '@/constants/dialogs';
import { compose } from '@/utils';
@@ -45,6 +48,7 @@ import { DRAWERS } from '@/constants/drawers';
function CreditNotesActionsBar({
// #withCreditNotes
creditNoteFilterRoles,
creditNotesSelectedRows,
// #withCreditNotesActions
setCreditNotesTableState,
@@ -59,7 +63,10 @@ function CreditNotesActionsBar({
openDialog,
// #withDrawerActions
openDrawer
openDrawer,
// #withAlertActions
openAlert,
}) {
const history = useHistory();
@@ -104,6 +111,26 @@ function CreditNotesActionsBar({
openDrawer(DRAWERS.BRANDING_TEMPLATES, { resource: 'CreditNote' });
}
// Show bulk delete button when rows are selected.
if (!isEmpty(creditNotesSelectedRows)) {
const handleBulkDelete = () => {
openAlert('credit-notes-bulk-delete', { creditNotesIds: creditNotesSelectedRows });
};
return (
<DashboardActionsBar>
<NavbarGroup>
<Button
className={Classes.MINIMAL}
icon={<Icon icon="trash-16" iconSize={16} />}
text={<T id={'delete'} />}
intent={Intent.DANGER}
onClick={handleBulkDelete}
/>
</NavbarGroup>
</DashboardActionsBar>
);
}
return (
<DashboardActionsBar>
<NavbarGroup>
@@ -195,12 +222,14 @@ function CreditNotesActionsBar({
export default compose(
withCreditNotesActions,
withSettingsActions,
withCreditNotes(({ creditNoteTableState }) => ({
withCreditNotes(({ creditNoteTableState, creditNotesSelectedRows }) => ({
creditNoteFilterRoles: creditNoteTableState.filterRoles,
creditNotesSelectedRows,
})),
withSettings(({ creditNoteSettings }) => ({
creditNoteTableSize: creditNoteSettings?.tableSize,
})),
withDialogActions,
withDrawerActions
withDrawerActions,
withAlertActions,
)(CreditNotesActionsBar);

View File

@@ -7,6 +7,9 @@ const ReceiptDeleteAlert = React.lazy(
const ReceiptCloseAlert = React.lazy(
() => import('@/containers/Alerts/Receipts/ReceiptCloseAlert'),
);
const ReceiptBulkDeleteAlert = React.lazy(
() => import('@/containers/Alerts/Receipts/ReceiptBulkDeleteAlert'),
);
/**
* Receipts alerts.
@@ -14,4 +17,5 @@ const ReceiptCloseAlert = React.lazy(
export default [
{ name: 'receipt-delete', component: ReceiptDeleteAlert },
{ name: 'receipt-close', component: ReceiptCloseAlert },
{ name: 'receipts-bulk-delete', component: ReceiptBulkDeleteAlert },
];

View File

@@ -35,6 +35,7 @@ import withReceiptsActions from './withReceiptsActions';
import withSettings from '@/containers/Settings/withSettings';
import withSettingsActions from '@/containers/Settings/withSettingsActions';
import withDialogActions from '@/containers/Dialog/withDialogActions';
import withAlertActions from '@/containers/Alert/withAlertActions';
import { useReceiptsListContext } from './ReceiptsListProvider';
import { useRefreshReceipts } from '@/hooks/query/receipts';
@@ -70,6 +71,9 @@ function ReceiptActionsBar({
// #withSettingsActions
addSetting,
// #withAlertActions
openAlert,
}) {
const history = useHistory();
@@ -250,4 +254,5 @@ export default compose(
})),
withDialogActions,
withDrawerActions,
withAlertActions,
)(ReceiptActionsBar);