import { useMutation } from "@tanstack/react-query"; import { SUCCESS_STATUS } from "@calcom/platform-constants"; import type { BookingResponse, RecurringBookingCreateBody } from "@calcom/platform-libraries"; import type { ApiResponse, ApiErrorResponse, ApiSuccessResponse } from "@calcom/platform-types"; import http from "../lib/http"; interface IUseCreateRecurringBooking { onSuccess?: (res: ApiSuccessResponse) => void; onError?: (err: ApiErrorResponse | Error) => void; } export const useCreateRecurringBooking = ( { onSuccess, onError }: IUseCreateRecurringBooking = { onSuccess: () => { return; }, onError: () => { return; }, } ) => { const createRecurringBooking = useMutation< ApiResponse, Error, RecurringBookingCreateBody[] >({ mutationFn: (data) => { return http.post>("/bookings/recurring", data).then((res) => res.data); }, onSuccess: (data) => { if (data.status === SUCCESS_STATUS) { onSuccess?.(data); } else { onError?.(data); } }, onError: (err) => { onError?.(err); }, }); return createRecurringBooking; };