Skip to content

Scheduling infrastructure for absolutely everyone.

feat: onBeforeUpdate AvailabilitySettings prop (#16737)

Lauris Skraucis11f0d48d0b3b
diff --git a/packages/platform/atoms/availability/wrappers/AvailabilitySettingsPlatformWrapper.tsx b/packages/platform/atoms/availability/wrappers/AvailabilitySettingsPlatformWrapper.tsx
index ac01bfa691c..fee22a5050e 100644
--- a/packages/platform/atoms/availability/wrappers/AvailabilitySettingsPlatformWrapper.tsx
+++ b/packages/platform/atoms/availability/wrappers/AvailabilitySettingsPlatformWrapper.tsx
@@ -1,5 +1,10 @@
import type { ScheduleLabelsType } from "@calcom/features/schedules/components/Schedule";
-import type { ApiErrorResponse, ApiResponse, ScheduleOutput_2024_06_11 } from "@calcom/platform-types";
+import type {
+ ApiErrorResponse,
+ ApiResponse,
+ ScheduleOutput_2024_06_11,
+ UpdateScheduleInput_2024_06_11,
+} from "@calcom/platform-types";
import useDeleteSchedule from "../../hooks/schedules/useDeleteSchedule";
import { useSchedule } from "../../hooks/schedules/useSchedule";
@@ -27,6 +32,7 @@ type AvailabilitySettingsPlatformWrapperProps = {
onDeleteError?: (err: ApiErrorResponse) => void;
disableEditableHeading?: boolean;
enableOverrides?: boolean;
+ onBeforeUpdate?: (updateBody: UpdateScheduleInput_2024_06_11) => boolean | Promise<boolean>;
};
export const AvailabilitySettingsPlatformWrapper = ({
@@ -38,6 +44,7 @@ export const AvailabilitySettingsPlatformWrapper = ({
onUpdateSuccess,
disableEditableHeading = false,
enableOverrides = false,
+ onBeforeUpdate,
}: AvailabilitySettingsPlatformWrapperProps) => {
const { isLoading, data: schedule } = useSchedule(id);
const { data: schedules } = useSchedules();
@@ -82,7 +89,16 @@ export const AvailabilitySettingsPlatformWrapper = ({
const handleUpdate = async (id: number, body: AvailabilityFormValues) => {
const updateBody = transformAtomScheduleForApi(body);
- updateSchedule({ id, ...updateBody });
+
+ let canUpdate = true;
+
+ if (onBeforeUpdate) {
+ canUpdate = await onBeforeUpdate(updateBody);
+ }
+
+ if (canUpdate) {
+ updateSchedule({ id, ...updateBody });
+ }
};
if (isLoading) return <div className="px-10 py-4 text-xl">Loading...</div>;
diff --git a/packages/platform/atoms/index.ts b/packages/platform/atoms/index.ts
index ceb98aa9e02..f0e670c70ee 100644
--- a/packages/platform/atoms/index.ts
+++ b/packages/platform/atoms/index.ts
@@ -23,3 +23,4 @@ export { useTeams } from "./hooks/teams/useTeams";
export { SelectedCalendarsSettingsPlatformWrapper as SelectedCalendarsSettings } from "./selected-calendars/index";
export { DestinationCalendarSettingsPlatformWrapper as DestinationCalendarSettings } from "./destination-calendar/index";
export { CalendarSettingsPlatformWrapper as CalendarSettings } from "./calendar-settings/index";
+export type { UpdateScheduleInput_2024_06_11 as UpdateScheduleBody } from "@calcom/platform-types";
diff --git a/packages/platform/atoms/monorepo.ts b/packages/platform/atoms/monorepo.ts
index 6b75d91aa32..8e3c936c3df 100644
--- a/packages/platform/atoms/monorepo.ts
+++ b/packages/platform/atoms/monorepo.ts
@@ -10,3 +10,4 @@ export { SelectedCalendarsSettingsWebWrapper } from "./selected-calendars/wrappe
export { DestinationCalendarSettingsWebWrapper } from "./destination-calendar/wrappers/DestinationCalendarSettingsWebWrapper";
export * from "./availability";
export { EventTypeWebWrapper as EventType } from "./event-types/wrappers/EventTypeWebWrapper";
+export type { UpdateScheduleInput_2024_06_11 as UpdateScheduleBody } from "@calcom/platform-types";