v1.5.6: boneyard-js skeleton migration, TanStack Query refactor, rate-limit config
- 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>
This commit is contained in:
78
src/admin/lib/queries/projects.ts
Normal file
78
src/admin/lib/queries/projects.ts
Normal file
@@ -0,0 +1,78 @@
|
||||
import { queryOptions } from "@tanstack/react-query";
|
||||
import { jsonQuery, paginatedJsonQuery } from "../apiAdapter";
|
||||
import apiFetch from "../../utils/api";
|
||||
|
||||
export const projectListOptions = (filters: {
|
||||
search?: string;
|
||||
sort?: string;
|
||||
order?: string;
|
||||
page?: number;
|
||||
perPage?: number;
|
||||
}) =>
|
||||
queryOptions({
|
||||
queryKey: ["projects", "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));
|
||||
const qs = params.toString();
|
||||
return paginatedJsonQuery(`/api/admin/projects${qs ? `?${qs}` : ""}`);
|
||||
},
|
||||
});
|
||||
|
||||
export const projectDetailOptions = (id: string | undefined) =>
|
||||
queryOptions({
|
||||
queryKey: ["projects", id],
|
||||
queryFn: () =>
|
||||
jsonQuery<Record<string, unknown>>(`/api/admin/projects/${id}`),
|
||||
enabled: !!id,
|
||||
});
|
||||
|
||||
export interface ProjectFilesData {
|
||||
items: Array<{
|
||||
name: string;
|
||||
type: "file" | "folder";
|
||||
size?: number;
|
||||
size_formatted?: string;
|
||||
modified?: string;
|
||||
extension?: string;
|
||||
item_count?: number;
|
||||
is_symlink?: boolean;
|
||||
link_target?: string;
|
||||
}>;
|
||||
breadcrumb: string[];
|
||||
path: string;
|
||||
full_path: string;
|
||||
}
|
||||
|
||||
export const projectFilesOptions = (projectId: number, path: string) =>
|
||||
queryOptions({
|
||||
queryKey: ["projects", String(projectId), "files", path],
|
||||
queryFn: async (): Promise<ProjectFilesData> => {
|
||||
const params = new URLSearchParams({ project_id: String(projectId) });
|
||||
if (path) params.set("path", path);
|
||||
let res: Response;
|
||||
try {
|
||||
res = await apiFetch(`/api/admin/project-files?${params}`);
|
||||
} catch {
|
||||
throw new Error("Chyba připojení");
|
||||
}
|
||||
if (res.status === 401) throw new Error("Unauthorized");
|
||||
if (res.status === 404) {
|
||||
return { items: [], breadcrumb: [""], path: "", full_path: "" };
|
||||
}
|
||||
const data = await res.json();
|
||||
if (!res.ok || !data.success) {
|
||||
throw new Error(data.error || `Request failed (${res.status})`);
|
||||
}
|
||||
return {
|
||||
items: data.data.items || [],
|
||||
breadcrumb: data.data.breadcrumb || [""],
|
||||
path: data.data.path || "",
|
||||
full_path: data.data.full_path || "",
|
||||
};
|
||||
},
|
||||
});
|
||||
Reference in New Issue
Block a user