mirror of
https://github.com/hanzoai/calendar.git
synced 2026-10-30 14:46:43 +00:00
* docs: request auth headers * feat: useOrganizationsBookings hook * feat: useOrganizationUserBookings hook * rename hooks * query params * fix: organizations users bookings extract user from userId not auth * fix: passing array from hook * docs * correct header doc --------- Co-authored-by: Anik Dhabal Babu <[email protected]>
39 lines
1.3 KiB
TypeScript
39 lines
1.3 KiB
TypeScript
import { useQuery } from "@tanstack/react-query";
|
|
|
|
import { SUCCESS_STATUS } from "@calcom/platform-constants";
|
|
import type { GetBookingsOutput_2024_08_13, GetOrganizationsBookingsInput } from "@calcom/platform-types";
|
|
|
|
import http from "../../../lib/http";
|
|
import { extractBookingsQueryKeys } from "../../bookings/useBookings";
|
|
import { useAtomsContext } from "../../useAtomsContext";
|
|
|
|
export const QUERY_KEY = "use-organization-bookings";
|
|
|
|
export const useOrganizationBookings = (query: GetOrganizationsBookingsInput) => {
|
|
const { organizationId } = useAtomsContext();
|
|
|
|
const pathname = `/organizations/${organizationId}/bookings`;
|
|
|
|
const organizationBookingsQuery = useQuery({
|
|
queryKey: [QUERY_KEY, ...extractOrganizationBookingsQueryKeys(query)],
|
|
queryFn: async () => {
|
|
return http
|
|
.get<GetBookingsOutput_2024_08_13>(pathname, {
|
|
params: query,
|
|
})
|
|
.then((res) => {
|
|
if (res.data.status === SUCCESS_STATUS) {
|
|
return res.data.data;
|
|
}
|
|
throw new Error(res.data?.error?.message);
|
|
});
|
|
},
|
|
});
|
|
|
|
return organizationBookingsQuery;
|
|
};
|
|
|
|
function extractOrganizationBookingsQueryKeys(query: GetOrganizationsBookingsInput) {
|
|
return [...extractBookingsQueryKeys(query), query.userIds];
|
|
}
|