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
This commit is contained in:
Lauris Skraucis authored and GitHub committed 2025-03-17 10:43:39 +02:00
1 parent 20d6eb5200
commit db52f44293
12 files changed
+57 -132

No files matched your search

@@ -501,7 +501,7 @@ export const BookerPlatformWrapper = (
}
}
rescheduleUid={props.rescheduleUid ?? null}
rescheduledBy={props.rescheduledBy}
rescheduledBy={props.rescheduledBy ?? null}
bookingUid={props.bookingUid ?? null}
isRedirect={false}
fromUserNameRedirected=""
@@ -32,7 +32,7 @@ import {
EventTypeMetaDataSchema,
} from "@calcom/prisma/zod-utils";
import type { BookerPlatformWrapperAtomProps } from "../../booker/BookerPlatformWrapper";
import type { BookerPlatformWrapperAtomProps } from "../../booker/types";
export function transformApiEventTypeForAtom(
eventType: Omit<EventTypeOutput_2024_06_14, "ownerId"> & { bannerUrl?: string },
@@ -1,36 +0,0 @@
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";
export const QUERY_KEY = "event-type-user-schedule";
export const useSchedule = (id?: number) => {
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: !!id,
});
return { isLoading, error, data };
};
@@ -1,35 +0,0 @@
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 { GetSchedulesOutput_2024_06_11 } from "@calcom/platform-types";
import http from "../../lib/http";
export const QUERY_KEY = "event-type-user-schedules";
export const useSchedules = () => {
const pathname = `/${V2_ENDPOINTS.availability}`;
const { isLoading, error, data } = useQuery({
queryKey: [QUERY_KEY],
queryFn: () => {
return http
.get<GetSchedulesOutput_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);
});
},
});
return { isLoading, error, data };
};
@@ -7,10 +7,10 @@ import type { User } from "@calcom/prisma/client";
import type { Availability } from "../../availability/AvailabilitySettings";
import { transformApiScheduleForAtom } from "../../availability/atom-api-transformers/transformApiScheduleForAtom";
import { useSchedule } from "../../hooks/schedules/useSchedule";
import { useSchedules } from "../../hooks/schedules/useSchedules";
import { useTeamMembers } from "../../hooks/teams/useTeamMembers";
import { useAtomHostSchedules } from "../hooks/useAtomHostSchedules";
import { useSchedule } from "../hooks/useSchedule";
import { useSchedules } from "../hooks/useSchedules";
type EventAvailabilityTabPlatformWrapperProps = {
user?: Pick<User, "id" | "defaultScheduleId" | "timeZone" | "timeFormat" | "weekStart">;
@@ -1,25 +1,38 @@
import { useQuery } from "@tanstack/react-query";
import { V2_ENDPOINTS, SUCCESS_STATUS } from "@calcom/platform-constants";
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?: string) => {
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],
queryKey: [QUERY_KEY, `${id}`],
queryFn: () => {
return http.get<GetScheduleOutput_2024_06_11>(pathname).then((res) => {
if (res.data.status === SUCCESS_STATUS) {
return res.data.data;
}
throw new Error(res.data.error?.message);
});
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 };
@@ -1,25 +1,38 @@
import { useQuery } from "@tanstack/react-query";
import { V2_ENDPOINTS, SUCCESS_STATUS } from "@calcom/platform-constants";
import {
V2_ENDPOINTS,
SUCCESS_STATUS,
VERSION_2024_06_11,
CAL_API_VERSION_HEADER,
} from "@calcom/platform-constants";
import type { GetSchedulesOutput_2024_06_11 } from "@calcom/platform-types";
import http from "../../lib/http";
import { useAtomsContext } from "../useAtomsContext";
export const QUERY_KEY = "user-schedules";
export const useSchedules = () => {
const { isInit } = useAtomsContext();
const pathname = `/${V2_ENDPOINTS.availability}`;
const { isLoading, error, data } = useQuery({
queryKey: [QUERY_KEY],
queryFn: () => {
return http.get<GetSchedulesOutput_2024_06_11>(pathname).then((res) => {
if (res.data.status === SUCCESS_STATUS) {
return res.data.data;
}
throw new Error(res.data.error?.message);
});
return http
.get<GetSchedulesOutput_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 };
@@ -2,7 +2,11 @@ import { useQuery } from "@tanstack/react-query";
import { SUCCESS_STATUS } from "@calcom/platform-constants";
import type { AvailableSlotsType } from "@calcom/platform-libraries";
import type { GetAvailableSlotsInput, ApiResponse, ApiSuccessResponse } from "@calcom/platform-types";
import type {
GetAvailableSlotsInput_2024_04_15,
ApiResponse,
ApiSuccessResponse,
} from "@calcom/platform-types";
import http from "../lib/http";
@@ -11,7 +15,7 @@ export const QUERY_KEY = "get-available-slots";
export const useAvailableSlots = ({
enabled,
...rest
}: GetAvailableSlotsInput & { enabled: boolean; isTeamEvent?: boolean; teamId?: number }) => {
}: GetAvailableSlotsInput_2024_04_15 & { enabled: boolean; isTeamEvent?: boolean; teamId?: number }) => {
const availableSlots = useQuery({
queryKey: [
QUERY_KEY,
@@ -5,9 +5,12 @@ import type { ConnectedDestinationCalendars } from "@calcom/platform-libraries";
import type { ApiResponse, ApiSuccessResponse } from "@calcom/platform-types";
import http from "../lib/http";
import { useAtomsContext } from "./useAtomsContext";
export const QUERY_KEY = "get-connected-calendars";
export const useConnectedCalendars = (props: { enabled?: boolean }) => {
const { isInit } = useAtomsContext();
const calendars = useQuery({
queryKey: [QUERY_KEY],
queryFn: () => {
@@ -18,7 +21,7 @@ export const useConnectedCalendars = (props: { enabled?: boolean }) => {
throw new Error(res.data.error.message);
});
},
enabled: props?.enabled ?? true,
enabled: props?.enabled !== undefined ? props.enabled && isInit : isInit,
});
return calendars;