From e59bbc7a1168d220f9d254d47dfe0b59b7aaf9cb Mon Sep 17 00:00:00 2001 From: Leopoldadmin Date: Sat, 4 Jul 2026 00:27:20 +0000 Subject: [PATCH] feat(core): add system settings, currency, tax, sequence API hooks --- frontend/src/api/hooks.ts | 172 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 172 insertions(+) diff --git a/frontend/src/api/hooks.ts b/frontend/src/api/hooks.ts index 737c6d3..eb47577 100644 --- a/frontend/src/api/hooks.ts +++ b/frontend/src/api/hooks.ts @@ -553,3 +553,175 @@ export function useDeleteRole() { }, }); } + +// ═══════════════════════════════════════════════════════════════ +// System Settings, Currency, Tax, Sequence hooks +// ═══════════════════════════════════════════════════════════════ + +export interface Currency { + id: string; + code: string; + name: string; + symbol: string; + is_default: boolean; + created_at?: string; + updated_at?: string; +} + +export interface TaxRate { + id: string; + name: string; + rate: number; + is_default: boolean; + country?: string | null; + created_at?: string; + updated_at?: string; +} + +export interface Sequence { + id: string; + name: string; + prefix: string; + next_number: number; + padding: number; + created_at?: string; + updated_at?: string; +} + +export interface SystemSettings { + id?: string; + company_name: string; + company_legal_form?: string | null; + company_street: string; + company_city: string; + company_zip: string; + company_country: string; + tax_number?: string | null; + vat_id?: string | null; + iban?: string | null; + bic?: string | null; + bank_name?: string | null; + ceo?: string | null; + trade_register?: string | null; + default_currency_id?: string | null; + default_tax_id?: string | null; + invoice_prefix: string; + quote_prefix: string; + payment_terms_days: number; + created_at?: string; + updated_at?: string; +} + +// System Settings +export function useSystemSettings() { + return useQuery({ + queryKey: ['systemSettings'], + queryFn: () => apiGet('/system-settings'), + }); +} + +export function useUpdateSystemSettings() { + const queryClient = useQueryClient(); + return useMutation({ + mutationFn: (data: Partial) => apiClient.put('/system-settings', data).then(r => r.data), + onSuccess: () => { + queryClient.invalidateQueries({ queryKey: ['systemSettings'] }); + }, + }); +} + +// Currencies +export function useCurrencies() { + return useQuery({ + queryKey: ['currencies'], + queryFn: () => apiGet<{ items: Currency[]; total: number }>('/currencies'), + }); +} + +export function useCreateCurrency() { + const queryClient = useQueryClient(); + return useMutation({ + mutationFn: (data: Partial) => apiPost('/currencies', data), + onSuccess: () => { + queryClient.invalidateQueries({ queryKey: ['currencies'] }); + }, + }); +} + +export function useUpdateCurrency() { + const queryClient = useQueryClient(); + return useMutation({ + mutationFn: ({ id, data }: { id: string; data: Partial }) => + apiPatch(`/currencies/${id}`, data), + onSuccess: () => { + queryClient.invalidateQueries({ queryKey: ['currencies'] }); + }, + }); +} + +export function useDeleteCurrency() { + const queryClient = useQueryClient(); + return useMutation({ + mutationFn: (id: string) => apiDelete(`/currencies/${id}`), + onSuccess: () => { + queryClient.invalidateQueries({ queryKey: ['currencies'] }); + }, + }); +} + +// Taxes +export function useTaxes() { + return useQuery({ + queryKey: ['taxes'], + queryFn: () => apiGet<{ items: TaxRate[]; total: number }>('/taxes'), + }); +} + +export function useCreateTax() { + const queryClient = useQueryClient(); + return useMutation({ + mutationFn: (data: Partial) => apiPost('/taxes', data), + onSuccess: () => { + queryClient.invalidateQueries({ queryKey: ['taxes'] }); + }, + }); +} + +export function useUpdateTax() { + const queryClient = useQueryClient(); + return useMutation({ + mutationFn: ({ id, data }: { id: string; data: Partial }) => + apiPatch(`/taxes/${id}`, data), + onSuccess: () => { + queryClient.invalidateQueries({ queryKey: ['taxes'] }); + }, + }); +} + +export function useDeleteTax() { + const queryClient = useQueryClient(); + return useMutation({ + mutationFn: (id: string) => apiDelete(`/taxes/${id}`), + onSuccess: () => { + queryClient.invalidateQueries({ queryKey: ['taxes'] }); + }, + }); +} + +// Sequences +export function useSequences() { + return useQuery({ + queryKey: ['sequences'], + queryFn: () => apiGet<{ items: Sequence[]; total: number }>('/sequences'), + }); +} + +export function useCreateSequence() { + const queryClient = useQueryClient(); + return useMutation({ + mutationFn: (data: Partial) => apiPost('/sequences', data), + onSuccess: () => { + queryClient.invalidateQueries({ queryKey: ['sequences'] }); + }, + }); +}