Files
calendar/packages/platform/atoms/hooks/useAvailableSlots.ts
T
Lauris SkraucisandGitHub db52f44293 fix: atoms making requests to customers' domains (#20084)
* refactor: centralize useSchedule hook with isInit

* refactor: centralize useSchedules hook with isInit

* refactor: useConnectedCalendars enabled if isInit

* chore: some type fixes

* chore: type fix

* fix: import paths

* driveby: oauth clients docs
2025-03-17 10:43:39 +02:00

50 lines
1.3 KiB
TypeScript

import { useQuery } from "@tanstack/react-query";
import { SUCCESS_STATUS } from "@calcom/platform-constants";
import type { AvailableSlotsType } from "@calcom/platform-libraries";
import type {
GetAvailableSlotsInput_2024_04_15,
ApiResponse,
ApiSuccessResponse,
} from "@calcom/platform-types";
import http from "../lib/http";
export const QUERY_KEY = "get-available-slots";
export const useAvailableSlots = ({
enabled,
...rest
}: GetAvailableSlotsInput_2024_04_15 & { enabled: boolean; isTeamEvent?: boolean; teamId?: number }) => {
const availableSlots = useQuery({
queryKey: [
QUERY_KEY,
rest.startTime,
rest.endTime,
rest.eventTypeId,
rest.eventTypeSlug,
rest.isTeamEvent ?? false,
rest.teamId ?? false,
rest.usernameList,
rest.routedTeamMemberIds,
rest.skipContactOwner,
rest.shouldServeCache,
rest.teamMemberEmail,
],
queryFn: () => {
return http
.get<ApiResponse<AvailableSlotsType>>("/slots/available", {
params: rest,
})
.then((res) => {
if (res.data.status === SUCCESS_STATUS) {
return (res.data as ApiSuccessResponse<AvailableSlotsType>).data;
}
throw new Error(res.data.error.message);
});
},
enabled: enabled,
});
return availableSlots;
};