@spaceinvoices/react-ui 0.4.6 → 0.4.7
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/cli/dist/index.js +1 -1
- package/package.json +1 -1
- package/src/components/advance-invoices/create/create-advance-invoice-form.tsx +60 -44
- package/src/components/credit-notes/create/create-credit-note-form.tsx +52 -42
- package/src/components/dashboard/collection-rate-card/use-collection-rate.ts +48 -92
- package/src/components/dashboard/invoice-status-chart/use-invoice-status.ts +48 -82
- package/src/components/dashboard/payment-methods-chart/use-payment-methods.ts +22 -31
- package/src/components/dashboard/payment-trend-chart/use-payment-trend.ts +33 -48
- package/src/components/dashboard/revenue-trend-chart/use-revenue-trend.ts +56 -76
- package/src/components/dashboard/shared/index.ts +1 -1
- package/src/components/dashboard/shared/use-revenue-data.ts +106 -182
- package/src/components/dashboard/shared/use-stats-counts.ts +18 -68
- package/src/components/dashboard/shared/use-stats-query.ts +35 -5
- package/src/components/dashboard/tax-collected-card/use-tax-collected.ts +57 -75
- package/src/components/dashboard/top-customers-chart/use-top-customers.ts +38 -49
- package/src/components/delivery-notes/create/create-delivery-note-form.tsx +3 -2
- package/src/components/documents/create/document-details-section.tsx +6 -4
- package/src/components/documents/create/document-recipient-section.tsx +30 -1
- package/src/components/documents/create/live-preview.tsx +15 -28
- package/src/components/documents/create/prepare-document-submission.ts +1 -0
- package/src/components/documents/create/use-document-customer-form.ts +4 -0
- package/src/components/documents/shared/document-preview-skeleton.tsx +63 -0
- package/src/components/documents/shared/index.ts +1 -0
- package/src/components/documents/view/document-actions-bar.tsx +29 -7
- package/src/components/entities/settings/tax-rules-settings-form.tsx +31 -13
- package/src/components/estimates/create/create-estimate-form.tsx +3 -2
- package/src/components/invoices/create/create-invoice-form.tsx +134 -62
- package/src/components/invoices/create/locales/de.ts +6 -0
- package/src/components/invoices/create/locales/es.ts +6 -0
- package/src/components/invoices/create/locales/fr.ts +6 -0
- package/src/components/invoices/create/locales/hr.ts +6 -0
- package/src/components/invoices/create/locales/it.ts +6 -0
- package/src/components/invoices/create/locales/nl.ts +6 -0
- package/src/components/invoices/create/locales/pl.ts +6 -0
- package/src/components/invoices/create/locales/pt.ts +6 -0
- package/src/components/invoices/create/locales/sl.ts +6 -0
- package/src/components/invoices/invoices.hooks.ts +1 -1
- package/src/components/ui/progress.tsx +27 -0
- package/src/generate-schemas.ts +15 -2
- package/src/generated/schemas/advanceinvoice.ts +2 -0
- package/src/generated/schemas/creditnote.ts +2 -0
- package/src/generated/schemas/customer.ts +2 -0
- package/src/generated/schemas/deliverynote.ts +2 -0
- package/src/generated/schemas/entity.ts +10 -0
- package/src/generated/schemas/estimate.ts +2 -0
- package/src/generated/schemas/finasettings.ts +4 -3
- package/src/generated/schemas/invoice.ts +2 -0
- package/src/generated/schemas/renderadvanceinvoicepreview_body.ts +16 -10
- package/src/generated/schemas/rendercreditnotepreview_body.ts +16 -10
- package/src/generated/schemas/renderdeliverynotepreview_body.ts +14 -7
- package/src/generated/schemas/renderestimatepreview_body.ts +14 -7
- package/src/generated/schemas/renderinvoicepreview_body.ts +16 -10
- package/src/generated/schemas/startpdfexport_body.ts +12 -17
- package/src/hooks/use-transaction-type-check.ts +152 -0
- package/src/hooks/use-vies-check.ts +7 -131
|
@@ -1,133 +1,9 @@
|
|
|
1
|
-
import type { ViesCheckRequest, ViesCheckResponse } from "@spaceinvoices/js-sdk";
|
|
2
|
-
import { useQuery } from "@tanstack/react-query";
|
|
3
|
-
import { useMemo } from "react";
|
|
4
|
-
import { useSDK } from "../providers/sdk-provider";
|
|
5
|
-
import { useDebounce } from "./use-debounce";
|
|
6
|
-
|
|
7
|
-
export const VIES_CHECK_CACHE_KEY = "vies-check";
|
|
8
|
-
|
|
9
|
-
/** Debounce delay for VIES checks (ms) */
|
|
10
|
-
const VIES_DEBOUNCE_DELAY = 500;
|
|
11
|
-
|
|
12
|
-
/** Cache time for VIES results - 5 minutes */
|
|
13
|
-
const VIES_STALE_TIME = 5 * 60 * 1000;
|
|
14
|
-
|
|
15
|
-
export interface UseViesCheckParams {
|
|
16
|
-
/** Issuer country name or code */
|
|
17
|
-
issuerCountry?: string | null;
|
|
18
|
-
/** Issuer country code (takes precedence over country name) */
|
|
19
|
-
issuerCountryCode?: string | null;
|
|
20
|
-
/** Whether the issuer is a tax subject (default: true) */
|
|
21
|
-
isTaxSubject?: boolean;
|
|
22
|
-
/** Customer country name or code */
|
|
23
|
-
customerCountry?: string | null;
|
|
24
|
-
/** Customer country code (takes precedence over country name) */
|
|
25
|
-
customerCountryCode?: string | null;
|
|
26
|
-
/** Customer VAT/tax number */
|
|
27
|
-
customerTaxNumber?: string | null;
|
|
28
|
-
/** Whether to enable the query (default: true) */
|
|
29
|
-
enabled?: boolean;
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
export interface UseViesCheckResult {
|
|
33
|
-
/** The VIES check result */
|
|
34
|
-
data: ViesCheckResponse | undefined;
|
|
35
|
-
/** Whether the query is loading */
|
|
36
|
-
isLoading: boolean;
|
|
37
|
-
/** Whether the query is fetching (includes background refetches) */
|
|
38
|
-
isFetching: boolean;
|
|
39
|
-
/** Error if the query failed */
|
|
40
|
-
error: Error | null;
|
|
41
|
-
/** Whether reverse charge should be applied */
|
|
42
|
-
reverseChargeApplies: boolean;
|
|
43
|
-
/** Transaction type determined by VIES check */
|
|
44
|
-
transactionType: ViesCheckResponse["transaction_type"] | undefined;
|
|
45
|
-
/** Customer country code returned by VIES check */
|
|
46
|
-
customerCountryCode: string | null;
|
|
47
|
-
/** Warning message from VIES validation */
|
|
48
|
-
warning: string | null;
|
|
49
|
-
/** Whether VIES validation was successful */
|
|
50
|
-
viesValid: boolean | null;
|
|
51
|
-
}
|
|
52
|
-
|
|
53
1
|
/**
|
|
54
|
-
*
|
|
55
|
-
* Uses debouncing to avoid excessive API calls during typing.
|
|
56
|
-
*
|
|
57
|
-
* @example
|
|
58
|
-
* ```tsx
|
|
59
|
-
* const { reverseChargeApplies, transactionType, warning } = useViesCheck({
|
|
60
|
-
* issuerCountryCode: entity.country_code,
|
|
61
|
-
* isTaxSubject: entity.is_tax_subject,
|
|
62
|
-
* customerCountry: customer.country,
|
|
63
|
-
* customerTaxNumber: customer.tax_number,
|
|
64
|
-
* });
|
|
65
|
-
*
|
|
66
|
-
* // Disable taxes when reverse charge applies
|
|
67
|
-
* if (reverseChargeApplies) {
|
|
68
|
-
* // Show reverse charge message and disable tax controls
|
|
69
|
-
* }
|
|
70
|
-
* ```
|
|
2
|
+
* @deprecated Use use-transaction-type-check.ts instead
|
|
71
3
|
*/
|
|
72
|
-
export
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
customerTaxNumber,
|
|
79
|
-
enabled = true,
|
|
80
|
-
}: UseViesCheckParams): UseViesCheckResult {
|
|
81
|
-
const { sdk } = useSDK();
|
|
82
|
-
|
|
83
|
-
// Build the request object
|
|
84
|
-
const requestData = useMemo((): ViesCheckRequest | null => {
|
|
85
|
-
// Need at least issuer info to make a check
|
|
86
|
-
if (!issuerCountry && !issuerCountryCode) return null;
|
|
87
|
-
|
|
88
|
-
// Need at least some customer info to make a meaningful check
|
|
89
|
-
if (!customerCountry && !customerCountryCode && !customerTaxNumber) return null;
|
|
90
|
-
|
|
91
|
-
return {
|
|
92
|
-
issuer: {
|
|
93
|
-
country: issuerCountry || undefined,
|
|
94
|
-
country_code: issuerCountryCode || undefined,
|
|
95
|
-
is_tax_subject: isTaxSubject,
|
|
96
|
-
},
|
|
97
|
-
customer: {
|
|
98
|
-
country: customerCountry || undefined,
|
|
99
|
-
country_code: customerCountryCode || undefined,
|
|
100
|
-
tax_number: customerTaxNumber || undefined,
|
|
101
|
-
},
|
|
102
|
-
};
|
|
103
|
-
}, [issuerCountry, issuerCountryCode, isTaxSubject, customerCountry, customerCountryCode, customerTaxNumber]);
|
|
104
|
-
|
|
105
|
-
// Debounce the request data to avoid excessive API calls
|
|
106
|
-
const debouncedRequest = useDebounce(requestData, VIES_DEBOUNCE_DELAY);
|
|
107
|
-
|
|
108
|
-
// Create a stable query key
|
|
109
|
-
const queryKey = useMemo(() => [VIES_CHECK_CACHE_KEY, debouncedRequest], [debouncedRequest]);
|
|
110
|
-
|
|
111
|
-
const query = useQuery({
|
|
112
|
-
queryKey,
|
|
113
|
-
queryFn: async () => {
|
|
114
|
-
if (!debouncedRequest) throw new Error("No request data");
|
|
115
|
-
return sdk.vies.checkVies(debouncedRequest);
|
|
116
|
-
},
|
|
117
|
-
enabled: enabled && !!sdk && !!debouncedRequest,
|
|
118
|
-
staleTime: VIES_STALE_TIME,
|
|
119
|
-
refetchOnWindowFocus: false,
|
|
120
|
-
});
|
|
121
|
-
|
|
122
|
-
return {
|
|
123
|
-
data: query.data,
|
|
124
|
-
isLoading: query.isLoading,
|
|
125
|
-
isFetching: query.isFetching,
|
|
126
|
-
error: query.error,
|
|
127
|
-
reverseChargeApplies: query.data?.reverse_charge_applies ?? false,
|
|
128
|
-
transactionType: query.data?.transaction_type,
|
|
129
|
-
customerCountryCode: query.data?.customer_country_code ?? null,
|
|
130
|
-
warning: query.data?.warning ?? null,
|
|
131
|
-
viesValid: query.data?.vies_valid ?? null,
|
|
132
|
-
};
|
|
133
|
-
}
|
|
4
|
+
export {
|
|
5
|
+
TRANSACTION_TYPE_CHECK_CACHE_KEY as VIES_CHECK_CACHE_KEY,
|
|
6
|
+
type UseTransactionTypeCheckParams as UseViesCheckParams,
|
|
7
|
+
type UseTransactionTypeCheckResult as UseViesCheckResult,
|
|
8
|
+
useTransactionTypeCheck as useViesCheck,
|
|
9
|
+
} from "./use-transaction-type-check";
|