Skip to content

Commit 618ef63

Browse files
authored
fix: Availability atom handleFormSubmit callbacks not triggering (calcom#23174)
* fix: form submit callbacks trigger * added changelog * fix: type-error
1 parent ae8e633 commit 618ef63

3 files changed

Lines changed: 13 additions & 7 deletions

File tree

.changeset/rich-impalas-hug.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@calcom/atoms": minor
3+
---
4+
5+
fix: Availability atom handleFormSubmit callbacks not triggering

packages/platform/atoms/availability/AvailabilitySettings.tsx

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,7 @@ type AvailabilitySettingsProps = {
124124
isEventTypesFetching?: boolean;
125125
handleBulkEditDialogToggle: () => void;
126126
};
127+
callbacksRef?: React.MutableRefObject<{ onSuccess?: () => void; onError?: (error: Error) => void }>;
127128
};
128129

129130
const DeleteDialogButton = ({
@@ -306,6 +307,7 @@ export const AvailabilitySettings = forwardRef<AvailabilitySettingsFormRef, Avai
306307
bulkUpdateModalProps,
307308
allowSetToDefault = true,
308309
allowDelete = true,
310+
callbacksRef,
309311
} = props;
310312
const [openSidebar, setOpenSidebar] = useState(false);
311313
const { t, i18n } = useLocale();
@@ -336,11 +338,9 @@ export const AvailabilitySettings = forwardRef<AvailabilitySettingsFormRef, Avai
336338

337339
const saveButtonRef = useRef<HTMLButtonElement>(null);
338340

339-
const callbacksRef = useRef<{ onSuccess?: () => void; onError?: (error: Error) => void }>({});
340-
341341
const handleFormSubmit = useCallback(
342342
(customCallbacks?: { onSuccess?: () => void; onError?: (error: Error) => void }) => {
343-
if (customCallbacks) {
343+
if (callbacksRef && customCallbacks) {
344344
callbacksRef.current = customCallbacks;
345345
}
346346

@@ -350,14 +350,14 @@ export const AvailabilitySettings = forwardRef<AvailabilitySettingsFormRef, Avai
350350
form.handleSubmit(async (data) => {
351351
try {
352352
await handleSubmit(data);
353-
callbacksRef.current?.onSuccess?.();
353+
callbacksRef?.current?.onSuccess?.();
354354
} catch (error) {
355-
callbacksRef.current?.onError?.(error as Error);
355+
callbacksRef?.current?.onError?.(error as Error);
356356
}
357357
})();
358358
}
359359
},
360-
[form, handleSubmit]
360+
[form, handleSubmit, callbacksRef]
361361
);
362362

363363
const validateForm = useCallback(async () => {

packages/platform/atoms/availability/wrappers/AvailabilitySettingsPlatformWrapper.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ export type AvailabilitySettingsPlatformWrapperProps = {
3939
};
4040

4141
export const AvailabilitySettingsPlatformWrapper = forwardRef<
42-
AvailabilitySettingsFormRef,
42+
AvailabilitySettingsFormRef,
4343
AvailabilitySettingsPlatformWrapperProps
4444
>(function AvailabilitySettingsPlatformWrapper(props, ref) {
4545
const {
@@ -202,6 +202,7 @@ AvailabilitySettingsFormRef,
202202
allowDelete={allowDelete}
203203
allowSetToDefault={allowSetToDefault}
204204
onFormStateChange={onFormStateChange}
205+
callbacksRef={callbacksRef}
205206
/>
206207
</AtomsWrapper>
207208
);

0 commit comments

Comments
 (0)