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 ⭐️

951 B
Raw Blame
import {IdParam, Product} from "../types.ts";
import {productClient} from "../api/product.client.ts";
import {queryClient} from "../utilites/queryClient.ts";
import {GET_EVENT_PRODUCT_CATEGORIES_QUERY_KEY} from "../queries/useGetProductCategories.ts";
import {GET_EVENT_QUERY_KEY} from "../queries/useGetEvent.ts";
import {useMutation} from "@tanstack/react-query";

export const useCreateProduct = () => {
    return useMutation({
        mutationFn: ({productData, eventId}: {
            eventId: IdParam,
            productData: Product,
        }) => productClient.create(eventId, productData),

        onSuccess: (_, variables) => {
            return Promise.all([
                queryClient.invalidateQueries({
                    queryKey: [GET_EVENT_PRODUCT_CATEGORIES_QUERY_KEY, variables.eventId],
                }),
                queryClient.invalidateQueries({queryKey: [GET_EVENT_QUERY_KEY]}),
            ]);
        }
    });
}