From 8b61d9bad7b7fa60b09cc112ce64dce70e09bf62 Mon Sep 17 00:00:00 2001 From: Anik Dhabal Babu Date: Wed, 1 May 2024 22:03:40 +0000 Subject: [PATCH 1/4] feat: availability after making changes --- .../atoms/availability/AvailabilitySettings.tsx | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/packages/platform/atoms/availability/AvailabilitySettings.tsx b/packages/platform/atoms/availability/AvailabilitySettings.tsx index 142a36257f2dc9..e3ba26a8fffb57 100644 --- a/packages/platform/atoms/availability/AvailabilitySettings.tsx +++ b/packages/platform/atoms/availability/AvailabilitySettings.tsx @@ -1,4 +1,4 @@ -import { useMemo, useState } from "react"; +import { useMemo, useState, useEffect } from "react"; import { Controller, useFieldArray, useForm, useWatch } from "react-hook-form"; import dayjs from "@calcom/dayjs"; @@ -237,6 +237,14 @@ export function AvailabilitySettings({ }, }); + useEffect(() => { + const subscription = form.watch((value) => handleSubmit(value as AvailabilityFormValues), { + ...schedule, + schedule: schedule.availability || [], + }); + return () => subscription.unsubscribe(); + }, [form.watch]); + const [Shell, Schedule, TimezoneSelect] = useMemo(() => { return isPlatform ? [PlatformShell, PlatformSchedule, PlatformTimzoneSelect] From f03641c06a053bcbeaceb216d384d741f0d6c95f Mon Sep 17 00:00:00 2001 From: Anik Dhabal Babu Date: Thu, 23 May 2024 22:04:38 +0000 Subject: [PATCH 2/4] update --- .../schedules/components/Schedule.tsx | 46 +++++++++++++++++-- .../availability/AvailabilitySettings.tsx | 14 ++++-- 2 files changed, 52 insertions(+), 8 deletions(-) diff --git a/packages/features/schedules/components/Schedule.tsx b/packages/features/schedules/components/Schedule.tsx index ffb304a3bac9bc..4eaaaeb2a3d1ec 100644 --- a/packages/features/schedules/components/Schedule.tsx +++ b/packages/features/schedules/components/Schedule.tsx @@ -12,6 +12,7 @@ import type { import { Controller, useFieldArray, useFormContext } from "react-hook-form"; import type { GroupBase, Props } from "react-select"; +import type { AvailabilityFormValues } from "@calcom/atoms/availability"; import type { ConfigType } from "@calcom/dayjs"; import dayjs from "@calcom/dayjs"; import { defaultDayRange as DEFAULT_DAY_RANGE } from "@calcom/lib/availability"; @@ -47,6 +48,7 @@ export const ScheduleDay = ({ name, weekday, control, + handleSubmit, CopyButton, disabled, labels, @@ -56,6 +58,7 @@ export const ScheduleDay = ({ name: ArrayPath; weekday: string; control: Control; + handleSubmit?: (data: AvailabilityFormValues) => Promise; CopyButton: JSX.Element; disabled?: boolean; labels?: ScheduleLabelsType; @@ -68,7 +71,7 @@ export const ScheduleDay = ({ scheduleContainer?: string; }; }) => { - const { watch, setValue } = useFormContext(); + const { watch, setValue, getValues } = useFormContext(); const watchDayRange = watch(name); return ( @@ -94,6 +97,7 @@ export const ScheduleDay = ({ data-testid={`${weekday}-switch`} onCheckedChange={(isChecked) => { setValue(name, (isChecked ? [DEFAULT_DAY_RANGE] : []) as TFieldValues[typeof name]); + handleSubmit && handleSubmit(getValues() as AvailabilityFormValues); }} /> @@ -110,6 +114,7 @@ export const ScheduleDay = ({ control={control} name={name} disabled={disabled} + handleSubmit={handleSubmit} className={{ dayRanges: className?.dayRanges, timeRangeField: className?.timeRangeField, @@ -129,10 +134,12 @@ const CopyButton = ({ getValuesFromDayRange, weekStart, labels, + handleSubmit, }: { getValuesFromDayRange: string; weekStart: number; labels?: ScheduleLabelsType; + handleSubmit?: (data: AvailabilityFormValues) => Promise; }) => { const { t } = useLocale(); const [open, setOpen] = useState(false); @@ -161,6 +168,7 @@ const CopyButton = ({ onClick={(selected) => { selected.forEach((day) => setValue(`${fieldArrayName}.${day}`, getValues(getValuesFromDayRange))); setOpen(false); + handleSubmit && handleSubmit(getValues() as AvailabilityFormValues); }} onCancel={() => setOpen(false)} /> @@ -177,6 +185,7 @@ const Schedule = < control: Control; weekStart?: number; disabled?: boolean; + handleSubmit?: (data: AvailabilityFormValues) => Promise; labels?: ScheduleLabelsType; userTimeFormat?: number | null; }) => { @@ -192,6 +201,7 @@ export const ScheduleComponent = < >({ name, control, + handleSubmit, disabled, weekStart = 0, labels, @@ -200,6 +210,7 @@ export const ScheduleComponent = < }: { name: TPath; control: Control; + handleSubmit?: (data: AvailabilityFormValues) => Promise; weekStart?: number; disabled?: boolean; labels?: ScheduleLabelsType; @@ -235,8 +246,14 @@ export const ScheduleComponent = < key={weekday} weekday={weekday} control={control} + handleSubmit={handleSubmit} CopyButton={ - + } /> ); @@ -252,6 +269,7 @@ export const DayRanges = ({ labels, userTimeFormat, className, + handleSubmit, }: { name: ArrayPath; control?: Control; @@ -262,6 +280,7 @@ export const DayRanges = ({ dayRanges?: string; timeRangeField?: string; }; + handleSubmit?: (data: AvailabilityFormValues) => Promise; }) => { const { t } = useLocale(); const { getValues } = useFormContext(); @@ -282,6 +301,7 @@ export const DayRanges = ({ )} @@ -305,16 +325,23 @@ export const DayRanges = ({ if (slotRange?.append) { append(slotRange.append); + handleSubmit && handleSubmit(getValues() as AvailabilityFormValues); } if (slotRange?.prepend) { prepend(slotRange.prepend); + handleSubmit && handleSubmit(getValues() as AvailabilityFormValues); } }} /> )} {index !== 0 && ( - + )} @@ -329,14 +356,17 @@ const RemoveTimeButton = ({ disabled, className, labels, + handleSubmit, }: { index: number | number[]; remove: UseFieldArrayRemove; className?: string; disabled?: boolean; labels?: ScheduleLabelsType; + handleSubmit?: (data: AvailabilityFormValues) => Promise; }) => { const { t } = useLocale(); + const { getValues } = useFormContext(); return (