mirror of
https://github.com/rennf93/roboco.git
synced 2026-08-03 07:23:24 +02:00
Apply `pnpm format` (prettier 3.8.5, 80-col / double-quote / semi /
trailing-comma-all) to the 223 pre-existing panel files that predated the
prettier infra added in cb5365a4. Pure formatting — no semantic changes:
multi-line arrays/objects collapsed where they fit, trailing newlines added
(.prettierrc.json), import grouping unchanged.
Verified: `pnpm format:check` clean, `pnpm lint` clean, `pnpm typecheck`
clean, `pnpm test` 113/113 pass (7 files).
55 lines
1.6 KiB
TypeScript
55 lines
1.6 KiB
TypeScript
import { useMutation, useQuery, useQueryClient } from "@tanstack/react-query";
|
|
import { productsApi } from "@/lib/api";
|
|
import type { ProductCreate, ProductUpdate } from "@/types";
|
|
|
|
export const productKeys = {
|
|
all: ["products"] as const,
|
|
lists: () => [...productKeys.all, "list"] as const,
|
|
details: () => [...productKeys.all, "detail"] as const,
|
|
detail: (id: string) => [...productKeys.details(), id] as const,
|
|
};
|
|
|
|
export function useProducts() {
|
|
return useQuery({
|
|
queryKey: productKeys.lists(),
|
|
queryFn: () => productsApi.list(),
|
|
staleTime: 60000,
|
|
});
|
|
}
|
|
|
|
export function useProduct(id: string) {
|
|
return useQuery({
|
|
queryKey: productKeys.detail(id),
|
|
queryFn: () => productsApi.get(id),
|
|
enabled: !!id,
|
|
});
|
|
}
|
|
|
|
export function useCreateProduct() {
|
|
const qc = useQueryClient();
|
|
return useMutation({
|
|
mutationFn: (p: ProductCreate) => productsApi.create(p),
|
|
onSuccess: () => qc.invalidateQueries({ queryKey: productKeys.lists() }),
|
|
});
|
|
}
|
|
|
|
export function useUpdateProduct() {
|
|
const qc = useQueryClient();
|
|
return useMutation({
|
|
mutationFn: ({ id, patch }: { id: string; patch: ProductUpdate }) =>
|
|
productsApi.update(id, patch),
|
|
onSuccess: (_d, v) => {
|
|
qc.invalidateQueries({ queryKey: productKeys.lists() });
|
|
qc.invalidateQueries({ queryKey: productKeys.detail(v.id) });
|
|
},
|
|
});
|
|
}
|
|
|
|
export function useDeleteProduct() {
|
|
const qc = useQueryClient();
|
|
return useMutation({
|
|
mutationFn: (id: string) => productsApi.delete(id),
|
|
onSuccess: () => qc.invalidateQueries({ queryKey: productKeys.lists() }),
|
|
});
|
|
}
|