feat: onBeforeUpdate AvailabilitySettings prop (#16737)

This commit is contained in:
Lauris Skraucis authored and GitHub committed 2024-09-20 11:42:10 +00:00
1 parent c4a1382982
commit 11f0d48d0b
3 files changed
+20 -2

No files matched your search

@@ -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>;
+1
View File
@@ -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";
+1
View File
@@ -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";