diff --git a/packages/server/src/services/Accounts/AccountsExportable.ts b/packages/server/src/services/Accounts/AccountsExportable.ts index c3c24e352..86a6293d8 100644 --- a/packages/server/src/services/Accounts/AccountsExportable.ts +++ b/packages/server/src/services/Accounts/AccountsExportable.ts @@ -20,6 +20,8 @@ export class AccountsExportable extends Exportable { inactiveMode: false, ...query, structure: IAccountsStructureType.Flat, + pageSize: 12000, + page: 1, } as IAccountsFilter; return this.accountsApplication diff --git a/packages/webapp/src/components/DialogsContainer.tsx b/packages/webapp/src/components/DialogsContainer.tsx index fc1195545..02f18d071 100644 --- a/packages/webapp/src/components/DialogsContainer.tsx +++ b/packages/webapp/src/components/DialogsContainer.tsx @@ -51,6 +51,7 @@ import EstimateMailDialog from '@/containers/Sales/Estimates/EstimateMailDialog/ import ReceiptMailDialog from '@/containers/Sales/Receipts/ReceiptMailDialog/ReceiptMailDialog'; import PaymentMailDialog from '@/containers/Sales/PaymentReceives/PaymentMailDialog/PaymentMailDialog'; import { ConnectBankDialog } from '@/containers/CashFlow/ConnectBankDialog'; +import { ExportDialog } from '@/containers/Dialogs/ExportDialog'; /** * Dialogs container. @@ -148,6 +149,8 @@ export default function DialogsContainer() { + + ); } diff --git a/packages/webapp/src/constants/dialogs.ts b/packages/webapp/src/constants/dialogs.ts index 34d30bd46..cd425ce58 100644 --- a/packages/webapp/src/constants/dialogs.ts +++ b/packages/webapp/src/constants/dialogs.ts @@ -73,5 +73,6 @@ export enum DialogsName { CustomerTransactionsPdfPreview = 'CustomerTransactionsPdfPreview', VendorTransactionsPdfPreview = 'VendorTransactionsPdfPreview', GeneralLedgerPdfPreview = 'GeneralLedgerPdfPreview', - SalesTaxLiabilitySummaryPdfPreview = 'SalesTaxLiabilitySummaryPdfPreview' + SalesTaxLiabilitySummaryPdfPreview = 'SalesTaxLiabilitySummaryPdfPreview', + Export = 'Export', } diff --git a/packages/webapp/src/containers/Accounting/JournalsLanding/ManualJournalActionsBar.tsx b/packages/webapp/src/containers/Accounting/JournalsLanding/ManualJournalActionsBar.tsx index 676322da1..c6a8c447a 100644 --- a/packages/webapp/src/containers/Accounting/JournalsLanding/ManualJournalActionsBar.tsx +++ b/packages/webapp/src/containers/Accounting/JournalsLanding/ManualJournalActionsBar.tsx @@ -18,7 +18,7 @@ import { Can, If, DashboardActionViewsList, - DashboardActionsBar + DashboardActionsBar, } from '@/components'; import { useRefreshJournals } from '@/hooks/query/manualJournals'; import { useManualJournalsContext } from './ManualJournalsListProvider'; @@ -31,6 +31,7 @@ import withSettingsActions from '@/containers/Settings/withSettingsActions'; import withDialogActions from '@/containers/Dialog/withDialogActions'; import { compose } from '@/utils'; +import { DialogsName } from '@/constants/dialogs'; /** * Manual journal actions bar. @@ -47,6 +48,9 @@ function ManualJournalActionsBar({ // #withSettingsActions addSetting, + + // #withDialogActions + openDialog }) { // History context. const history = useHistory(); @@ -75,13 +79,18 @@ function ManualJournalActionsBar({ // Handle import button click. const handleImportBtnClick = () => { history.push('/manual-journals/import'); - } + }; // Handle table row size change. const handleTableRowSizeChange = (size) => { addSetting('manualJournals', 'tableSize', size); }; + // Handle the export button click. + const handleExportBtnClick = () => { + openDialog(DialogsName.Export, { resource: 'manual_journal' }); + }; + return ( @@ -140,6 +149,7 @@ function ManualJournalActionsBar({ className={Classes.MINIMAL} icon={} text={} + onClick={handleExportBtnClick} /> { history.push('/accounts/import'); }; + // Handle the export button click. + const handleExportBtnClick = () => { + openDialog(DialogsName.Export, { resource: 'account' }); + } return ( @@ -186,6 +190,7 @@ function AccountsActionsBar({ className={Classes.MINIMAL} icon={} text={} + onClick={handleExportBtnClick} /> + + + ); +} diff --git a/packages/webapp/src/containers/Dialogs/ExportDialog/constants.ts b/packages/webapp/src/containers/Dialogs/ExportDialog/constants.ts new file mode 100644 index 000000000..b971a8433 --- /dev/null +++ b/packages/webapp/src/containers/Dialogs/ExportDialog/constants.ts @@ -0,0 +1,17 @@ +export const ExportResources = [ + { value: 'account', text: 'Accounts' }, + { value: 'item', text: 'Items' }, + { value: 'item_category', text: 'Item Categories' }, + { value: 'customer', text: 'Customers' }, + { value: 'vendor', text: 'Vendors' }, + { value: 'manual_journal', text: 'Manual Journal' }, + { value: 'expense', text: 'Expenses' }, + { value: 'sale_invoice', text: 'Invoices' }, + { value: 'sale_estimate', text: ' Estimates' }, + { value: 'sale_receipt', text: 'Receipts' }, + { value: 'payment_receive', text: 'Payments Received' }, + { value: 'credit_note', text: 'Credit Notes' }, + { value: 'bill', text: 'Bills' }, + { value: 'bill_payment', text: 'Bill Payments' }, + { value: 'vendor_credit', text: 'Vendor Credits' }, +]; diff --git a/packages/webapp/src/containers/Dialogs/ExportDialog/index.tsx b/packages/webapp/src/containers/Dialogs/ExportDialog/index.tsx new file mode 100644 index 000000000..2ca7e562a --- /dev/null +++ b/packages/webapp/src/containers/Dialogs/ExportDialog/index.tsx @@ -0,0 +1,31 @@ +// @ts-nocheck +import React, { lazy } from 'react'; +import { Dialog, DialogSuspense, FormattedMessage as T } from '@/components'; +import withDialogRedux from '@/components/DialogReduxConnect'; +import { compose } from '@/utils'; + +const ExportDialogContent = lazy(() => import('./ExportDialogContent')); + +// User form dialog. +function ExportDialogRoot({ dialogName, payload, isOpen }) { + const { resource = null, format = null } = payload; + + return ( + + + + + + ); +} + +export const ExportDialog = compose(withDialogRedux())(ExportDialogRoot); diff --git a/packages/webapp/src/containers/Dialogs/ExportDialog/type.ts b/packages/webapp/src/containers/Dialogs/ExportDialog/type.ts new file mode 100644 index 000000000..448c30cbc --- /dev/null +++ b/packages/webapp/src/containers/Dialogs/ExportDialog/type.ts @@ -0,0 +1,6 @@ + + +export interface ExportFormInitialValues { + resource?: string; + format?: string; +} \ No newline at end of file diff --git a/packages/webapp/src/containers/Expenses/ExpensesLanding/ExpenseActionsBar.tsx b/packages/webapp/src/containers/Expenses/ExpensesLanding/ExpenseActionsBar.tsx index e5c7368e4..1a1fb0209 100644 --- a/packages/webapp/src/containers/Expenses/ExpensesLanding/ExpenseActionsBar.tsx +++ b/packages/webapp/src/containers/Expenses/ExpensesLanding/ExpenseActionsBar.tsx @@ -33,6 +33,7 @@ import withDialogActions from '@/containers/Dialog/withDialogActions'; import withSettings from '@/containers/Settings/withSettings'; import { compose } from '@/utils'; +import { DialogsName } from '@/constants/dialogs'; /** * Expenses actions bar. @@ -49,6 +50,9 @@ function ExpensesActionsBar({ // #withSettingsActions addSetting, + + // #withDialogActions + openDialog, }) { // History context. const history = useHistory(); @@ -63,7 +67,6 @@ function ExpensesActionsBar({ const onClickNewExpense = () => { history.push('/expenses/new'); }; - // Handle delete button click. const handleBulkDelete = () => {}; @@ -73,21 +76,23 @@ function ExpensesActionsBar({ viewSlug: view ? view.slug : null, }); }; - // Handle click a refresh const handleRefreshBtnClick = () => { refresh(); }; - // Handle the import button click. const handleImportBtnClick = () => { history.push('/expenses/import'); - } - + }; // Handle table row size change. const handleTableRowSizeChange = (size) => { addSetting('expenses', 'tableSize', size); }; + // Handle the export button click. + const handleExportBtnClick = () => { + openDialog(DialogsName.Export, { resource: 'expense' }); + }; + return ( @@ -146,6 +151,7 @@ function ExpensesActionsBar({ className={Classes.MINIMAL} icon={} text={} + onClick={handleExportBtnClick} /> { + openDialog(DialogsName.Export, { resource: 'item' }); + } + return ( @@ -154,6 +164,7 @@ function ItemsActionsBar({ className={Classes.MINIMAL} icon={} text={} + onClick={handleExportBtnClick} /> { + openDialog(DialogsName.Export, { resource: 'item_category' }); + }; return ( @@ -105,6 +110,7 @@ function ItemsCategoryActionsBar({ className={Classes.MINIMAL} icon={} text={} + onClick={handleExportBtnClick} /> diff --git a/packages/webapp/src/containers/Purchases/Bills/BillsLanding/BillsActionsBar.tsx b/packages/webapp/src/containers/Purchases/Bills/BillsLanding/BillsActionsBar.tsx index da5415e45..3d0fbb2ff 100644 --- a/packages/webapp/src/containers/Purchases/Bills/BillsLanding/BillsActionsBar.tsx +++ b/packages/webapp/src/containers/Purchases/Bills/BillsLanding/BillsActionsBar.tsx @@ -32,6 +32,8 @@ import withSettingsActions from '@/containers/Settings/withSettingsActions'; import { useBillsListContext } from './BillsListProvider'; import { useRefreshBills } from '@/hooks/query/bills'; import { compose } from '@/utils'; +import withDialogActions from '@/containers/Dialog/withDialogActions'; +import { DialogsName } from '@/constants/dialogs'; /** * Bills actions bar. @@ -48,6 +50,9 @@ function BillActionsBar({ // #withSettingsActions addSetting, + + // #withDialogActions + openDialog, }) { const history = useHistory(); @@ -81,7 +86,12 @@ function BillActionsBar({ // Handle the import button click. const handleImportBtnClick = () => { history.push('/bills/import'); - } + }; + + // Handle the export button click. + const handleExportBtnClick = () => { + openDialog(DialogsName.Export, { resource: 'bill' }); + }; return ( @@ -141,6 +151,7 @@ function BillActionsBar({ className={Classes.MINIMAL} icon={} text={} + onClick={handleExportBtnClick} /> @@ -170,4 +181,5 @@ export default compose( withSettings(({ billsettings }) => ({ billsTableSize: billsettings?.tableSize, })), + withDialogActions, )(BillActionsBar); diff --git a/packages/webapp/src/containers/Purchases/CreditNotes/CreditNotesLanding/VendorsCreditNoteActionsBar.tsx b/packages/webapp/src/containers/Purchases/CreditNotes/CreditNotesLanding/VendorsCreditNoteActionsBar.tsx index e4a7b1ff9..7ba8e7531 100644 --- a/packages/webapp/src/containers/Purchases/CreditNotes/CreditNotesLanding/VendorsCreditNoteActionsBar.tsx +++ b/packages/webapp/src/containers/Purchases/CreditNotes/CreditNotesLanding/VendorsCreditNoteActionsBar.tsx @@ -22,14 +22,16 @@ import { import { useVendorsCreditNoteListContext } from './VendorsCreditNoteListProvider'; import { VendorCreditAction, AbilitySubject } from '@/constants/abilityOption'; + +import withVendorsCreditNotesActions from './withVendorsCreditNotesActions'; import withSettings from '@/containers/Settings/withSettings'; import withSettingsActions from '@/containers/Settings/withSettingsActions'; import withVendorsCreditNotes from './withVendorsCreditNotes'; -import withVendorsCreditNotesActions from './withVendorsCreditNotesActions'; - +import withDialogActions from '@/containers/Dialog/withDialogActions'; import withVendorActions from './withVendorActions'; import { compose } from '@/utils'; +import { DialogsName } from '@/constants/dialogs'; /** * Vendors Credit note table actions bar. @@ -48,6 +50,9 @@ function VendorsCreditNoteActionsBar({ // #withSettingsActions addSetting, + + // #withDialogActions + openDialog, }) { const history = useHistory(); @@ -77,8 +82,13 @@ function VendorsCreditNoteActionsBar({ // Handle import button click. const handleImportBtnClick = () => { - history.push('/vendor-credits/import') - } + history.push('/vendor-credits/import'); + }; + + // Handle the export button click. + const handleExportBtnClick = () => { + openDialog(DialogsName.Export, { resource: 'vendor_credit' }); + }; return ( @@ -128,6 +138,7 @@ function VendorsCreditNoteActionsBar({ className={Classes.MINIMAL} icon={} text={} + onClick={handleExportBtnClick} /> ({ creditNoteTableSize: vendorsCreditNoteSetting?.tableSize, })), + withDialogActions, )(VendorsCreditNoteActionsBar); diff --git a/packages/webapp/src/containers/Purchases/PaymentMades/PaymentsLanding/PaymentMadeActionsBar.tsx b/packages/webapp/src/containers/Purchases/PaymentMades/PaymentsLanding/PaymentMadeActionsBar.tsx index 1d7e3d67d..f269f63ed 100644 --- a/packages/webapp/src/containers/Purchases/PaymentMades/PaymentsLanding/PaymentMadeActionsBar.tsx +++ b/packages/webapp/src/containers/Purchases/PaymentMades/PaymentsLanding/PaymentMadeActionsBar.tsx @@ -33,6 +33,8 @@ import { useRefreshPaymentMades } from '@/hooks/query/paymentMades'; import { PaymentMadeAction, AbilitySubject } from '@/constants/abilityOption'; import { compose } from '@/utils'; +import withDialogActions from '@/containers/Dialog/withDialogActions'; +import { DialogsName } from '@/constants/dialogs'; /** * Payment made actions bar. @@ -47,6 +49,9 @@ function PaymentMadeActionsBar({ // #withSettings paymentMadesTableSize, + // #withDialogActions + openDialog, + // #withSettingsActions addSetting, }) { @@ -81,7 +86,12 @@ function PaymentMadeActionsBar({ // Handle the import button click. const handleImportBtnClick = () => { history.push('/payment-mades/import'); - } + }; + + // Handle the export button click. + const handleExportBtnClick = () => { + openDialog(DialogsName.Export, { resource: 'bill_payment' }); + }; return ( @@ -139,6 +149,7 @@ function PaymentMadeActionsBar({ className={Classes.MINIMAL} icon={} text={} + onClick={handleExportBtnClick} /> @@ -168,4 +179,5 @@ export default compose( withSettings(({ billPaymentSettings }) => ({ paymentMadesTableSize: billPaymentSettings?.tableSize, })), + withDialogActions, )(PaymentMadeActionsBar); diff --git a/packages/webapp/src/containers/Sales/CreditNotes/CreditNotesLanding/CreditNotesActionsBar.tsx b/packages/webapp/src/containers/Sales/CreditNotes/CreditNotesLanding/CreditNotesActionsBar.tsx index 7c8294858..7e55e6a13 100644 --- a/packages/webapp/src/containers/Sales/CreditNotes/CreditNotesLanding/CreditNotesActionsBar.tsx +++ b/packages/webapp/src/containers/Sales/CreditNotes/CreditNotesLanding/CreditNotesActionsBar.tsx @@ -25,8 +25,10 @@ import withCreditNotes from './withCreditNotes'; import withCreditNotesActions from './withCreditNotesActions'; 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'; /** * Credit note table actions bar. @@ -43,6 +45,9 @@ function CreditNotesActionsBar({ // #withSettingsActions addSetting, + + // #withDialogActions + openDialog, }) { const history = useHistory(); @@ -74,6 +79,11 @@ function CreditNotesActionsBar({ history.push('/credit-notes/import'); }; + // Handle the export button click. + const handleExportBtnClick = () => { + openDialog(DialogsName.Export, { resource: 'credit_note' }); + }; + return ( @@ -122,6 +132,7 @@ function CreditNotesActionsBar({ className={Classes.MINIMAL} icon={} text={} + onClick={handleExportBtnClick} /> ({ creditNoteTableSize: creditNoteSettings?.tableSize, })), + withDialogActions, )(CreditNotesActionsBar); diff --git a/packages/webapp/src/containers/Sales/Estimates/EstimatesLanding/EstimatesActionsBar.tsx b/packages/webapp/src/containers/Sales/Estimates/EstimatesLanding/EstimatesActionsBar.tsx index ff4f5d6bd..2b374d2db 100644 --- a/packages/webapp/src/containers/Sales/Estimates/EstimatesLanding/EstimatesActionsBar.tsx +++ b/packages/webapp/src/containers/Sales/Estimates/EstimatesLanding/EstimatesActionsBar.tsx @@ -31,6 +31,8 @@ import { useEstimatesListContext } from './EstimatesListProvider'; import { useRefreshEstimates } from '@/hooks/query/estimates'; import { SaleEstimateAction, AbilitySubject } from '@/constants/abilityOption'; import { compose } from '@/utils'; +import withDialogActions from '@/containers/Dialog/withDialogActions'; +import { DialogsName } from '@/constants/dialogs'; /** * Estimates list actions bar. @@ -45,6 +47,9 @@ function EstimateActionsBar({ // #withSettings estimatesTableSize, + // #withDialogActions + openDialog, + // #withSettingsActions addSetting, }) { @@ -80,7 +85,11 @@ function EstimateActionsBar({ // Handle the import button click. const handleImportBtnClick = () => { history.push('/estimates/import'); - } + }; + // Handle the export button click. + const handleExportBtnClick = () => { + openDialog(DialogsName.Export, { resource: 'sale_estimate' }); + }; return ( @@ -141,6 +150,7 @@ function EstimateActionsBar({ className={Classes.MINIMAL} icon={} text={} + onClick={handleExportBtnClick} /> ({ estimatesTableSize: estimatesSettings?.tableSize, })), + withDialogActions )(EstimateActionsBar); diff --git a/packages/webapp/src/containers/Sales/Invoices/InvoicesLanding/InvoicesActionsBar.tsx b/packages/webapp/src/containers/Sales/Invoices/InvoicesLanding/InvoicesActionsBar.tsx index cdfa295a3..8f4a4d686 100644 --- a/packages/webapp/src/containers/Sales/Invoices/InvoicesLanding/InvoicesActionsBar.tsx +++ b/packages/webapp/src/containers/Sales/Invoices/InvoicesLanding/InvoicesActionsBar.tsx @@ -29,6 +29,8 @@ import withInvoiceActions from './withInvoiceActions'; import withSettings from '@/containers/Settings/withSettings'; import withSettingsActions from '@/containers/Settings/withSettingsActions'; import { compose } from '@/utils'; +import withDialogActions from '@/containers/Dialog/withDialogActions'; +import { DialogsName } from '@/constants/dialogs'; /** * Invoices table actions bar. @@ -45,6 +47,9 @@ function InvoiceActionsBar({ // #withSettingsActions addSetting, + + // #withDialogsActions + openDialog }) { const history = useHistory(); @@ -79,6 +84,11 @@ function InvoiceActionsBar({ history.push('/invoices/import'); }; + // Handle the export button click. + const handleExportBtnClick = () => { + openDialog(DialogsName.Export, { resource: 'sale_invoice' }); + }; + return ( @@ -135,6 +145,7 @@ function InvoiceActionsBar({ className={Classes.MINIMAL} icon={} text={} + onClick={handleExportBtnClick} /> ({ invoicesTableSize: invoiceSettings?.tableSize, })), + withDialogActions, )(InvoiceActionsBar); diff --git a/packages/webapp/src/containers/Sales/PaymentReceives/PaymentsLanding/PaymentReceiveActionsBar.tsx b/packages/webapp/src/containers/Sales/PaymentReceives/PaymentsLanding/PaymentReceiveActionsBar.tsx index c1d510c1d..42bf63666 100644 --- a/packages/webapp/src/containers/Sales/PaymentReceives/PaymentsLanding/PaymentReceiveActionsBar.tsx +++ b/packages/webapp/src/containers/Sales/PaymentReceives/PaymentsLanding/PaymentReceiveActionsBar.tsx @@ -26,6 +26,7 @@ import withPaymentReceives from './withPaymentReceives'; import withPaymentReceivesActions from './withPaymentReceivesActions'; import withSettings from '@/containers/Settings/withSettings'; import withSettingsActions from '@/containers/Settings/withSettingsActions'; +import withDialogActions from '@/containers/Dialog/withDialogActions'; import { PaymentReceiveAction, AbilitySubject, @@ -33,6 +34,7 @@ import { import { usePaymentReceivesListContext } from './PaymentReceiptsListProvider'; import { useRefreshPaymentReceive } from '@/hooks/query/paymentReceives'; import { compose } from '@/utils'; +import { DialogsName } from '@/constants/dialogs'; /** * Payment receives actions bar. @@ -49,6 +51,9 @@ function PaymentReceiveActionsBar({ // #withSettingsActions addSetting, + + // #withDialogActions + openDialog, }) { // History context. const history = useHistory(); @@ -82,6 +87,10 @@ function PaymentReceiveActionsBar({ const handleImportBtnClick = () => { history.push('/payment-receives/import'); }; + // Handle the export button click. + const handleExportBtnClick = () => { + openDialog(DialogsName.Export, { resource: 'payment_receive' }); + }; return ( @@ -139,6 +148,7 @@ function PaymentReceiveActionsBar({ className={Classes.MINIMAL} icon={} text={} + onClick={handleExportBtnClick} /> @@ -169,4 +179,5 @@ export default compose( withSettings(({ paymentReceiveSettings }) => ({ paymentReceivesTableSize: paymentReceiveSettings?.tableSize, })), + withDialogActions, )(PaymentReceiveActionsBar); diff --git a/packages/webapp/src/containers/Sales/Receipts/ReceiptsLanding/ReceiptActionsBar.tsx b/packages/webapp/src/containers/Sales/Receipts/ReceiptsLanding/ReceiptActionsBar.tsx index f27a505c9..f4ecfe39f 100644 --- a/packages/webapp/src/containers/Sales/Receipts/ReceiptsLanding/ReceiptActionsBar.tsx +++ b/packages/webapp/src/containers/Sales/Receipts/ReceiptsLanding/ReceiptActionsBar.tsx @@ -35,6 +35,8 @@ import { useRefreshReceipts } from '@/hooks/query/receipts'; import { SaleReceiptAction, AbilitySubject } from '@/constants/abilityOption'; import { compose } from '@/utils'; +import withDialogActions from '@/containers/Dialog/withDialogActions'; +import { DialogsName } from '@/constants/dialogs'; /** * Receipts actions bar. @@ -49,6 +51,9 @@ function ReceiptActionsBar({ // #withSettings receiptsTableSize, + // #withDialogActions + openDialog, + // #withSettingsActions addSetting, }) { @@ -86,6 +91,11 @@ function ReceiptActionsBar({ history.push('/receipts/import'); }; + // Handle the export button click. + const handleExportBtnClick = () => { + openDialog(DialogsName.Export, { resource: 'sale_receipt' }); + }; + return ( @@ -145,6 +155,7 @@ function ReceiptActionsBar({ className={Classes.MINIMAL} icon={} text={} + onClick={handleExportBtnClick} /> ({ receiptsTableSize: receiptSettings?.tableSize, })), + withDialogActions, )(ReceiptActionsBar); diff --git a/packages/webapp/src/containers/Vendors/VendorsLanding/VendorActionsBar.tsx b/packages/webapp/src/containers/Vendors/VendorsLanding/VendorActionsBar.tsx index bd54a6b16..86c11ea8a 100644 --- a/packages/webapp/src/containers/Vendors/VendorsLanding/VendorActionsBar.tsx +++ b/packages/webapp/src/containers/Vendors/VendorsLanding/VendorActionsBar.tsx @@ -31,8 +31,10 @@ import withVendors from './withVendors'; import withVendorsActions from './withVendorsActions'; 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'; /** * Vendors actions bar. @@ -50,6 +52,9 @@ function VendorActionsBar({ // #withSettingsActions addSetting, + + // #withDialogActions + openDialog, }) { const history = useHistory(); @@ -83,10 +88,17 @@ function VendorActionsBar({ const handleTableRowSizeChange = (size) => { addSetting('vendors', 'tableSize', size); }; + // Handle import button success. const handleImportBtnSuccess = () => { history.push('/vendors/import'); }; + + // Handle the export button click. + const handleExportBtnClick = () => { + openDialog(DialogsName.Export, { resource: 'vendor' }); + }; + return ( @@ -138,6 +150,7 @@ function VendorActionsBar({ className={Classes.MINIMAL} icon={} text={} + onClick={handleExportBtnClick} /> ({ vendorsTableSize: vendorsSettings?.tableSize, })), + withDialogActions, )(VendorActionsBar); diff --git a/packages/webapp/src/hooks/query/FinancialReports/use-export.ts b/packages/webapp/src/hooks/query/FinancialReports/use-export.ts new file mode 100644 index 000000000..63e1e5d74 --- /dev/null +++ b/packages/webapp/src/hooks/query/FinancialReports/use-export.ts @@ -0,0 +1,38 @@ +// @ts-nocheck +import { downloadFile } from '@/hooks/useDownloadFile'; +import useApiRequest from '@/hooks/useRequest'; +import { AxiosError } from 'axios'; +import { useMutation } from 'react-query'; + +interface ResourceExportValues { + resource: string; + format: string; +} +/** + * Initiates a download of the balance sheet in XLSX format. + * @param {Object} query - The query parameters for the request. + * @param {Object} args - Additional configurations for the download. + * @returns {Function} A function to trigger the file download. + */ +export const useResourceExport = () => { + const apiRequest = useApiRequest(); + + return useMutation((data: ResourceExportValues) => { + return apiRequest + .get('/export', { + responseType: 'blob', + headers: { + accept: + data.format === 'xlsx' ? 'application/xlsx' : 'application/csv', + }, + params: { + resource: data.resource, + format: data.format, + }, + }) + .then((res) => { + downloadFile(res.data, `${data.resource}.${data.format}`); + return res; + }); + }); +};