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

@@ -26,12 +26,14 @@ import withEstimates from './withEstimates';
import withEstimatesActions from './withEstimatesActions';
import withSettings from '@/containers/Settings/withSettings';
import withSettingsActions from '@/containers/Settings/withSettingsActions';
import withDialogActions from '@/containers/Dialog/withDialogActions';
import { useEstimatesListContext } from './EstimatesListProvider';
import { useRefreshEstimates } from '@/hooks/query/estimates';
import { useResourceExportPdf } from '@/hooks/query/FinancialReports/use-export-pdf';
import { SaleEstimateAction, AbilitySubject } from '@/constants/abilityOption';
import { compose } from '@/utils';
import withDialogActions from '@/containers/Dialog/withDialogActions';
import { DialogsName } from '@/constants/dialogs';
/**
@@ -58,6 +60,10 @@ function EstimateActionsBar({
// Estimates list context.
const { estimatesViews, fields } = useEstimatesListContext();
// Exports the given resource into pdf.
const { mutateAsync: exportPdf, isLoading: isExportPdfLoading } =
useResourceExportPdf();
// Handle click a new sale estimate.
const onClickNewEstimate = () => {
history.push('/estimates/new');
@@ -71,17 +77,14 @@ function EstimateActionsBar({
viewSlug: view ? view.slug : null,
});
};
// Handle click a refresh sale estimates
const handleRefreshBtnClick = () => {
refresh();
};
// Handle table row size change.
const handleTableRowSizeChange = (size) => {
addSetting('salesEstimates', 'tableSize', size);
};
// Handle the import button click.
const handleImportBtnClick = () => {
history.push('/estimates/import');
@@ -90,6 +93,10 @@ function EstimateActionsBar({
const handleExportBtnClick = () => {
openDialog(DialogsName.Export, { resource: 'sale_estimate' });
};
// Handles the print button click.
const handlePrintBtnClick = () => {
exportPdf({ resource: 'SaleEstimate' });
};
return (
<DashboardActionsBar>
@@ -138,8 +145,9 @@ function EstimateActionsBar({
className={Classes.MINIMAL}
icon={<Icon icon={'print-16'} iconSize={'16'} />}
text={<T id={'print'} />}
onClick={handlePrintBtnClick}
disabled={isExportPdfLoading}
/>
<Button
className={Classes.MINIMAL}
icon={<Icon icon={'file-import-16'} />}
@@ -180,5 +188,5 @@ export default compose(
withSettings(({ estimatesSettings }) => ({
estimatesTableSize: estimatesSettings?.tableSize,
})),
withDialogActions
withDialogActions,
)(EstimateActionsBar);