Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/deep-owls-hang.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@calcom/atoms": minor
---

fix: EventTypeSettings Atom crashes on enabling `Lock timezone on booking` in advanced tab
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { useState, Suspense } from "react";
import { useState, Suspense, useMemo } from "react";
import type { Dispatch, SetStateAction } from "react";
import { Controller, useFormContext } from "react-hook-form";
import type { z } from "zod";
Expand All @@ -10,9 +10,10 @@ import {
SelectedCalendarSettingsScope,
SelectedCalendarsSettingsWebWrapperSkeleton,
} from "@calcom/atoms/selected-calendars/wrappers/SelectedCalendarsSettingsWebWrapper";
import { Timezone as PlatformTimzoneSelect } from "@calcom/atoms/timezone";
import getLocationsOptionsForSelect from "@calcom/features/bookings/lib/getLocationOptionsForSelect";
import DestinationCalendarSelector from "@calcom/features/calendars/DestinationCalendarSelector";
import { TimezoneSelect } from "@calcom/features/components/timezone-select";
import { TimezoneSelect as WebTimezoneSelect } from "@calcom/features/components/timezone-select";
import useLockedFieldsManager from "@calcom/features/ee/managed-event-types/hooks/useLockedFieldsManager";
import {
allowDisablingAttendeeConfirmationEmails,
Expand Down Expand Up @@ -565,6 +566,10 @@ export const EventAdvancedTab = ({
userEmail = removePlatformClientIdFromEmail(userEmail, platformContext.clientId);
}

const TimezoneSelect = useMemo(() => {
return isPlatform ? PlatformTimzoneSelect : WebTimezoneSelect;
}, [isPlatform]);

return (
<div className="flex flex-col space-y-4">
<calendarComponents.CalendarSettings
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ const EventType = forwardRef<
const description = message ? t(message) : t(err.message);
toast({ description });
onError?.(currentValues, err);

const errorObj = new Error(description);
callbacksRef.current?.onError?.(errorObj);
},
Expand All @@ -175,24 +175,27 @@ const EventType = forwardRef<

const callbacksRef = useRef<{ onSuccess?: () => void; onError?: (error: Error) => void }>({});

const handleFormSubmit = useCallback((customCallbacks?: { onSuccess?: () => void; onError?: (error: Error) => void }) => {
if (customCallbacks) {
callbacksRef.current = customCallbacks;
}
const handleFormSubmit = useCallback(
(customCallbacks?: { onSuccess?: () => void; onError?: (error: Error) => void }) => {
if (customCallbacks) {
callbacksRef.current = customCallbacks;
}

if (saveButtonRef.current) {
saveButtonRef.current.click();
} else {
form.handleSubmit((data) => {
try {
handleSubmit(data);
customCallbacks?.onSuccess?.();
} catch (error) {
customCallbacks?.onError?.(error as Error);
}
})();
}
}, [handleSubmit, form]);
if (saveButtonRef.current) {
saveButtonRef.current.click();
} else {
form.handleSubmit((data) => {
try {
handleSubmit(data);
customCallbacks?.onSuccess?.();
} catch (error) {
customCallbacks?.onError?.(error as Error);
}
})();
}
},
[handleSubmit, form]
);
Comment on lines +178 to +198
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue

Avoid duplicate/early success callbacks in handleFormSubmit.

customCallbacks?.onSuccess?.() is invoked immediately after handleSubmit(data), which likely fires an async mutation. This will:

  • Call onSuccess too early (before the mutation settles).
  • Potentially call onSuccess twice (here and again in updateMutation.onSuccess via callbacksRef).

Rely on mutation callbacks (already wired via callbacksRef) and remove the immediate invocations in this handler.

Apply this diff:

-  const handleFormSubmit = useCallback(
-    (customCallbacks?: { onSuccess?: () => void; onError?: (error: Error) => void }) => {
-      if (customCallbacks) {
-        callbacksRef.current = customCallbacks;
-      }
-
-      if (saveButtonRef.current) {
-        saveButtonRef.current.click();
-      } else {
-        form.handleSubmit((data) => {
-          try {
-            handleSubmit(data);
-            customCallbacks?.onSuccess?.();
-          } catch (error) {
-            customCallbacks?.onError?.(error as Error);
-          }
-        })();
-      }
-    },
-    [handleSubmit, form]
-  );
+  const handleFormSubmit = useCallback(
+    (customCallbacks?: { onSuccess?: () => void; onError?: (error: Error) => void }) => {
+      if (customCallbacks) {
+        callbacksRef.current = customCallbacks;
+      }
+      if (saveButtonRef.current) {
+        // Triggers the underlying submit which will call mutation and invoke callbacksRef on settle
+        saveButtonRef.current.click();
+        return;
+      }
+      // Fallback: submit programmatically; rely on mutation onSuccess/onError to invoke callbacksRef
+      form.handleSubmit((data) => {
+        handleSubmit(data);
+      })();
+    },
+    [handleSubmit, form]
+  );
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
const handleFormSubmit = useCallback(
(customCallbacks?: { onSuccess?: () => void; onError?: (error: Error) => void }) => {
if (customCallbacks) {
callbacksRef.current = customCallbacks;
}
if (saveButtonRef.current) {
saveButtonRef.current.click();
} else {
form.handleSubmit((data) => {
try {
handleSubmit(data);
customCallbacks?.onSuccess?.();
} catch (error) {
customCallbacks?.onError?.(error as Error);
}
})();
}
}, [handleSubmit, form]);
if (saveButtonRef.current) {
saveButtonRef.current.click();
} else {
form.handleSubmit((data) => {
try {
handleSubmit(data);
customCallbacks?.onSuccess?.();
} catch (error) {
customCallbacks?.onError?.(error as Error);
}
})();
}
},
[handleSubmit, form]
);
const handleFormSubmit = useCallback(
(customCallbacks?: { onSuccess?: () => void; onError?: (error: Error) => void }) => {
if (customCallbacks) {
callbacksRef.current = customCallbacks;
}
if (saveButtonRef.current) {
// Triggers the underlying submit which will call mutation and invoke callbacksRef on settle
saveButtonRef.current.click();
return;
}
// Fallback: submit programmatically; rely on mutation onSuccess/onError to invoke callbacksRef
form.handleSubmit((data) => {
handleSubmit(data);
})();
},
[handleSubmit, form]
);
🤖 Prompt for AI Agents
In packages/platform/atoms/event-types/wrappers/EventTypePlatformWrapper.tsx
around lines 178-198, remove the immediate invocations of
customCallbacks?.onSuccess and customCallbacks?.onError inside the
form.handleSubmit branch so callbacks are only invoked via the mutation
callbacks wired through callbacksRef; keep the assignment callbacksRef.current =
customCallbacks when provided and still call saveButtonRef.current.click() when
present, but inside the form.handleSubmit try/catch do not call customCallbacks
directly — let updateMutation.onSuccess/onError (via callbacksRef) handle
success/error notifications.


const validateForm = useCallback(async () => {
const isValid = await form.trigger();
Expand Down
Loading