Files
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

40 lines
1.1 KiB
TypeScript

import { useQuery } from "@tanstack/react-query";
import {
V2_ENDPOINTS,
SUCCESS_STATUS,
VERSION_2024_06_11,
CAL_API_VERSION_HEADER,
} from "@calcom/platform-constants";
import type { GetScheduleOutput_2024_06_11 } from "@calcom/platform-types";
import http from "../../lib/http";
import { useAtomsContext } from "../useAtomsContext";
export const QUERY_KEY = "user-schedule";
export const useSchedule = (id?: number | string) => {
const { isInit } = useAtomsContext();
const pathname = id ? `/${V2_ENDPOINTS.availability}/${id}` : `/${V2_ENDPOINTS.availability}/default`;
const { isLoading, error, data } = useQuery({
queryKey: [QUERY_KEY, `${id}`],
queryFn: () => {
return http
.get<GetScheduleOutput_2024_06_11>(pathname, {
headers: { [CAL_API_VERSION_HEADER]: VERSION_2024_06_11 },
})
.then((res) => {
if (res.data.status === SUCCESS_STATUS) {
return res.data.data;
}
throw new Error(res.data.error?.message);
});
},
enabled: isInit,
});
return { isLoading, error, data };
};