From 935115d7c12de0d40500cb88e3208f1166fea19d Mon Sep 17 00:00:00 2001 From: Somay Chauhan Date: Mon, 25 Nov 2024 12:43:58 +0530 Subject: [PATCH] feat: added custom classnames for event-limits tab (#17478) * added custom classnames for event limits tab * added classNames to common types * updated classnames to use the common exported types * undo * Update EventTypePlatformWrapper.tsx * better clasnames naming * added example classnames for demo * fix: better calssnames bookingFrequencyLimitSection-> bookingFrequencyLimit totalDurationLimitSection-> totalDurationLimit futureBookingLimitSection-> futureBookingLimit offsetStartTimesSection-> offsetStartTimes * suffix->addOn * Update types.ts --- .../components/tabs/limits/EventLimitsTab.tsx | 239 +++++++++++++++--- .../wrappers/EventTypePlatformWrapper.tsx | 11 +- .../examples/base/src/pages/event-types.tsx | 144 +++++++++++ 3 files changed, 351 insertions(+), 43 deletions(-) diff --git a/packages/features/eventtypes/components/tabs/limits/EventLimitsTab.tsx b/packages/features/eventtypes/components/tabs/limits/EventLimitsTab.tsx index ff375da02c..e80a4eabb2 100644 --- a/packages/features/eventtypes/components/tabs/limits/EventLimitsTab.tsx +++ b/packages/features/eventtypes/components/tabs/limits/EventLimitsTab.tsx @@ -8,7 +8,8 @@ import type { SingleValue } from "react-select"; import useLockedFieldsManager from "@calcom/features/ee/managed-event-types/hooks/useLockedFieldsManager"; import { getDefinedBufferTimes } from "@calcom/features/eventtypes/lib/getDefinedBufferTimes"; -import type { FormValues, EventTypeSetupProps } from "@calcom/features/eventtypes/lib/types"; +import type { FormValues, EventTypeSetupProps, InputClassNames } from "@calcom/features/eventtypes/lib/types"; +import type { SelectClassNames, SettingsToggleClassNames } from "@calcom/features/eventtypes/lib/types"; import CheckboxField from "@calcom/features/form/components/CheckboxField"; import { classNames } from "@calcom/lib"; import { ROLLING_WINDOW_PERIOD_MAX_DAYS_TO_CHECK } from "@calcom/lib/constants"; @@ -23,7 +24,35 @@ import { Button, DateRangePicker, InputField, Label, Select, SettingsToggle, Tex type IPeriodType = (typeof PeriodType)[keyof typeof PeriodType]; -export type EventLimitsTabProps = Pick; +export type EventLimitsTabCustomClassNames = { + bufferAndNoticeSection?: { + container?: string; + beforeBufferSelect?: SelectClassNames; + afterBufferSelect?: SelectClassNames; + minimumNoticeInput?: SelectClassNames & { input?: string }; + timeSlotIntervalSelect?: SelectClassNames; + }; + + bookingFrequencyLimit: SettingsToggleClassNames & { + intervalLimitItem?: IntervalLimitItemCustomClassNames; + intervalLimitContainer?: string; + }; + firstAvailableSlotOnly?: SettingsToggleClassNames; + totalDurationLimit?: SettingsToggleClassNames & { + intervalLimitItem?: IntervalLimitItemCustomClassNames; + }; + futureBookingLimit?: SettingsToggleClassNames & { + rollingLimit: RollingLimitCustomClassNames; + rangeLimit: RangeLimitCustomClassNames; + }; + offsetStartTimes?: SettingsToggleClassNames & { + offsetInput?: InputClassNames; + }; +}; + +export type EventLimitsTabProps = Pick & { + customClassNames?: EventLimitsTabCustomClassNames; +}; /** * We technically have a ROLLING_WINDOW future limit option that isn't shown as a Radio Option. Because UX is better by providing it as a toggle with ROLLING Limit radio option. @@ -65,18 +94,30 @@ const getPeriodTypeFromUiValue = (uiValue: { value: PeriodType; rollingExcludeUn return uiValue.value; }; +type RangeLimitCustomClassNames = { + wrapper?: string; + datePickerWraper?: string; + datePicker?: string; +}; + function RangeLimitRadioItem({ isDisabled, formMethods, radioValue, + customClassNames, }: { radioValue: string; isDisabled: boolean; formMethods: UseFormReturn; + customClassNames?: RangeLimitCustomClassNames; }) { const { t } = useLocale(); return ( -
+
{!isDisabled && ( {t("within_date_range")}  -
+
( @@ -103,6 +148,7 @@ function RangeLimitRadioItem({ endDate, }); }} + className={customClassNames?.datePicker} /> )} /> @@ -112,18 +158,26 @@ function RangeLimitRadioItem({ ); } +type RollingLimitCustomClassNames = { + container?: string; + textField?: string; + periodTypeSelect?: Pick; +}; + function RollingLimitRadioItem({ radioValue, isDisabled, formMethods, onChange, rollingExcludeUnavailableDays, + customClassNames, }: { radioValue: IPeriodType; isDisabled: boolean; formMethods: UseFormReturn; onChange: (opt: { value: number } | null) => void; rollingExcludeUnavailableDays: boolean; + customClassNames?: RollingLimitCustomClassNames; }) { const { t } = useLocale(); @@ -136,7 +190,11 @@ function RollingLimitRadioItem({ const periodDaysWatch = formMethods.watch("periodDays"); return ( -
+
{!isDisabled && (  {t("into_the_future")}
@@ -200,8 +263,10 @@ function RollingLimitRadioItem({ const MinimumBookingNoticeInput = React.forwardRef< HTMLInputElement, - Omit, "ref"> ->(function MinimumBookingNoticeInput({ ...passThroughProps }, ref) { + Omit, "ref"> & { + customClassNames?: SelectClassNames & { input?: string }; + } +>(function MinimumBookingNoticeInput({ customClassNames, ...passThroughProps }, ref) { const { t } = useLocale(); const { setValue, getValues } = useFormContext(); const durationTypeOptions: { @@ -262,15 +327,19 @@ const MinimumBookingNoticeInput = React.forwardRef< label={t("minimum_booking_notice")} type="number" placeholder="0" + className={classNames("mb-0 h-9 rounded-[4px] ltr:mr-2 rtl:ml-2", customClassNames?.input)} min={0} - className="mb-0 h-9 rounded-[4px] ltr:mr-2 rtl:ml-2" />