Files
calendar/packages/platform/atoms/hooks/useCreateRecurringBooking.ts
T
MorganandGitHub 38e62786e4 chore: remove /ee from apiv2 urls (#14568)
* chore: remove /ee from apiv2 urls

* fixup! chore: remove /ee from apiv2 urls

* chore: remove /ee from apiv2 urls

* fixup! chore: remove /ee from apiv2 urls

* fixup! fixup! chore: remove /ee from apiv2 urls

* fixup! fixup! fixup! chore: remove /ee from apiv2 urls
2024-04-13 22:16:37 +00:00

45 lines
1.2 KiB
TypeScript

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<BookingResponse[]>) => void;
onError?: (err: ApiErrorResponse | Error) => void;
}
export const useCreateRecurringBooking = (
{ onSuccess, onError }: IUseCreateRecurringBooking = {
onSuccess: () => {
return;
},
onError: () => {
return;
},
}
) => {
const createRecurringBooking = useMutation<
ApiResponse<BookingResponse[]>,
Error,
RecurringBookingCreateBody[]
>({
mutationFn: (data) => {
return http.post<ApiResponse<BookingResponse[]>>("/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;
};