feat: print action when click on print button

This commit is contained in:
Ahmed Bouhuolia
2024-05-23 19:39:23 +02:00
parent fe41f7976d
commit dc5bdf0b66
16 changed files with 239 additions and 64 deletions

View File

@@ -20,6 +20,8 @@ import {
} from '@/components';
import { useCreditNoteListContext } from './CreditNotesListProvider';
import { useResourceExportPdf } from '@/hooks/query/FinancialReports/use-export-pdf';
import { CreditNoteAction, AbilitySubject } from '@/constants/abilityOption';
import withCreditNotes from './withCreditNotes';
import withCreditNotesActions from './withCreditNotesActions';
@@ -27,8 +29,8 @@ import withSettings from '@/containers/Settings/withSettings';
import withSettingsActions from '@/containers/Settings/withSettingsActions';
import withDialogActions from '@/containers/Dialog/withDialogActions';
import { compose } from '@/utils';
import { DialogsName } from '@/constants/dialogs';
import { compose } from '@/utils';
/**
* Credit note table actions bar.
@@ -54,6 +56,10 @@ function CreditNotesActionsBar({
// credit note list context.
const { CreditNotesView, fields, refresh } = useCreditNoteListContext();
// Exports the given resource into pdf.
const { mutateAsync: exportPdf, isLoading: isExportPdfLoading } =
useResourceExportPdf();
// Handle view tab change.
const handleTabChange = (view) => {
setCreditNotesTableState({ viewSlug: view ? view.slug : null });
@@ -68,21 +74,22 @@ function CreditNotesActionsBar({
const handleRefreshBtnClick = () => {
refresh();
};
// Handle table row size change.
const handleTableRowSizeChange = (size) => {
addSetting('creditNote', 'tableSize', size);
};
// Handle import button click.
const handleImportBtnClick = () => {
history.push('/credit-notes/import');
};
// Handle the export button click.
const handleExportBtnClick = () => {
openDialog(DialogsName.Export, { resource: 'credit_note' });
};
// Handle print button click.
const handlePrintBtnClick = () => {
exportPdf({ resource: 'CreditNote' });
};
return (
<DashboardActionsBar>
@@ -121,6 +128,7 @@ function CreditNotesActionsBar({
className={Classes.MINIMAL}
icon={<Icon icon={'print-16'} iconSize={'16'} />}
text={<T id={'print'} />}
onClick={handlePrintBtnClick}
/>
<Button
className={Classes.MINIMAL}
@@ -133,6 +141,7 @@ function CreditNotesActionsBar({
icon={<Icon icon={'file-export-16'} iconSize={'16'} />}
text={<T id={'export'} />}
onClick={handleExportBtnClick}
disabled={isExportPdfLoading}
/>
<NavbarDivider />
<DashboardRowsHeightButton