From 11f0d48d0b3b70a2c22431f0eaccfdda5497616a Mon Sep 17 00:00:00 2001 From: Lauris Skraucis Date: Fri, 20 Sep 2024 13:42:10 +0200 Subject: [PATCH] feat: onBeforeUpdate AvailabilitySettings prop (#16737) --- .../AvailabilitySettingsPlatformWrapper.tsx | 20 +++++++++++++++++-- packages/platform/atoms/index.ts | 1 + packages/platform/atoms/monorepo.ts | 1 + 3 files changed, 20 insertions(+), 2 deletions(-) diff --git a/packages/platform/atoms/availability/wrappers/AvailabilitySettingsPlatformWrapper.tsx b/packages/platform/atoms/availability/wrappers/AvailabilitySettingsPlatformWrapper.tsx index ac01bfa691..fee22a5050 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; }; 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
Loading...
; diff --git a/packages/platform/atoms/index.ts b/packages/platform/atoms/index.ts index ceb98aa9e0..f0e670c70e 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 6b75d91aa3..8e3c936c3d 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";