From 64b321ac9c14042a99e5a406ec8c731378eb1b04 Mon Sep 17 00:00:00 2001 From: Somay Chauhan Date: Wed, 16 Oct 2024 17:34:33 +0530 Subject: [PATCH] feat: added custom class name to booker and availability atom (#17105) * added custom class name for booker atoms wrapper * atomsWrapper * added props to availability atom * allowDelete * allowSetToDefault * added customClassNames -> hiddenSwitchClassname, deleteButtonClassname * Update availability.tsx * fixup! Merge branch 'main' into add-custom-classname-to-booker-atom-wrapper --------- Co-authored-by: Morgan <33722304+ThyMinimalDev@users.noreply.github.com> Co-authored-by: Morgan Vernay --- packages/features/bookings/Booker/types.ts | 1 + .../availability/AvailabilitySettings.tsx | 99 ++++++++++++------- .../AvailabilitySettingsPlatformWrapper.tsx | 6 ++ .../atoms/booker/BookerPlatformWrapper.tsx | 2 +- .../wrappers/EventTypePlatformWrapper.tsx | 12 ++- .../atoms/src/components/atoms-wrapper.tsx | 16 ++- .../examples/base/src/pages/availability.tsx | 1 + .../examples/base/src/pages/event-types.tsx | 1 + 8 files changed, 96 insertions(+), 42 deletions(-) diff --git a/packages/features/bookings/Booker/types.ts b/packages/features/bookings/Booker/types.ts index 42fd05a0fe..e34f7da558 100644 --- a/packages/features/bookings/Booker/types.ts +++ b/packages/features/bookings/Booker/types.ts @@ -151,4 +151,5 @@ export type CustomClassNames = { availableTimeSlotsTimeFormatToggle?: string; availableTimes?: string; }; + atomsWrapper: string; }; diff --git a/packages/platform/atoms/availability/AvailabilitySettings.tsx b/packages/platform/atoms/availability/AvailabilitySettings.tsx index 89c9971f1d..7bb6be7b7d 100644 --- a/packages/platform/atoms/availability/AvailabilitySettings.tsx +++ b/packages/platform/atoms/availability/AvailabilitySettings.tsx @@ -66,6 +66,11 @@ export type CustomClassNames = { labelAndSwitchContainer?: string; }; overridesModalClassNames?: string; + hiddenSwitchClassname?: { + container?: string; + thumb?: string; + }; + deleteButtonClassname?: string; }; export type Availability = Pick; @@ -85,6 +90,8 @@ type AvailabilitySettingsProps = { }; travelSchedules?: RouterOutputs["viewer"]["getTravelSchedules"]; handleDelete: () => void; + allowDelete?: boolean; + allowSetToDefault?: boolean; isDeleting: boolean; isSaving: boolean; isLoading: boolean; @@ -252,6 +259,8 @@ export function AvailabilitySettings({ disableEditableHeading = false, enableOverrides = false, bulkUpdateModalProps, + allowSetToDefault = true, + allowDelete = true, }: AvailabilitySettingsProps) { const [openSidebar, setOpenSidebar] = useState(false); const { t, i18n } = useLocale(); @@ -314,7 +323,7 @@ export function AvailabilitySettings({ CTA={
- {!openSidebar ? ( + {!openSidebar && allowSetToDefault ? ( <> ( { @@ -339,6 +352,7 @@ export function AvailabilitySettings({ /> )} /> + ) : null}
@@ -353,14 +367,17 @@ export function AvailabilitySettings({ /> )} - - - + {allowDelete && ( + <> + + + + )} <>
@@ -403,25 +422,33 @@ export function AvailabilitySettings({ />
- - {t("set_to_default")} - - ( - + + {t("set_to_default")} + + ( + + )} /> - )} - /> + + )}
diff --git a/packages/platform/atoms/availability/wrappers/AvailabilitySettingsPlatformWrapper.tsx b/packages/platform/atoms/availability/wrappers/AvailabilitySettingsPlatformWrapper.tsx index fee22a5050..cad2cda278 100644 --- a/packages/platform/atoms/availability/wrappers/AvailabilitySettingsPlatformWrapper.tsx +++ b/packages/platform/atoms/availability/wrappers/AvailabilitySettingsPlatformWrapper.tsx @@ -33,6 +33,8 @@ type AvailabilitySettingsPlatformWrapperProps = { disableEditableHeading?: boolean; enableOverrides?: boolean; onBeforeUpdate?: (updateBody: UpdateScheduleInput_2024_06_11) => boolean | Promise; + allowDelete?: boolean; + allowSetToDefault?: boolean; }; export const AvailabilitySettingsPlatformWrapper = ({ @@ -45,6 +47,8 @@ export const AvailabilitySettingsPlatformWrapper = ({ disableEditableHeading = false, enableOverrides = false, onBeforeUpdate, + allowDelete, + allowSetToDefault, }: AvailabilitySettingsPlatformWrapperProps) => { const { isLoading, data: schedule } = useSchedule(id); const { data: schedules } = useSchedules(); @@ -142,6 +146,8 @@ export const AvailabilitySettingsPlatformWrapper = ({ backPath="" isPlatform={true} customClassNames={customClassNames} + allowDelete={allowDelete} + allowSetToDefault={allowSetToDefault} /> ); diff --git a/packages/platform/atoms/booker/BookerPlatformWrapper.tsx b/packages/platform/atoms/booker/BookerPlatformWrapper.tsx index 2620a5d7ba..b700f86ab2 100644 --- a/packages/platform/atoms/booker/BookerPlatformWrapper.tsx +++ b/packages/platform/atoms/booker/BookerPlatformWrapper.tsx @@ -401,7 +401,7 @@ export const BookerPlatformWrapper = ( }, [view, isOverlayCalendarEnabled]); return ( - + void; onDeleteError?: (msg: string) => void; allowDelete: boolean; + customClassNames?: { + atomsWrapper?: string; + }; }; const EventType = ({ @@ -45,6 +48,7 @@ const EventType = ({ onDeleteError, id, allowDelete = true, + customClassNames, ...props }: EventTypeSetupProps & EventTypePlatformWrapperProps) => { const { t } = useLocale(); @@ -84,7 +88,7 @@ const EventType = ({ // Reset the form with these values as new default values to ensure the correct comparison for dirtyFields eval form.reset(currentValues); toast({ description: t("event_type_updated_successfully", { eventTypeTitle: eventType.title }) }); - props.onSuccess?.(currentValues); + onSuccess?.(currentValues); }, async onSettled() { return; @@ -93,7 +97,7 @@ const EventType = ({ const currentValues = form.getValues(); const message = err?.message; toast({ description: message ? t(message) : t(err.message) }); - props.onError?.(currentValues, err); + onError?.(currentValues, err); }, }); @@ -185,7 +189,7 @@ const EventType = ({ tabs, }); return ( - + { const { data: eventTypeQueryData } = useAtomsEventTypeById(id); const queryClient = useQueryClient(); @@ -258,6 +263,7 @@ export const EventTypePlatformWrapper = ({ onDeleteSuccess={onDeleteSuccess} onDeleteError={onDeleteError} allowDelete={allowDelete} + customClassNames={customClassNames} /> ); }; diff --git a/packages/platform/atoms/src/components/atoms-wrapper.tsx b/packages/platform/atoms/src/components/atoms-wrapper.tsx index 0ef2b832ba..83076b5cbe 100644 --- a/packages/platform/atoms/src/components/atoms-wrapper.tsx +++ b/packages/platform/atoms/src/components/atoms-wrapper.tsx @@ -1,7 +1,19 @@ import type { ReactNode } from "react"; +import { classNames } from "@calcom/lib"; + import { CALCOM_ATOMS_WRAPPER_CLASS } from "../constants/styles"; -export const AtomsWrapper = ({ children }: { children: ReactNode }) => { - return
{children}
; +export const AtomsWrapper = ({ + children, + customClassName, +}: { + children: ReactNode; + customClassName?: string; +}) => { + return ( +
+ {children} +
+ ); }; diff --git a/packages/platform/examples/base/src/pages/availability.tsx b/packages/platform/examples/base/src/pages/availability.tsx index 6be3b2ad4f..068e499de9 100644 --- a/packages/platform/examples/base/src/pages/availability.tsx +++ b/packages/platform/examples/base/src/pages/availability.tsx @@ -16,6 +16,7 @@ export default function Availability(props: { calUsername: string; calEmail: str subtitlesClassName: "text-red-500", ctaClassName: "border p-4 rounded-md", editableHeadingClassName: "underline font-semibold", + hiddenSwitchClassname: { thumb: "bg-red-500" }, }} onUpdateSuccess={() => { console.log("Updated successfully"); diff --git a/packages/platform/examples/base/src/pages/event-types.tsx b/packages/platform/examples/base/src/pages/event-types.tsx index 643822cf86..653b494802 100644 --- a/packages/platform/examples/base/src/pages/event-types.tsx +++ b/packages/platform/examples/base/src/pages/event-types.tsx @@ -89,6 +89,7 @@ export default function Bookings(props: { calUsername: string; calEmail: string {eventTypeId && (