@spaceinvoices/react-ui 0.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +340 -0
- package/cli/dist/index.js +922 -0
- package/package.json +87 -0
- package/registry.json +600 -0
- package/spaceinvoices.schema.json +47 -0
- package/src/app.tsx +25 -0
- package/src/common/autocomplete.tsx +135 -0
- package/src/components/activities/activity-timeline.tsx +160 -0
- package/src/components/activities/index.ts +1 -0
- package/src/components/activities/locales/de.ts +30 -0
- package/src/components/activities/locales/sl.ts +30 -0
- package/src/components/advance-invoices/advance-invoices.hooks.ts +75 -0
- package/src/components/advance-invoices/create/create-advance-invoice-form.tsx +702 -0
- package/src/components/advance-invoices/create/locales/de.ts +29 -0
- package/src/components/advance-invoices/create/locales/sl.ts +25 -0
- package/src/components/advance-invoices/create/prepare-advance-invoice-submission.ts +74 -0
- package/src/components/advance-invoices/index.ts +5 -0
- package/src/components/advance-invoices/list/index.ts +3 -0
- package/src/components/advance-invoices/list/list-row-actions.tsx +119 -0
- package/src/components/advance-invoices/list/list-table.tsx +178 -0
- package/src/components/advance-invoices/list/locales/de.ts +32 -0
- package/src/components/advance-invoices/list/locales/sl.ts +32 -0
- package/src/components/advance-invoices/list/use-advance-invoice-download.ts +63 -0
- package/src/components/button-loader.tsx +11 -0
- package/src/components/combobox.tsx +96 -0
- package/src/components/company-registry/company-registry-autocomplete.tsx +151 -0
- package/src/components/company-registry/company-registry.hooks.ts +67 -0
- package/src/components/company-registry/index.ts +7 -0
- package/src/components/credit-notes/create/create-credit-note-form.tsx +332 -0
- package/src/components/credit-notes/create/index.ts +1 -0
- package/src/components/credit-notes/create/locales/de.ts +69 -0
- package/src/components/credit-notes/create/locales/sl.ts +67 -0
- package/src/components/credit-notes/credit-notes.hooks.ts +22 -0
- package/src/components/credit-notes/index.ts +10 -0
- package/src/components/credit-notes/list/index.ts +3 -0
- package/src/components/credit-notes/list/list-row-actions.tsx +116 -0
- package/src/components/credit-notes/list/list-table.tsx +183 -0
- package/src/components/credit-notes/list/locales/de.ts +33 -0
- package/src/components/credit-notes/list/locales/sl.ts +33 -0
- package/src/components/credit-notes/list/use-credit-note-download.ts +65 -0
- package/src/components/customers/create-customer-form/create-customer-form.tsx +134 -0
- package/src/components/customers/create-customer-form/locales/de.ts +20 -0
- package/src/components/customers/create-customer-form/locales/sl.ts +20 -0
- package/src/components/customers/customer-autocomplete.tsx +173 -0
- package/src/components/customers/customer-combobox.tsx +130 -0
- package/src/components/customers/customer-list-table/customer-list-row-actions.tsx +48 -0
- package/src/components/customers/customer-list-table/customer-list-table.tsx +124 -0
- package/src/components/customers/customer-list-table/index.ts +2 -0
- package/src/components/customers/customer-list-table/locales/de.ts +16 -0
- package/src/components/customers/customer-list-table/locales/sl.ts +16 -0
- package/src/components/customers/customers.hooks.test.ts +348 -0
- package/src/components/customers/customers.hooks.ts +57 -0
- package/src/components/customers/index.ts +5 -0
- package/src/components/dashboard/chart-empty-state.tsx +29 -0
- package/src/components/dashboard/collection-rate-card/collection-rate-card.tsx +80 -0
- package/src/components/dashboard/collection-rate-card/index.ts +4 -0
- package/src/components/dashboard/collection-rate-card/locales/sl.ts +3 -0
- package/src/components/dashboard/collection-rate-card/use-collection-rate.ts +74 -0
- package/src/components/dashboard/index.ts +54 -0
- package/src/components/dashboard/invoice-status-chart/index.ts +4 -0
- package/src/components/dashboard/invoice-status-chart/invoice-status-chart.tsx +130 -0
- package/src/components/dashboard/invoice-status-chart/locales/sl.ts +9 -0
- package/src/components/dashboard/invoice-status-chart/use-invoice-status.ts +105 -0
- package/src/components/dashboard/loading-card.tsx +19 -0
- package/src/components/dashboard/payment-methods-chart/index.ts +4 -0
- package/src/components/dashboard/payment-methods-chart/locales/sl.ts +12 -0
- package/src/components/dashboard/payment-methods-chart/payment-methods-chart.tsx +152 -0
- package/src/components/dashboard/payment-methods-chart/use-payment-methods.ts +50 -0
- package/src/components/dashboard/payment-trend-chart/index.ts +4 -0
- package/src/components/dashboard/payment-trend-chart/locales/sl.ts +5 -0
- package/src/components/dashboard/payment-trend-chart/payment-trend-chart.tsx +137 -0
- package/src/components/dashboard/payment-trend-chart/use-payment-trend.ts +92 -0
- package/src/components/dashboard/revenue-card.tsx +49 -0
- package/src/components/dashboard/revenue-trend-chart/index.ts +4 -0
- package/src/components/dashboard/revenue-trend-chart/locales/sl.ts +5 -0
- package/src/components/dashboard/revenue-trend-chart/revenue-trend-chart.tsx +137 -0
- package/src/components/dashboard/revenue-trend-chart/use-revenue-trend.ts +93 -0
- package/src/components/dashboard/shared/index.ts +5 -0
- package/src/components/dashboard/shared/use-revenue-data.ts +160 -0
- package/src/components/dashboard/shared/use-stats-counts.ts +89 -0
- package/src/components/dashboard/shared/use-stats-query.ts +38 -0
- package/src/components/dashboard/stat-card.tsx +41 -0
- package/src/components/dashboard/tax-collected-card/index.ts +2 -0
- package/src/components/dashboard/tax-collected-card/tax-collected-card.tsx +77 -0
- package/src/components/dashboard/tax-collected-card/use-tax-collected.ts +145 -0
- package/src/components/dashboard/top-customers-chart/index.ts +4 -0
- package/src/components/dashboard/top-customers-chart/locales/sl.ts +5 -0
- package/src/components/dashboard/top-customers-chart/top-customers-chart.tsx +130 -0
- package/src/components/dashboard/top-customers-chart/use-top-customers.ts +72 -0
- package/src/components/documents/create/document-add-item-form.tsx +379 -0
- package/src/components/documents/create/document-add-item-tax-rate-field.tsx +120 -0
- package/src/components/documents/create/document-details-section.tsx +597 -0
- package/src/components/documents/create/document-items-section.tsx +133 -0
- package/src/components/documents/create/document-recipient-section.tsx +101 -0
- package/src/components/documents/create/form-types.ts +36 -0
- package/src/components/documents/create/index.ts +9 -0
- package/src/components/documents/create/live-preview.tsx +235 -0
- package/src/components/documents/create/mark-as-paid-section.tsx +82 -0
- package/src/components/documents/create/prepare-document-submission.test.ts +132 -0
- package/src/components/documents/create/prepare-document-submission.ts +187 -0
- package/src/components/documents/create/prepare-preview-data.test.ts +155 -0
- package/src/components/documents/create/prepare-preview-data.ts +16 -0
- package/src/components/documents/create/smart-code-insert-button.tsx +139 -0
- package/src/components/documents/create/use-document-customer-form.ts +161 -0
- package/src/components/documents/document-preview.tsx +13 -0
- package/src/components/documents/documents.hooks.ts +146 -0
- package/src/components/documents/index.ts +23 -0
- package/src/components/documents/shared/document-preview-display.tsx +172 -0
- package/src/components/documents/shared/index.ts +3 -0
- package/src/components/documents/shared/scaled-document-preview.tsx +70 -0
- package/src/components/documents/shared/use-a4-scaling.ts +62 -0
- package/src/components/documents/types.ts +61 -0
- package/src/components/documents/view/document-actions-bar.tsx +328 -0
- package/src/components/documents/view/document-details-card.tsx +179 -0
- package/src/components/documents/view/document-payments-list.tsx +256 -0
- package/src/components/documents/view/index.ts +4 -0
- package/src/components/documents/view/locales/de.ts +85 -0
- package/src/components/documents/view/locales/sl.ts +84 -0
- package/src/components/documents/view/use-document-download.ts +125 -0
- package/src/components/entities/create-entity-form.tsx +105 -0
- package/src/components/entities/entities.hooks.ts +50 -0
- package/src/components/entities/entity-settings-form/email-template-variables-info.tsx +103 -0
- package/src/components/entities/entity-settings-form/entity-settings-form.tsx +1326 -0
- package/src/components/entities/entity-settings-form/image-upload-with-crop.tsx +222 -0
- package/src/components/entities/entity-settings-form/index.ts +2 -0
- package/src/components/entities/entity-settings-form/input-with-preview.tsx +190 -0
- package/src/components/entities/entity-settings-form/locales/de.ts +192 -0
- package/src/components/entities/entity-settings-form/locales/sl.ts +188 -0
- package/src/components/entities/furs-settings-form/furs-settings-form.tsx +410 -0
- package/src/components/entities/furs-settings-form/furs-settings.hooks.ts +320 -0
- package/src/components/entities/furs-settings-form/index.ts +3 -0
- package/src/components/entities/furs-settings-form/locales/de.ts +233 -0
- package/src/components/entities/furs-settings-form/locales/en.ts +194 -0
- package/src/components/entities/furs-settings-form/locales/sl.ts +196 -0
- package/src/components/entities/furs-settings-form/sections/certificate-settings-section.tsx +242 -0
- package/src/components/entities/furs-settings-form/sections/enable-fiscalization-section.tsx +139 -0
- package/src/components/entities/furs-settings-form/sections/general-settings-section.tsx +252 -0
- package/src/components/entities/furs-settings-form/sections/premises-management-section.tsx +370 -0
- package/src/components/entities/furs-settings-form/sections/register-premise-dialog.tsx +420 -0
- package/src/components/entities/keys.ts +2 -0
- package/src/components/entities/settings/branding-settings-form.tsx +274 -0
- package/src/components/entities/settings/company-settings-form.tsx +256 -0
- package/src/components/entities/settings/defaults-settings-form.tsx +501 -0
- package/src/components/entities/settings/email-settings-form.tsx +288 -0
- package/src/components/entities/settings/eslog-settings-form.tsx +113 -0
- package/src/components/entities/settings/index.ts +8 -0
- package/src/components/entities/settings/number-format-settings-form.tsx +244 -0
- package/src/components/entities/settings/pdf-template-selector/demo-invoice-data.ts +164 -0
- package/src/components/entities/settings/pdf-template-selector/index.ts +2 -0
- package/src/components/entities/settings/pdf-template-selector/locales/de.ts +18 -0
- package/src/components/entities/settings/pdf-template-selector/locales/sl.ts +18 -0
- package/src/components/entities/settings/pdf-template-selector/pdf-template-cards.tsx +49 -0
- package/src/components/entities/settings/settings-footer.tsx +16 -0
- package/src/components/entities/settings/tax-rules-settings-form.tsx +346 -0
- package/src/components/estimates/create/create-estimate-form.tsx +384 -0
- package/src/components/estimates/create/locales/de.ts +64 -0
- package/src/components/estimates/create/locales/sl.ts +63 -0
- package/src/components/estimates/create/prepare-estimate-submission.ts +39 -0
- package/src/components/estimates/create/use-estimate-customer-form.ts +5 -0
- package/src/components/estimates/estimates.hooks.ts +15 -0
- package/src/components/estimates/index.ts +6 -0
- package/src/components/estimates/list/index.ts +3 -0
- package/src/components/estimates/list/list-row-actions.tsx +103 -0
- package/src/components/estimates/list/list-table.tsx +171 -0
- package/src/components/estimates/list/locales/de.ts +26 -0
- package/src/components/estimates/list/locales/sl.ts +26 -0
- package/src/components/estimates/list/use-estimate-download.ts +63 -0
- package/src/components/export/document-export-form.tsx +288 -0
- package/src/components/export/index.ts +2 -0
- package/src/components/form/form-input.tsx +89 -0
- package/src/components/form/index.ts +1 -0
- package/src/components/invoices/create/create-invoice-form.tsx +852 -0
- package/src/components/invoices/create/eslog-validation.test.ts +242 -0
- package/src/components/invoices/create/eslog-validation.ts +208 -0
- package/src/components/invoices/create/locales/de.ts +118 -0
- package/src/components/invoices/create/locales/sl.ts +114 -0
- package/src/components/invoices/create/prepare-invoice-submission.test.ts +777 -0
- package/src/components/invoices/create/prepare-invoice-submission.ts +79 -0
- package/src/components/invoices/create/use-invoice-customer-form.ts +5 -0
- package/src/components/invoices/index.ts +9 -0
- package/src/components/invoices/invoices-furs.hooks.ts +28 -0
- package/src/components/invoices/invoices.hooks.ts +110 -0
- package/src/components/invoices/list/index.ts +3 -0
- package/src/components/invoices/list/list-row-actions.tsx +132 -0
- package/src/components/invoices/list/list-table.tsx +165 -0
- package/src/components/invoices/list/locales/de.ts +33 -0
- package/src/components/invoices/list/locales/sl.ts +33 -0
- package/src/components/invoices/list/use-invoice-download.ts +62 -0
- package/src/components/invoices/send-email-dialog/index.ts +1 -0
- package/src/components/invoices/send-email-dialog/locales/de.ts +18 -0
- package/src/components/invoices/send-email-dialog/locales/sl.ts +17 -0
- package/src/components/invoices/send-email-dialog/send-email-dialog.tsx +289 -0
- package/src/components/invoices/send-email-dialog.tsx +2 -0
- package/src/components/invoices/shared/index.ts +2 -0
- package/src/components/invoices/shared/scaled-document-preview.tsx +32 -0
- package/src/components/invoices/shared/use-a4-scaling.tsx +39 -0
- package/src/components/invoices/view/eslog-info-display.tsx +160 -0
- package/src/components/invoices/view/furs-info-display.tsx +213 -0
- package/src/components/items/create-item-form/create-item-form.tsx +155 -0
- package/src/components/items/create-item-form/locales/de.ts +14 -0
- package/src/components/items/create-item-form/locales/en.ts +9 -0
- package/src/components/items/create-item-form/locales/sl.ts +14 -0
- package/src/components/items/item-combobox.tsx +147 -0
- package/src/components/items/item-list-table/item-list-header.tsx +33 -0
- package/src/components/items/item-list-table/item-list-row-actions.tsx +48 -0
- package/src/components/items/item-list-table/item-list-row.tsx +32 -0
- package/src/components/items/item-list-table/item-list-table.tsx +76 -0
- package/src/components/items/item-list-table/locales/de.ts +10 -0
- package/src/components/items/item-list-table/locales/en.ts +10 -0
- package/src/components/items/item-list-table/locales/sl.ts +10 -0
- package/src/components/items/items.hooks.ts +63 -0
- package/src/components/loading-spinner.tsx +24 -0
- package/src/components/payments/create-payment-form/create-payment-form.tsx +222 -0
- package/src/components/payments/create-payment-form/locales/de.ts +20 -0
- package/src/components/payments/create-payment-form/locales/sl.ts +20 -0
- package/src/components/payments/edit-payment-form/edit-payment-form.tsx +230 -0
- package/src/components/payments/edit-payment-form/index.ts +1 -0
- package/src/components/payments/edit-payment-form/locales/de.ts +20 -0
- package/src/components/payments/edit-payment-form/locales/sl.ts +20 -0
- package/src/components/payments/index.ts +4 -0
- package/src/components/payments/list/index.ts +2 -0
- package/src/components/payments/list/list-row-actions.tsx +98 -0
- package/src/components/payments/list/list-table.tsx +186 -0
- package/src/components/payments/list/locales/de.ts +19 -0
- package/src/components/payments/list/locales/sl.ts +19 -0
- package/src/components/payments/payments.hooks.ts +15 -0
- package/src/components/request-logs/index.ts +3 -0
- package/src/components/request-logs/request-log-detail.tsx +242 -0
- package/src/components/request-logs/request-log-list-table.tsx +266 -0
- package/src/components/request-logs/request-logs-page.tsx +10 -0
- package/src/components/table/README.md +410 -0
- package/src/components/table/data-table.tsx +251 -0
- package/src/components/table/date-cell.tsx +35 -0
- package/src/components/table/filter-bar.tsx +114 -0
- package/src/components/table/filter-panel.tsx +407 -0
- package/src/components/table/hooks/use-table-fetch.ts +17 -0
- package/src/components/table/hooks/use-table-query.ts +36 -0
- package/src/components/table/hooks/use-table-state.ts +293 -0
- package/src/components/table/index.ts +35 -0
- package/src/components/table/search-input.tsx +85 -0
- package/src/components/table/sortable-header.tsx +56 -0
- package/src/components/table/table-empty-state.tsx +40 -0
- package/src/components/table/table-no-results.tsx +41 -0
- package/src/components/table/table-pagination.tsx +42 -0
- package/src/components/table/table-skeleton.tsx +54 -0
- package/src/components/table/types.ts +136 -0
- package/src/components/tax-reports/index.ts +1 -0
- package/src/components/tax-reports/kir-export-form.tsx +172 -0
- package/src/components/taxes/create-tax-form/create-tax-form.tsx +112 -0
- package/src/components/taxes/create-tax-form/locales/de.ts +8 -0
- package/src/components/taxes/create-tax-form/locales/en.ts +7 -0
- package/src/components/taxes/create-tax-form/locales/sl.ts +8 -0
- package/src/components/taxes/tax-list-table/locales/de.ts +11 -0
- package/src/components/taxes/tax-list-table/locales/en.ts +10 -0
- package/src/components/taxes/tax-list-table/locales/sl.ts +11 -0
- package/src/components/taxes/tax-list-table/tax-list-header.tsx +29 -0
- package/src/components/taxes/tax-list-table/tax-list-row-actions.tsx +43 -0
- package/src/components/taxes/tax-list-table/tax-list-row.tsx +46 -0
- package/src/components/taxes/tax-list-table/tax-list-table.tsx +59 -0
- package/src/components/taxes/taxes.hooks.ts +35 -0
- package/src/components/ui/alert-dialog.tsx +61 -0
- package/src/components/ui/alert.tsx +72 -0
- package/src/components/ui/badge.tsx +48 -0
- package/src/components/ui/breadcrumb.tsx +132 -0
- package/src/components/ui/button.tsx +61 -0
- package/src/components/ui/calendar.tsx +213 -0
- package/src/components/ui/card.tsx +94 -0
- package/src/components/ui/chart.tsx +380 -0
- package/src/components/ui/checkbox.tsx +27 -0
- package/src/components/ui/collapsible.tsx +56 -0
- package/src/components/ui/command.tsx +187 -0
- package/src/components/ui/dialog.tsx +187 -0
- package/src/components/ui/drawer.tsx +123 -0
- package/src/components/ui/dropdown-menu.tsx +291 -0
- package/src/components/ui/form.tsx +166 -0
- package/src/components/ui/input-group.tsx +149 -0
- package/src/components/ui/input.tsx +20 -0
- package/src/components/ui/label.tsx +18 -0
- package/src/components/ui/loading-spinner.tsx +16 -0
- package/src/components/ui/popover.tsx +108 -0
- package/src/components/ui/radio-group.tsx +37 -0
- package/src/components/ui/select.tsx +200 -0
- package/src/components/ui/separator.tsx +23 -0
- package/src/components/ui/sheet.tsx +145 -0
- package/src/components/ui/sidebar.tsx +771 -0
- package/src/components/ui/skeleton.tsx +13 -0
- package/src/components/ui/sonner.tsx +60 -0
- package/src/components/ui/spinner.tsx +10 -0
- package/src/components/ui/sticky-form-footer.tsx +55 -0
- package/src/components/ui/switch.tsx +30 -0
- package/src/components/ui/table.tsx +101 -0
- package/src/components/ui/tabs.tsx +80 -0
- package/src/components/ui/textarea.tsx +18 -0
- package/src/components/ui/tooltip.tsx +89 -0
- package/src/components/wl-subscription/index.ts +2 -0
- package/src/components/wl-subscription/locked-feature.tsx +173 -0
- package/src/components/wl-subscription/upgrade-modal.tsx +209 -0
- package/src/frontend.tsx +28 -0
- package/src/generate-schemas.ts +265 -0
- package/src/generated/schemas/advanceinvoice.ts +177 -0
- package/src/generated/schemas/creditnote.ts +187 -0
- package/src/generated/schemas/customer.ts +29 -0
- package/src/generated/schemas/entity.ts +252 -0
- package/src/generated/schemas/estimate.ts +159 -0
- package/src/generated/schemas/furssettings.ts +25 -0
- package/src/generated/schemas/index.ts +24 -0
- package/src/generated/schemas/invoice.ts +167 -0
- package/src/generated/schemas/item.ts +38 -0
- package/src/generated/schemas/payment.ts +44 -0
- package/src/generated/schemas/previewadvanceinvoice_body.ts +354 -0
- package/src/generated/schemas/previewestimate_body.ts +309 -0
- package/src/generated/schemas/registerfursmovablepremise_body.ts +22 -0
- package/src/generated/schemas/registerfursrealestatepremise_body.ts +32 -0
- package/src/generated/schemas/renderdocument_body.ts +594 -0
- package/src/generated/schemas/sendemail_body.ts +26 -0
- package/src/generated/schemas/startpdfexport_body.ts +20 -0
- package/src/generated/schemas/tax.ts +48 -0
- package/src/generated/schemas/uploadfile_body.ts +23 -0
- package/src/generated/schemas/uploadfurscertificate_body.ts +20 -0
- package/src/generated/schemas/userfurssettings.ts +19 -0
- package/src/hooks/create-resource-hooks.test.ts +483 -0
- package/src/hooks/create-resource-hooks.ts +300 -0
- package/src/hooks/use-debounce.ts +12 -0
- package/src/hooks/use-duplicate-document.ts +185 -0
- package/src/hooks/use-media-query.tsx +19 -0
- package/src/hooks/use-mobile.ts +39 -0
- package/src/hooks/use-next-document-number.ts +57 -0
- package/src/hooks/use-resource-mutation.ts +118 -0
- package/src/hooks/use-vies-check.ts +130 -0
- package/src/index.css +11 -0
- package/src/index.html +13 -0
- package/src/index.tsx +12 -0
- package/src/lib/auth.ts +4 -0
- package/src/lib/browser-cookies.ts +70 -0
- package/src/lib/constants.ts +287 -0
- package/src/lib/cookies.ts +36 -0
- package/src/lib/schemas/advance-invoice.ts +43 -0
- package/src/lib/schemas/credit-note.ts +32 -0
- package/src/lib/schemas/estimate.ts +31 -0
- package/src/lib/schemas/index.ts +18 -0
- package/src/lib/schemas/invoice.ts +43 -0
- package/src/lib/schemas/shared.ts +79 -0
- package/src/lib/translation.ts +38 -0
- package/src/lib/utils.ts +6 -0
- package/src/providers/entities-context.tsx +41 -0
- package/src/providers/entities-provider.tsx +201 -0
- package/src/providers/form-footer-context.tsx +72 -0
- package/src/providers/sdk-provider.tsx +164 -0
- package/src/providers/white-label-provider.tsx +91 -0
- package/src/providers/wl-subscription-provider.tsx +277 -0
- package/src/utils/string-helpers.ts +111 -0
|
@@ -0,0 +1,171 @@
|
|
|
1
|
+
import type { Estimate } from "@spaceinvoices/js-sdk";
|
|
2
|
+
import { useMemo } from "react";
|
|
3
|
+
import { DataTable } from "@/ui/components/table/data-table";
|
|
4
|
+
import { FormattedDate } from "@/ui/components/table/date-cell";
|
|
5
|
+
import { useTableFetch } from "@/ui/components/table/hooks/use-table-fetch";
|
|
6
|
+
import type {
|
|
7
|
+
Column,
|
|
8
|
+
FilterConfig,
|
|
9
|
+
ListTableProps,
|
|
10
|
+
TableQueryParams,
|
|
11
|
+
TableQueryResponse,
|
|
12
|
+
} from "@/ui/components/table/types";
|
|
13
|
+
import { Badge } from "@/ui/components/ui/badge";
|
|
14
|
+
import { Button } from "@/ui/components/ui/button";
|
|
15
|
+
import { createTranslation } from "@/ui/lib/translation";
|
|
16
|
+
import { useSDK } from "@/ui/providers/sdk-provider";
|
|
17
|
+
|
|
18
|
+
import EstimateListRowActions from "./list-row-actions";
|
|
19
|
+
import de from "./locales/de";
|
|
20
|
+
import sl from "./locales/sl";
|
|
21
|
+
|
|
22
|
+
const translations = {
|
|
23
|
+
sl,
|
|
24
|
+
de,
|
|
25
|
+
} as const;
|
|
26
|
+
|
|
27
|
+
type EstimateListTableProps = {
|
|
28
|
+
t?: (key: string) => string;
|
|
29
|
+
namespace?: string;
|
|
30
|
+
locale?: string;
|
|
31
|
+
entityId?: string;
|
|
32
|
+
onDuplicate?: (estimate: Estimate) => void;
|
|
33
|
+
onDownloadStart?: () => void;
|
|
34
|
+
onDownloadSuccess?: (fileName: string) => void;
|
|
35
|
+
onDownloadError?: (error: string) => void;
|
|
36
|
+
} & ListTableProps<Estimate>;
|
|
37
|
+
|
|
38
|
+
export default function EstimateListTable({
|
|
39
|
+
queryParams,
|
|
40
|
+
onRowClick,
|
|
41
|
+
onDuplicate,
|
|
42
|
+
onChangeParams,
|
|
43
|
+
entityId,
|
|
44
|
+
onDownloadStart,
|
|
45
|
+
onDownloadSuccess,
|
|
46
|
+
onDownloadError,
|
|
47
|
+
...i18nProps
|
|
48
|
+
}: EstimateListTableProps) {
|
|
49
|
+
const t = createTranslation({
|
|
50
|
+
translations,
|
|
51
|
+
...i18nProps,
|
|
52
|
+
});
|
|
53
|
+
|
|
54
|
+
const { sdk } = useSDK();
|
|
55
|
+
|
|
56
|
+
const handleFetch = useTableFetch(async (params: TableQueryParams) => {
|
|
57
|
+
if (!sdk) throw new Error("SDK not initialized");
|
|
58
|
+
if (!params.entity_id) throw new Error("Entity ID required");
|
|
59
|
+
|
|
60
|
+
const response = await sdk.estimates.list({
|
|
61
|
+
entity_id: params.entity_id,
|
|
62
|
+
limit: params.limit,
|
|
63
|
+
next_cursor: params.next_cursor,
|
|
64
|
+
prev_cursor: params.prev_cursor,
|
|
65
|
+
order_by: params.order_by,
|
|
66
|
+
search: params.search,
|
|
67
|
+
query: params.query,
|
|
68
|
+
});
|
|
69
|
+
return response as unknown as TableQueryResponse<Estimate>;
|
|
70
|
+
}, entityId);
|
|
71
|
+
|
|
72
|
+
const filterConfig: FilterConfig = useMemo(
|
|
73
|
+
() => ({
|
|
74
|
+
dateFields: [
|
|
75
|
+
{ id: "date", label: t("Date") },
|
|
76
|
+
{ id: "date_valid_till", label: t("Valid Until") },
|
|
77
|
+
{ id: "created_at", label: t("Created At") },
|
|
78
|
+
],
|
|
79
|
+
statusFilter: false, // Estimates don't have payment status
|
|
80
|
+
}),
|
|
81
|
+
[t],
|
|
82
|
+
);
|
|
83
|
+
|
|
84
|
+
const columns: Column<Estimate>[] = useMemo(
|
|
85
|
+
() => [
|
|
86
|
+
{
|
|
87
|
+
id: "number",
|
|
88
|
+
header: t("Number"),
|
|
89
|
+
sortable: true,
|
|
90
|
+
cell: (estimate) => (
|
|
91
|
+
<div className="flex items-center gap-2">
|
|
92
|
+
<Button variant="link" className="cursor-pointer py-0 underline" onClick={() => onRowClick?.(estimate)}>
|
|
93
|
+
{estimate.number}
|
|
94
|
+
</Button>
|
|
95
|
+
{(estimate as any).is_draft && (
|
|
96
|
+
<Badge
|
|
97
|
+
variant="outline"
|
|
98
|
+
className="border-amber-500 bg-amber-50 text-amber-700 dark:bg-amber-950 dark:text-amber-400"
|
|
99
|
+
>
|
|
100
|
+
{t("Draft")}
|
|
101
|
+
</Badge>
|
|
102
|
+
)}
|
|
103
|
+
</div>
|
|
104
|
+
),
|
|
105
|
+
},
|
|
106
|
+
{
|
|
107
|
+
id: "customer",
|
|
108
|
+
header: t("Customer"),
|
|
109
|
+
cell: (estimate) => estimate.customer?.name ?? "-",
|
|
110
|
+
},
|
|
111
|
+
{
|
|
112
|
+
id: "date",
|
|
113
|
+
header: t("Date"),
|
|
114
|
+
sortable: true,
|
|
115
|
+
cell: (estimate) => <FormattedDate date={estimate.date} />,
|
|
116
|
+
},
|
|
117
|
+
{
|
|
118
|
+
id: "date_valid_till",
|
|
119
|
+
header: t("Valid Until"),
|
|
120
|
+
sortable: true,
|
|
121
|
+
cell: (estimate) => <FormattedDate date={estimate.date_valid_till} />,
|
|
122
|
+
},
|
|
123
|
+
{
|
|
124
|
+
id: "total",
|
|
125
|
+
header: t("Total"),
|
|
126
|
+
sortable: true,
|
|
127
|
+
align: "right",
|
|
128
|
+
cell: (estimate) => estimate.total,
|
|
129
|
+
},
|
|
130
|
+
{
|
|
131
|
+
id: "total_with_tax",
|
|
132
|
+
header: t("Total with Tax"),
|
|
133
|
+
sortable: true,
|
|
134
|
+
align: "right",
|
|
135
|
+
cell: (estimate) => estimate.total_with_tax,
|
|
136
|
+
},
|
|
137
|
+
{
|
|
138
|
+
id: "actions",
|
|
139
|
+
header: "",
|
|
140
|
+
align: "right",
|
|
141
|
+
cell: (estimate) => (
|
|
142
|
+
<EstimateListRowActions
|
|
143
|
+
estimate={estimate}
|
|
144
|
+
onDuplicate={onDuplicate}
|
|
145
|
+
onDownloadStart={onDownloadStart}
|
|
146
|
+
onDownloadSuccess={onDownloadSuccess}
|
|
147
|
+
onDownloadError={onDownloadError}
|
|
148
|
+
{...i18nProps}
|
|
149
|
+
/>
|
|
150
|
+
),
|
|
151
|
+
},
|
|
152
|
+
],
|
|
153
|
+
[t, onRowClick, onDuplicate, onDownloadStart, onDownloadSuccess, onDownloadError, i18nProps],
|
|
154
|
+
);
|
|
155
|
+
|
|
156
|
+
return (
|
|
157
|
+
<DataTable
|
|
158
|
+
columns={columns}
|
|
159
|
+
queryParams={queryParams}
|
|
160
|
+
onChangeParams={onChangeParams}
|
|
161
|
+
onFetch={handleFetch}
|
|
162
|
+
cacheKey="estimates"
|
|
163
|
+
resourceName="estimate"
|
|
164
|
+
createNewLink="/app/documents/add/estimate"
|
|
165
|
+
entityId={entityId}
|
|
166
|
+
filterConfig={filterConfig}
|
|
167
|
+
t={t}
|
|
168
|
+
locale={i18nProps.locale}
|
|
169
|
+
/>
|
|
170
|
+
);
|
|
171
|
+
}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
export default {
|
|
2
|
+
Draft: "Entwurf",
|
|
3
|
+
Number: "Nummer",
|
|
4
|
+
Customer: "Kunde",
|
|
5
|
+
Date: "Datum",
|
|
6
|
+
"Valid Until": "Gültig bis",
|
|
7
|
+
Total: "Gesamt",
|
|
8
|
+
"Total with Tax": "Gesamt mit MwSt.",
|
|
9
|
+
Actions: "Aktionen",
|
|
10
|
+
"Open menu": "Menü öffnen",
|
|
11
|
+
"Copy estimate ID": "Angebots-ID kopieren",
|
|
12
|
+
"View estimate": "Angebot ansehen",
|
|
13
|
+
"Download PDF": "PDF herunterladen",
|
|
14
|
+
"Downloading...": "Wird heruntergeladen...",
|
|
15
|
+
Duplicate: "Duplizieren",
|
|
16
|
+
Estimate: "Angebot",
|
|
17
|
+
"Failed to download PDF": "PDF-Download fehlgeschlagen",
|
|
18
|
+
// Filter translations
|
|
19
|
+
"Search...": "Suchen...",
|
|
20
|
+
Filters: "Filter",
|
|
21
|
+
"Date Range": "Datumsbereich",
|
|
22
|
+
From: "Von",
|
|
23
|
+
To: "Bis",
|
|
24
|
+
"Clear filters": "Filter löschen",
|
|
25
|
+
"Created At": "Erstellt am",
|
|
26
|
+
} as const;
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
export default {
|
|
2
|
+
Draft: "Osnutek",
|
|
3
|
+
Number: "Številka",
|
|
4
|
+
Customer: "Stranka",
|
|
5
|
+
Date: "Datum",
|
|
6
|
+
"Valid Until": "Veljavno do",
|
|
7
|
+
Total: "Skupaj",
|
|
8
|
+
"Total with Tax": "Skupaj z DDV",
|
|
9
|
+
Actions: "Dejanja",
|
|
10
|
+
"Open menu": "Odpri meni",
|
|
11
|
+
"Copy estimate ID": "Kopiraj ID predračuna",
|
|
12
|
+
"View estimate": "Poglej predračun",
|
|
13
|
+
"Download PDF": "Prenesi PDF",
|
|
14
|
+
"Downloading...": "Prenašanje...",
|
|
15
|
+
Duplicate: "Podvoji",
|
|
16
|
+
Estimate: "Predračun",
|
|
17
|
+
"Failed to download PDF": "Prenos PDF ni uspel",
|
|
18
|
+
// Filter translations
|
|
19
|
+
"Search...": "Iskanje...",
|
|
20
|
+
Filters: "Filtri",
|
|
21
|
+
"Date Range": "Datumski razpon",
|
|
22
|
+
From: "Od",
|
|
23
|
+
To: "Do",
|
|
24
|
+
"Clear filters": "Počisti filtre",
|
|
25
|
+
"Created At": "Ustvarjeno",
|
|
26
|
+
} as const;
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
import type { Estimate } from "@spaceinvoices/js-sdk";
|
|
2
|
+
import { useState } from "react";
|
|
3
|
+
import type { ComponentTranslationProps } from "@/ui/lib/translation";
|
|
4
|
+
import { createTranslation } from "@/ui/lib/translation";
|
|
5
|
+
import { useEntities } from "@/ui/providers/entities-context";
|
|
6
|
+
import { useSDK } from "@/ui/providers/sdk-provider";
|
|
7
|
+
|
|
8
|
+
type UseEstimateDownloadProps = {
|
|
9
|
+
onDownloadStart?: () => void;
|
|
10
|
+
onDownloadSuccess?: (fileName: string) => void;
|
|
11
|
+
onDownloadError?: (error: string) => void;
|
|
12
|
+
} & ComponentTranslationProps;
|
|
13
|
+
|
|
14
|
+
export function useEstimateDownload({
|
|
15
|
+
onDownloadStart,
|
|
16
|
+
onDownloadSuccess,
|
|
17
|
+
onDownloadError,
|
|
18
|
+
...i18nProps
|
|
19
|
+
}: UseEstimateDownloadProps) {
|
|
20
|
+
const [isDownloading, setIsDownloading] = useState(false);
|
|
21
|
+
const { activeEntity } = useEntities();
|
|
22
|
+
const { sdk } = useSDK();
|
|
23
|
+
const t = createTranslation(i18nProps);
|
|
24
|
+
|
|
25
|
+
const downloadPDF = async (estimate: Estimate) => {
|
|
26
|
+
if (!activeEntity?.id || !sdk) {
|
|
27
|
+
console.error("Missing SDK or active entity for PDF download");
|
|
28
|
+
onDownloadError?.(t("Failed to download PDF"));
|
|
29
|
+
return;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
setIsDownloading(true);
|
|
33
|
+
onDownloadStart?.();
|
|
34
|
+
|
|
35
|
+
try {
|
|
36
|
+
// SDK signature: renderPdf(id, params?, SDKMethodOptions?)
|
|
37
|
+
// entity_id goes in SDKMethodOptions (last arg), not params
|
|
38
|
+
// Note: renderPdf is on invoices module but works with any document ID
|
|
39
|
+
const blob = await sdk.invoices.renderPdf(estimate.id, {}, { entity_id: activeEntity.id });
|
|
40
|
+
const downloadUrl = window.URL.createObjectURL(blob);
|
|
41
|
+
const link = document.createElement("a");
|
|
42
|
+
link.href = downloadUrl;
|
|
43
|
+
const fileName = `${t("Estimate")} ${estimate.number}.pdf`;
|
|
44
|
+
link.download = fileName;
|
|
45
|
+
document.body.appendChild(link);
|
|
46
|
+
link.click();
|
|
47
|
+
document.body.removeChild(link);
|
|
48
|
+
window.URL.revokeObjectURL(downloadUrl);
|
|
49
|
+
|
|
50
|
+
onDownloadSuccess?.(fileName);
|
|
51
|
+
} catch (error) {
|
|
52
|
+
console.error("Error downloading PDF:", error);
|
|
53
|
+
onDownloadError?.(t("Failed to download PDF"));
|
|
54
|
+
} finally {
|
|
55
|
+
setIsDownloading(false);
|
|
56
|
+
}
|
|
57
|
+
};
|
|
58
|
+
|
|
59
|
+
return {
|
|
60
|
+
isDownloading,
|
|
61
|
+
downloadPDF,
|
|
62
|
+
};
|
|
63
|
+
}
|
|
@@ -0,0 +1,288 @@
|
|
|
1
|
+
type TFunction = (key: string, options?: Record<string, unknown>) => string;
|
|
2
|
+
|
|
3
|
+
import { Calendar, Download, Loader2 } from "lucide-react";
|
|
4
|
+
import { useRef, useState } from "react";
|
|
5
|
+
import { Button } from "../ui/button";
|
|
6
|
+
import { Input } from "../ui/input";
|
|
7
|
+
import { Label } from "../ui/label";
|
|
8
|
+
import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue } from "../ui/select";
|
|
9
|
+
|
|
10
|
+
export type DocumentType = "invoice" | "estimate" | "credit_note";
|
|
11
|
+
export type ExportFormat = "xlsx" | "csv" | "pdf_zip";
|
|
12
|
+
|
|
13
|
+
// Maximum date range for export (1 year in milliseconds)
|
|
14
|
+
const MAX_DATE_RANGE_MS = 365 * 24 * 60 * 60 * 1000;
|
|
15
|
+
|
|
16
|
+
function formatDateLocal(date: Date): string {
|
|
17
|
+
const year = date.getFullYear();
|
|
18
|
+
const month = String(date.getMonth() + 1).padStart(2, "0");
|
|
19
|
+
const day = String(date.getDate()).padStart(2, "0");
|
|
20
|
+
return `${year}-${month}-${day}`;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
function getPreviousMonthRange(): { from: string; to: string } {
|
|
24
|
+
const now = new Date();
|
|
25
|
+
const firstDayPrevMonth = new Date(now.getFullYear(), now.getMonth() - 1, 1);
|
|
26
|
+
const lastDayPrevMonth = new Date(now.getFullYear(), now.getMonth(), 0);
|
|
27
|
+
return {
|
|
28
|
+
from: formatDateLocal(firstDayPrevMonth),
|
|
29
|
+
to: formatDateLocal(lastDayPrevMonth),
|
|
30
|
+
};
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
function isDateRangeValid(dateFrom: string, dateTo: string): boolean {
|
|
34
|
+
if (!dateFrom || !dateTo) return true;
|
|
35
|
+
const from = new Date(dateFrom);
|
|
36
|
+
const to = new Date(dateTo);
|
|
37
|
+
return to.getTime() - from.getTime() <= MAX_DATE_RANGE_MS;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
export type DocumentExportFormProps = {
|
|
41
|
+
entityId: string;
|
|
42
|
+
token: string;
|
|
43
|
+
language: string;
|
|
44
|
+
t: TFunction;
|
|
45
|
+
onSuccess?: (fileName: string) => void;
|
|
46
|
+
onError?: (error: Error) => void;
|
|
47
|
+
onPdfExportStarted?: () => void;
|
|
48
|
+
onLoadingChange?: (isLoading: boolean, toastId: string | number | null) => void;
|
|
49
|
+
};
|
|
50
|
+
|
|
51
|
+
export function DocumentExportForm({
|
|
52
|
+
entityId,
|
|
53
|
+
token,
|
|
54
|
+
language,
|
|
55
|
+
t,
|
|
56
|
+
onSuccess,
|
|
57
|
+
onError,
|
|
58
|
+
onPdfExportStarted,
|
|
59
|
+
onLoadingChange,
|
|
60
|
+
}: DocumentExportFormProps) {
|
|
61
|
+
const defaultDates = getPreviousMonthRange();
|
|
62
|
+
const [documentType, setDocumentType] = useState<DocumentType>("invoice");
|
|
63
|
+
const [exportFormat, setExportFormat] = useState<ExportFormat>("xlsx");
|
|
64
|
+
const [dateFrom, setDateFrom] = useState(defaultDates.from);
|
|
65
|
+
const [dateTo, setDateTo] = useState(defaultDates.to);
|
|
66
|
+
const [isExporting, setIsExporting] = useState(false);
|
|
67
|
+
const [dateRangeError, setDateRangeError] = useState(false);
|
|
68
|
+
|
|
69
|
+
const toastIdRef = useRef<string | number | null>(null);
|
|
70
|
+
|
|
71
|
+
const validateDateRange = (from: string, to: string) => {
|
|
72
|
+
const isValid = isDateRangeValid(from, to);
|
|
73
|
+
setDateRangeError(!isValid);
|
|
74
|
+
return isValid;
|
|
75
|
+
};
|
|
76
|
+
|
|
77
|
+
const handleExport = async () => {
|
|
78
|
+
if (!validateDateRange(dateFrom, dateTo)) {
|
|
79
|
+
onError?.(new Error(t("export-page.error.date-range-exceeded")));
|
|
80
|
+
return;
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
setIsExporting(true);
|
|
84
|
+
onLoadingChange?.(true, null);
|
|
85
|
+
|
|
86
|
+
// PDF export is async - different flow
|
|
87
|
+
if (exportFormat === "pdf_zip") {
|
|
88
|
+
try {
|
|
89
|
+
const response = await fetch("/documents/export/pdf", {
|
|
90
|
+
method: "POST",
|
|
91
|
+
headers: {
|
|
92
|
+
Authorization: `Bearer ${token}`,
|
|
93
|
+
"x-entity-id": entityId,
|
|
94
|
+
"Content-Type": "application/json",
|
|
95
|
+
},
|
|
96
|
+
body: JSON.stringify({
|
|
97
|
+
type: documentType,
|
|
98
|
+
date_from: dateFrom || undefined,
|
|
99
|
+
date_to: dateTo || undefined,
|
|
100
|
+
}),
|
|
101
|
+
});
|
|
102
|
+
|
|
103
|
+
if (!response.ok) {
|
|
104
|
+
const error = await response.json().catch(() => ({}));
|
|
105
|
+
throw new Error(error.error || `Export failed: ${response.statusText}`);
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
onPdfExportStarted?.();
|
|
109
|
+
} catch (error) {
|
|
110
|
+
console.error("PDF export error:", error);
|
|
111
|
+
onError?.(error instanceof Error ? error : new Error("Unknown error"));
|
|
112
|
+
} finally {
|
|
113
|
+
setIsExporting(false);
|
|
114
|
+
onLoadingChange?.(false, toastIdRef.current);
|
|
115
|
+
toastIdRef.current = null;
|
|
116
|
+
}
|
|
117
|
+
return;
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
// XLSX/CSV export - synchronous download
|
|
121
|
+
try {
|
|
122
|
+
const exportLanguage = language === "sl" ? "sl" : "en";
|
|
123
|
+
const queryParams: Record<string, string> = {
|
|
124
|
+
type: documentType,
|
|
125
|
+
format: exportFormat,
|
|
126
|
+
language: exportLanguage,
|
|
127
|
+
};
|
|
128
|
+
if (dateFrom) {
|
|
129
|
+
queryParams.date_from = dateFrom;
|
|
130
|
+
}
|
|
131
|
+
if (dateTo) {
|
|
132
|
+
queryParams.date_to = dateTo;
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
const response = await fetch(`/documents/export?${new URLSearchParams(queryParams).toString()}`, {
|
|
136
|
+
headers: {
|
|
137
|
+
Authorization: `Bearer ${token}`,
|
|
138
|
+
"x-entity-id": entityId,
|
|
139
|
+
},
|
|
140
|
+
});
|
|
141
|
+
|
|
142
|
+
if (!response.ok) {
|
|
143
|
+
throw new Error(`Export failed: ${response.statusText}`);
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
const contentDisposition = response.headers.get("content-disposition");
|
|
147
|
+
let fileName = `${documentType}s_export.${exportFormat}`;
|
|
148
|
+
if (contentDisposition) {
|
|
149
|
+
const match = contentDisposition.match(/filename="?([^";\n]+)"?/);
|
|
150
|
+
if (match) {
|
|
151
|
+
fileName = match[1];
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
const blob = await response.blob();
|
|
156
|
+
const downloadUrl = window.URL.createObjectURL(blob);
|
|
157
|
+
const link = document.createElement("a");
|
|
158
|
+
link.href = downloadUrl;
|
|
159
|
+
link.download = fileName;
|
|
160
|
+
document.body.appendChild(link);
|
|
161
|
+
link.click();
|
|
162
|
+
setTimeout(() => {
|
|
163
|
+
document.body.removeChild(link);
|
|
164
|
+
window.URL.revokeObjectURL(downloadUrl);
|
|
165
|
+
}, 1000);
|
|
166
|
+
|
|
167
|
+
onSuccess?.(fileName);
|
|
168
|
+
} catch (error) {
|
|
169
|
+
console.error("Export error:", error);
|
|
170
|
+
onError?.(error instanceof Error ? error : new Error("Unknown error"));
|
|
171
|
+
} finally {
|
|
172
|
+
setIsExporting(false);
|
|
173
|
+
onLoadingChange?.(false, toastIdRef.current);
|
|
174
|
+
toastIdRef.current = null;
|
|
175
|
+
}
|
|
176
|
+
};
|
|
177
|
+
|
|
178
|
+
return (
|
|
179
|
+
<div className="space-y-6">
|
|
180
|
+
<p className="text-muted-foreground">{t("export-page.description")}</p>
|
|
181
|
+
|
|
182
|
+
{/* Document Type */}
|
|
183
|
+
<div className="space-y-2">
|
|
184
|
+
<Label htmlFor="document-type">{t("export-page.document-type")}</Label>
|
|
185
|
+
<Select value={documentType} onValueChange={(v) => setDocumentType(v as DocumentType)}>
|
|
186
|
+
<SelectTrigger id="document-type">
|
|
187
|
+
<SelectValue />
|
|
188
|
+
</SelectTrigger>
|
|
189
|
+
<SelectContent>
|
|
190
|
+
<SelectItem value="invoice">{t("export-page.types.invoice")}</SelectItem>
|
|
191
|
+
<SelectItem value="estimate">{t("export-page.types.estimate")}</SelectItem>
|
|
192
|
+
<SelectItem value="credit_note">{t("export-page.types.credit_note")}</SelectItem>
|
|
193
|
+
</SelectContent>
|
|
194
|
+
</Select>
|
|
195
|
+
</div>
|
|
196
|
+
|
|
197
|
+
{/* Export Format */}
|
|
198
|
+
<div className="space-y-2">
|
|
199
|
+
<Label htmlFor="export-format">{t("export-page.format")}</Label>
|
|
200
|
+
<Select value={exportFormat} onValueChange={(v) => setExportFormat(v as ExportFormat)}>
|
|
201
|
+
<SelectTrigger id="export-format">
|
|
202
|
+
<SelectValue />
|
|
203
|
+
</SelectTrigger>
|
|
204
|
+
<SelectContent>
|
|
205
|
+
<SelectItem value="xlsx">{t("export-page.formats.xlsx")}</SelectItem>
|
|
206
|
+
<SelectItem value="csv">{t("export-page.formats.csv")}</SelectItem>
|
|
207
|
+
<SelectItem value="pdf_zip">{t("export-page.formats.pdf_zip")}</SelectItem>
|
|
208
|
+
</SelectContent>
|
|
209
|
+
</Select>
|
|
210
|
+
{exportFormat === "pdf_zip" && (
|
|
211
|
+
<p className="text-muted-foreground text-sm">{t("export-page.pdf-export-info")}</p>
|
|
212
|
+
)}
|
|
213
|
+
</div>
|
|
214
|
+
|
|
215
|
+
{/* Date Range */}
|
|
216
|
+
<div className="grid grid-cols-2 gap-4">
|
|
217
|
+
<div className="space-y-2">
|
|
218
|
+
<Label htmlFor="date-from">{t("export-page.date-from")}</Label>
|
|
219
|
+
<div className="relative">
|
|
220
|
+
<Input
|
|
221
|
+
id="date-from"
|
|
222
|
+
type="date"
|
|
223
|
+
value={dateFrom}
|
|
224
|
+
onChange={(e) => {
|
|
225
|
+
setDateFrom(e.target.value);
|
|
226
|
+
validateDateRange(e.target.value, dateTo);
|
|
227
|
+
}}
|
|
228
|
+
onClick={(e) => (e.target as HTMLInputElement).showPicker?.()}
|
|
229
|
+
className="cursor-pointer pr-9 [&::-webkit-calendar-picker-indicator]:hidden"
|
|
230
|
+
/>
|
|
231
|
+
<Calendar className="pointer-events-none absolute top-1/2 right-2 h-4 w-4 -translate-y-1/2 text-muted-foreground" />
|
|
232
|
+
</div>
|
|
233
|
+
</div>
|
|
234
|
+
|
|
235
|
+
<div className="space-y-2">
|
|
236
|
+
<Label htmlFor="date-to">{t("export-page.date-to")}</Label>
|
|
237
|
+
<div className="relative">
|
|
238
|
+
<Input
|
|
239
|
+
id="date-to"
|
|
240
|
+
type="date"
|
|
241
|
+
value={dateTo}
|
|
242
|
+
onChange={(e) => {
|
|
243
|
+
setDateTo(e.target.value);
|
|
244
|
+
validateDateRange(dateFrom, e.target.value);
|
|
245
|
+
}}
|
|
246
|
+
onClick={(e) => (e.target as HTMLInputElement).showPicker?.()}
|
|
247
|
+
className={`cursor-pointer pr-9 [&::-webkit-calendar-picker-indicator]:hidden ${dateRangeError ? "border-destructive" : ""}`}
|
|
248
|
+
/>
|
|
249
|
+
<Calendar className="pointer-events-none absolute top-1/2 right-2 h-4 w-4 -translate-y-1/2 text-muted-foreground" />
|
|
250
|
+
</div>
|
|
251
|
+
</div>
|
|
252
|
+
</div>
|
|
253
|
+
|
|
254
|
+
{/* Date range error message */}
|
|
255
|
+
{dateRangeError && <p className="text-destructive text-sm">{t("export-page.error.date-range-exceeded")}</p>}
|
|
256
|
+
|
|
257
|
+
{/* Clear dates button */}
|
|
258
|
+
{(dateFrom || dateTo) && (
|
|
259
|
+
<Button
|
|
260
|
+
variant="ghost"
|
|
261
|
+
size="sm"
|
|
262
|
+
onClick={() => {
|
|
263
|
+
setDateFrom("");
|
|
264
|
+
setDateTo("");
|
|
265
|
+
setDateRangeError(false);
|
|
266
|
+
}}
|
|
267
|
+
>
|
|
268
|
+
{t("export-page.clear-dates")}
|
|
269
|
+
</Button>
|
|
270
|
+
)}
|
|
271
|
+
|
|
272
|
+
{/* Export Button */}
|
|
273
|
+
<Button onClick={handleExport} disabled={isExporting || dateRangeError} className="w-full" size="lg">
|
|
274
|
+
{isExporting ? (
|
|
275
|
+
<>
|
|
276
|
+
<Loader2 className="mr-2 h-4 w-4 animate-spin" />
|
|
277
|
+
{t("export-page.exporting")}
|
|
278
|
+
</>
|
|
279
|
+
) : (
|
|
280
|
+
<>
|
|
281
|
+
<Download className="mr-2 h-4 w-4" />
|
|
282
|
+
{t("export-page.export-button")}
|
|
283
|
+
</>
|
|
284
|
+
)}
|
|
285
|
+
</Button>
|
|
286
|
+
</div>
|
|
287
|
+
);
|
|
288
|
+
}
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
import { forwardRef } from "react";
|
|
2
|
+
import type { FieldPath, FieldValues } from "react-hook-form";
|
|
3
|
+
import { FormControl, FormField, FormItem, FormLabel, FormMessage } from "@/ui/components/ui/form";
|
|
4
|
+
import { Input } from "@/ui/components/ui/input";
|
|
5
|
+
|
|
6
|
+
type FormInputProps<
|
|
7
|
+
TFieldValues extends FieldValues = FieldValues,
|
|
8
|
+
TName extends FieldPath<TFieldValues> = FieldPath<TFieldValues>,
|
|
9
|
+
> = {
|
|
10
|
+
control: any;
|
|
11
|
+
name: TName;
|
|
12
|
+
label: string;
|
|
13
|
+
placeholder?: string;
|
|
14
|
+
type?: "text" | "number" | "email" | "password" | "tel" | "url";
|
|
15
|
+
disabled?: boolean;
|
|
16
|
+
autoComplete?: string;
|
|
17
|
+
onChange?: (value: any) => void;
|
|
18
|
+
className?: string;
|
|
19
|
+
required?: boolean;
|
|
20
|
+
};
|
|
21
|
+
|
|
22
|
+
const FormInputComponent = <
|
|
23
|
+
TFieldValues extends FieldValues = FieldValues,
|
|
24
|
+
TName extends FieldPath<TFieldValues> = FieldPath<TFieldValues>,
|
|
25
|
+
>(
|
|
26
|
+
{
|
|
27
|
+
control,
|
|
28
|
+
name,
|
|
29
|
+
label,
|
|
30
|
+
placeholder,
|
|
31
|
+
type = "text",
|
|
32
|
+
disabled,
|
|
33
|
+
autoComplete,
|
|
34
|
+
onChange,
|
|
35
|
+
className,
|
|
36
|
+
required = false,
|
|
37
|
+
}: FormInputProps<TFieldValues, TName>,
|
|
38
|
+
ref: React.Ref<HTMLInputElement>,
|
|
39
|
+
) => {
|
|
40
|
+
const handleFieldChange = (field: any, e: React.ChangeEvent<HTMLInputElement>) => {
|
|
41
|
+
if (type === "number") {
|
|
42
|
+
const value = Number(e.target.value);
|
|
43
|
+
field.onChange(value);
|
|
44
|
+
onChange?.(value);
|
|
45
|
+
} else {
|
|
46
|
+
// Convert empty strings to undefined to prevent sending empty strings to API
|
|
47
|
+
const value = e.target.value === "" ? undefined : e.target.value;
|
|
48
|
+
field.onChange(value);
|
|
49
|
+
onChange?.(value);
|
|
50
|
+
}
|
|
51
|
+
};
|
|
52
|
+
|
|
53
|
+
return (
|
|
54
|
+
<FormField
|
|
55
|
+
control={control}
|
|
56
|
+
name={name}
|
|
57
|
+
render={({ field }) => (
|
|
58
|
+
<FormItem className={className}>
|
|
59
|
+
{label && (
|
|
60
|
+
<FormLabel>
|
|
61
|
+
{label}
|
|
62
|
+
{required && <span className="ml-1 text-red-500">*</span>}
|
|
63
|
+
</FormLabel>
|
|
64
|
+
)}
|
|
65
|
+
<FormControl>
|
|
66
|
+
<Input
|
|
67
|
+
type={type}
|
|
68
|
+
placeholder={placeholder}
|
|
69
|
+
disabled={disabled}
|
|
70
|
+
autoComplete={autoComplete}
|
|
71
|
+
{...field}
|
|
72
|
+
ref={ref}
|
|
73
|
+
value={field.value ?? ""}
|
|
74
|
+
onChange={(e) => handleFieldChange(field, e)}
|
|
75
|
+
/>
|
|
76
|
+
</FormControl>
|
|
77
|
+
<FormMessage />
|
|
78
|
+
</FormItem>
|
|
79
|
+
)}
|
|
80
|
+
/>
|
|
81
|
+
);
|
|
82
|
+
};
|
|
83
|
+
|
|
84
|
+
export const FormInput = forwardRef(FormInputComponent) as <
|
|
85
|
+
TFieldValues extends FieldValues = FieldValues,
|
|
86
|
+
TName extends FieldPath<TFieldValues> = FieldPath<TFieldValues>,
|
|
87
|
+
>(
|
|
88
|
+
props: FormInputProps<TFieldValues, TName> & { ref?: React.Ref<HTMLInputElement> },
|
|
89
|
+
) => ReturnType<typeof FormInputComponent>;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { FormInput } from "./form-input";
|