Files
calendar/packages/platform/atoms/hooks/bookings/useBooking.ts
T
Lauris SkraucisandGitHub a10d3599e2 refactor: platform bookings hooks & bookings API (#16963)
* chore: delete unused bookings hook

* refactor: group bookings hooks in folder

* refactor: rename useGetBooking, useGetBookings to useBooking, useBookings

* refactor: booking inputs and outputs

* chore: make bookings controller work with new inputs and outputs

* make examples app work

* refactor: deprecate fields instead of removing them

* readd eventtypeid

* swagger regenerate

* make recurring booking backwards compatible

* fix test

* update changelog

* swagger update

* fix import

* chore: update lock file
2024-10-08 14:05:28 +02:00

34 lines
867 B
TypeScript

import { useQuery } from "@tanstack/react-query";
import {
V2_ENDPOINTS,
SUCCESS_STATUS,
CAL_API_VERSION_HEADER,
VERSION_2024_08_13,
} from "@calcom/platform-constants";
import type { GetBookingOutput_2024_08_13 } from "@calcom/platform-types";
import http from "../../lib/http";
export const useBooking = (uid: string) => {
const pathname = `/${V2_ENDPOINTS.bookings}/${uid}`;
const headers = {
[CAL_API_VERSION_HEADER]: VERSION_2024_08_13,
};
const bookingQuery = useQuery({
queryKey: ["use-booking", uid],
queryFn: async () => {
return http.get<GetBookingOutput_2024_08_13>(pathname, { headers }).then((res) => {
if (res.data.status === SUCCESS_STATUS) {
return res.data.data;
}
throw new Error(res.data?.error?.message);
});
},
enabled: !!uid,
});
return bookingQuery;
};