feat: OnformChange on Availability Settings Atom (#21560)
* feat: OnformChange on Availability Settings Atom * docs: update availability-settings * Update docs/platform/atoms/availability-settings.mdx Co-authored-by: cubic-dev-ai[bot] <191113872+cubic-dev-ai[bot]@users.noreply.github.com> --------- Co-authored-by: cubic-dev-ai[bot] <191113872+cubic-dev-ai[bot]@users.noreply.github.com>
This commit is contained in:
1 parent
c9eac73fec
commit
8d5c6b8877
3 files changed
+26
-1
No files matched your search
@@ -1,7 +1,7 @@
|
||||
"use client";
|
||||
|
||||
import type { SetStateAction, Dispatch } from "react";
|
||||
import { useMemo, useState } from "react";
|
||||
import React, { useMemo, useState, useEffect } from "react";
|
||||
import { Controller, useFieldArray, useForm, useFormContext, useWatch } from "react-hook-form";
|
||||
|
||||
import dayjs from "@calcom/dayjs";
|
||||
@@ -103,6 +103,7 @@ type AvailabilitySettingsProps = {
|
||||
customClassNames?: CustomClassNames;
|
||||
disableEditableHeading?: boolean;
|
||||
enableOverrides?: boolean;
|
||||
onFormStateChange?: (formState: AvailabilityFormValues) => void;
|
||||
bulkUpdateModalProps?: {
|
||||
isOpen: boolean;
|
||||
setIsOpen: Dispatch<SetStateAction<boolean>>;
|
||||
@@ -275,6 +276,7 @@ export function AvailabilitySettings({
|
||||
customClassNames,
|
||||
disableEditableHeading = false,
|
||||
enableOverrides = false,
|
||||
onFormStateChange,
|
||||
bulkUpdateModalProps,
|
||||
allowSetToDefault = true,
|
||||
allowDelete = true,
|
||||
@@ -289,6 +291,17 @@ export function AvailabilitySettings({
|
||||
},
|
||||
});
|
||||
|
||||
const watchedValues = useWatch({
|
||||
control: form.control,
|
||||
});
|
||||
|
||||
// Trigger callback whenever the form state changes
|
||||
useEffect(() => {
|
||||
if (onFormStateChange && watchedValues) {
|
||||
onFormStateChange(watchedValues as AvailabilityFormValues);
|
||||
}
|
||||
}, [watchedValues, onFormStateChange]);
|
||||
|
||||
const [Shell, Schedule, TimezoneSelect] = useMemo(() => {
|
||||
return isPlatform
|
||||
? [PlatformShell, PlatformSchedule, PlatformTimzoneSelect]
|
||||
|
||||
@@ -35,6 +35,7 @@ type AvailabilitySettingsPlatformWrapperProps = {
|
||||
disableEditableHeading?: boolean;
|
||||
enableOverrides?: boolean;
|
||||
onBeforeUpdate?: (updateBody: UpdateScheduleInput_2024_06_11) => boolean | Promise<boolean>;
|
||||
onFormStateChange?: (formState: AvailabilityFormValues) => void;
|
||||
allowDelete?: boolean;
|
||||
allowSetToDefault?: boolean;
|
||||
disableToasts?: boolean;
|
||||
@@ -52,6 +53,7 @@ export const AvailabilitySettingsPlatformWrapper = ({
|
||||
disableEditableHeading = false,
|
||||
enableOverrides = false,
|
||||
onBeforeUpdate,
|
||||
onFormStateChange,
|
||||
allowDelete,
|
||||
allowSetToDefault,
|
||||
disableToasts,
|
||||
@@ -186,6 +188,7 @@ export const AvailabilitySettingsPlatformWrapper = ({
|
||||
customClassNames={customClassNames}
|
||||
allowDelete={allowDelete}
|
||||
allowSetToDefault={allowSetToDefault}
|
||||
onFormStateChange={onFormStateChange}
|
||||
/>
|
||||
</AtomsWrapper>
|
||||
);
|
||||
|
||||
Reference in new issue
Block a user