Extract cleanParams helper to deduplicate query param cleaning
The identical strip-undefined-values loop was duplicated in useTickets and useTicketsPaged. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -27,14 +27,20 @@ export const qk = {
|
||||
analytics: (window: number) => ['analytics', window] as const,
|
||||
};
|
||||
|
||||
// ── Tickets ──────────────────────────────────────────────────────────────────
|
||||
// ── Helpers ─────────────────────────────────────────────────────────────────
|
||||
|
||||
export function useTickets(params: Record<string, string | number | undefined> = {}) {
|
||||
// Strip undefined values for a stable key
|
||||
function cleanParams(params: Record<string, string | number | undefined>): Record<string, string | number> {
|
||||
const clean: Record<string, string | number> = {};
|
||||
Object.entries(params).forEach(([k, v]) => {
|
||||
if (v !== undefined && v !== '' && v !== null) clean[k] = v;
|
||||
});
|
||||
return clean;
|
||||
}
|
||||
|
||||
// ── Tickets ──────────────────────────────────────────────────────────────────
|
||||
|
||||
export function useTickets(params: Record<string, string | number | undefined> = {}) {
|
||||
const clean = cleanParams(params);
|
||||
|
||||
return useQuery({
|
||||
queryKey: qk.tickets(clean),
|
||||
@@ -47,10 +53,7 @@ export function useTickets(params: Record<string, string | number | undefined> =
|
||||
}
|
||||
|
||||
export function useTicketsPaged(params: Record<string, string | number | undefined> = {}) {
|
||||
const clean: Record<string, string | number> = {};
|
||||
Object.entries(params).forEach(([k, v]) => {
|
||||
if (v !== undefined && v !== '' && v !== null) clean[k] = v;
|
||||
});
|
||||
const clean = cleanParams(params);
|
||||
|
||||
return useQuery({
|
||||
queryKey: qk.ticketsPaged(clean),
|
||||
|
||||
Reference in New Issue
Block a user