import { useQuery } from "@tanstack/react-query"; import * as auditService from "@/services/audit.service"; import type { PageResult, Audits } from "@/types/audit"; const AUDIT_QUERY_KEYS = { all: ["audit"] as const, list: () => [...AUDIT_QUERY_KEYS.all, "list"] as const, audits: (params: any) => [...AUDIT_QUERY_KEYS.all, "audits", params] as const, }; export function useGetAudits( params: { pageNumber?: number; pageSize?: number; username?: string | null; action?: string | null; from?: string | null; to?: string | null; } = { pageNumber: 1, pageSize: 20 }, enabled = true ) { const { pageNumber = 1, pageSize = 20, username, action, from, to } = params; return useQuery>({ queryKey: AUDIT_QUERY_KEYS.audits({ pageNumber, pageSize, username, action, from, to }), queryFn: () => auditService.getAudits( pageNumber, pageSize, username ?? null, action ?? null, from ?? null, to ?? null ), enabled, }); }