Skip to content

Open-source event management and ticket selling platform — perfect for concerts, conferences, and everything in between 🎟️ If you find this project helpful, please consider giving us a star ⭐️

1.1 KB
Raw Blame
import { useQuery } from "@tanstack/react-query";
import { IdParam } from "../types.ts";
import { eventsClient } from "../api/event.client.ts";

export const GET_EVENT_REPORT_QUERY_KEY = 'getEventReport';

export const useGetEventReport = (
    eventId: IdParam,
    reportType: IdParam,
    startDate?: Date | null,
    endDate?: Date | null,
    occurrenceId?: IdParam,
) => {
    return useQuery({
        queryKey: [
            GET_EVENT_REPORT_QUERY_KEY,
            eventId,
            reportType,
            startDate?.toISOString(),
            endDate?.toISOString(),
            occurrenceId,
        ],
        queryFn: async () => {
            const startDateString = startDate?.toISOString();
            const endDateString = endDate?.toISOString();

            return await eventsClient.getEventReport(
                eventId,
                reportType,
                startDateString,
                endDateString,
                occurrenceId,
            );
        },
        enabled: !!eventId && !!reportType && (!!startDate && !!endDate) || (!startDate && !endDate)
    });
};