- Replace hand-coded skeleton CSS/JSX with boneyard-js auto-generated bones - Remove skeleton.css and @keyframes shimmer from base.css - Add <Skeleton> wrappers with fixtures to all 25+ page components - Generate 20 bone captures via boneyard CLI (CDP auth-gated capture) - Refactor data fetching from useEffect+useState to TanStack Query - Extract query hooks into src/admin/lib/queries/ and apiAdapter - Add usePaginatedQuery hook replacing useApiCall/useListData - Fix parseFloat || 0 anti-pattern in OfferDetail and OffersTemplates inputs - Fix customer_id mandatory validation on offer creation - Fix leave-requests comma-separated status filter (Prisma enum in: []) - Add cross-entity cache invalidation for orders/offers/invoices/projects - Make rate limits configurable via env vars (RATE_LIMIT_MAX, RATE_LIMIT_REFRESH, etc.) - Add boneyard.config.json with routes and breakpoints Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
127 lines
3.6 KiB
TypeScript
127 lines
3.6 KiB
TypeScript
import { queryOptions } from "@tanstack/react-query";
|
|
import { jsonQuery, paginatedJsonQuery } from "../apiAdapter";
|
|
|
|
export interface CurrencyAmount {
|
|
amount: number;
|
|
currency: string;
|
|
}
|
|
|
|
export interface Invoice {
|
|
id: number;
|
|
invoice_number: string;
|
|
customer_name: string | null;
|
|
status: string;
|
|
issue_date: string;
|
|
due_date: string;
|
|
total: number;
|
|
currency: string;
|
|
}
|
|
|
|
export interface InvoiceStats {
|
|
paid_month: CurrencyAmount[];
|
|
paid_month_czk: number;
|
|
paid_month_count: number;
|
|
awaiting: CurrencyAmount[];
|
|
awaiting_czk: number;
|
|
awaiting_count: number;
|
|
overdue: CurrencyAmount[];
|
|
overdue_czk: number;
|
|
overdue_count: number;
|
|
vat_month: CurrencyAmount[];
|
|
vat_month_czk: number;
|
|
}
|
|
|
|
export const invoiceListOptions = (filters: {
|
|
search?: string;
|
|
sort?: string;
|
|
order?: string;
|
|
page?: number;
|
|
perPage?: number;
|
|
month?: number;
|
|
year?: number;
|
|
status?: string;
|
|
}) =>
|
|
queryOptions({
|
|
queryKey: ["invoices", "list", filters],
|
|
queryFn: () => {
|
|
const params = new URLSearchParams();
|
|
if (filters.search) params.set("search", filters.search);
|
|
if (filters.sort) params.set("sort", filters.sort);
|
|
if (filters.order) params.set("order", filters.order);
|
|
if (filters.page) params.set("page", String(filters.page));
|
|
if (filters.perPage) params.set("per_page", String(filters.perPage));
|
|
if (filters.month) params.set("month", String(filters.month));
|
|
if (filters.year) params.set("year", String(filters.year));
|
|
if (filters.status) params.set("status", filters.status);
|
|
const qs = params.toString();
|
|
return paginatedJsonQuery<Invoice>(
|
|
`/api/admin/invoices${qs ? `?${qs}` : ""}`,
|
|
);
|
|
},
|
|
});
|
|
|
|
export const receivedInvoiceListOptions = (filters: {
|
|
month?: number;
|
|
year?: number;
|
|
search?: string;
|
|
sort?: string;
|
|
order?: string;
|
|
page?: number;
|
|
perPage?: number;
|
|
}) =>
|
|
queryOptions({
|
|
queryKey: [
|
|
"invoices",
|
|
"received",
|
|
{
|
|
month: filters.month,
|
|
year: filters.year,
|
|
search: filters.search,
|
|
sort: filters.sort,
|
|
order: filters.order,
|
|
page: filters.page,
|
|
perPage: filters.perPage,
|
|
},
|
|
],
|
|
queryFn: () => {
|
|
const params = new URLSearchParams();
|
|
if (filters.month) params.set("month", String(filters.month));
|
|
if (filters.year) params.set("year", String(filters.year));
|
|
if (filters.search) params.set("search", filters.search);
|
|
if (filters.sort) params.set("sort", filters.sort);
|
|
if (filters.order) params.set("order", filters.order);
|
|
if (filters.page) params.set("page", String(filters.page));
|
|
if (filters.perPage) params.set("per_page", String(filters.perPage));
|
|
const qs = params.toString();
|
|
return paginatedJsonQuery(
|
|
`/api/admin/received-invoices${qs ? `?${qs}` : ""}`,
|
|
);
|
|
},
|
|
});
|
|
|
|
export const invoiceStatsOptions = (month: number, year: number) =>
|
|
queryOptions({
|
|
queryKey: ["invoices", "stats", month, year],
|
|
queryFn: () =>
|
|
jsonQuery<InvoiceStats>(
|
|
`/api/admin/invoices/stats?month=${month}&year=${year}`,
|
|
),
|
|
});
|
|
|
|
export const receivedInvoiceStatsOptions = (month: number, year: number) =>
|
|
queryOptions({
|
|
queryKey: ["invoices", "received", "stats", month, year],
|
|
queryFn: () =>
|
|
jsonQuery<Record<string, unknown>>(
|
|
`/api/admin/received-invoices/stats?month=${month}&year=${year}`,
|
|
),
|
|
});
|
|
|
|
export const invoiceDetailOptions = (id: string | undefined) =>
|
|
queryOptions({
|
|
queryKey: ["invoices", id],
|
|
queryFn: () =>
|
|
jsonQuery<Record<string, unknown>>(`/api/admin/invoices/${id}`),
|
|
enabled: !!id,
|
|
});
|