Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: added custom class name to booker and availability atom #17105

Merged
merged 10 commits into from
Oct 16, 2024
Merged
1 change: 1 addition & 0 deletions packages/features/bookings/Booker/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -151,4 +151,5 @@ export type CustomClassNames = {
availableTimeSlotsTimeFormatToggle?: string;
availableTimes?: string;
};
atomsWrapper: string;
};
99 changes: 63 additions & 36 deletions packages/platform/atoms/availability/AvailabilitySettings.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,11 @@ export type CustomClassNames = {
labelAndSwitchContainer?: string;
};
overridesModalClassNames?: string;
hiddenSwitchClassname?: {
container?: string;
thumb?: string;
};
deleteButtonClassname?: string;
};

export type Availability = Pick<Schedule, "days" | "startTime" | "endTime">;
Expand All @@ -85,6 +90,8 @@ type AvailabilitySettingsProps = {
};
travelSchedules?: RouterOutputs["viewer"]["getTravelSchedules"];
handleDelete: () => void;
allowDelete?: boolean;
allowSetToDefault?: boolean;
isDeleting: boolean;
isSaving: boolean;
isLoading: boolean;
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -314,7 +323,7 @@ export function AvailabilitySettings({
CTA={
<div className={cn(customClassNames?.ctaClassName, "flex items-center justify-end")}>
<div className="sm:hover:bg-muted hidden items-center rounded-md px-2 transition sm:flex">
{!openSidebar ? (
{!openSidebar && allowSetToDefault ? (
<>
<Skeleton
as={Label}
Expand All @@ -330,6 +339,10 @@ export function AvailabilitySettings({
render={({ field: { value, onChange } }) => (
<Switch
id="hiddenSwitch"
classNames={{
container: cn(customClassNames?.hiddenSwitchClassname?.container),
thumb: cn(customClassNames?.hiddenSwitchClassname?.thumb),
}}
disabled={isSaving || schedule.isDefault}
checked={value}
onCheckedChange={(checked) => {
Expand All @@ -339,6 +352,7 @@ export function AvailabilitySettings({
/>
)}
/>
<VerticalDivider className="hidden sm:inline" />
</>
) : null}
</div>
Expand All @@ -353,14 +367,17 @@ export function AvailabilitySettings({
/>
)}

<VerticalDivider className="hidden sm:inline" />
<DeleteDialogButton
buttonClassName="hidden sm:inline"
disabled={schedule.isLastSchedule}
isPending={isDeleting}
handleDelete={handleDelete}
/>
<VerticalDivider className="hidden sm:inline" />
{allowDelete && (
<>
<DeleteDialogButton
buttonClassName={cn("hidden sm:inline", customClassNames?.deleteButtonClassname)}
disabled={schedule.isLastSchedule}
isPending={isDeleting}
handleDelete={handleDelete}
/>
<VerticalDivider className="hidden sm:inline" />
</>
)}
<SmallScreenSideBar open={openSidebar}>
<>
<div
Expand All @@ -377,15 +394,17 @@ export function AvailabilitySettings({
<div className="flex flex-row items-center pt-5">
<Button StartIcon="arrow-left" color="minimal" onClick={() => setOpenSidebar(false)} />
<p className="-ml-2">{t("availability_settings")}</p>
<DeleteDialogButton
buttonClassName="ml-16 inline"
disabled={schedule.isLastSchedule}
isPending={isDeleting}
handleDelete={handleDelete}
onDeleteConfirmed={() => {
setOpenSidebar(false);
}}
/>
{allowDelete && (
<DeleteDialogButton
buttonClassName={cn("ml-16 inline", customClassNames?.deleteButtonClassname)}
disabled={schedule.isLastSchedule}
isPending={isDeleting}
handleDelete={handleDelete}
onDeleteConfirmed={() => {
setOpenSidebar(false);
}}
/>
)}
</div>
<div className="flex flex-col px-2 py-2">
<Skeleton as={Label} waitForTranslation={!isPlatform}>
Expand All @@ -403,25 +422,33 @@ export function AvailabilitySettings({
/>
</div>
<div className="flex h-9 flex-row-reverse items-center justify-end gap-3 px-2">
<Skeleton
as={Label}
htmlFor="hiddenSwitch"
className="mt-2 cursor-pointer self-center pr-2 sm:inline"
waitForTranslation={!isPlatform}>
{t("set_to_default")}
</Skeleton>
<Controller
control={form.control}
name="isDefault"
render={({ field: { value, onChange } }) => (
<Switch
id="hiddenSwitch"
disabled={isSaving || value}
checked={value}
onCheckedChange={onChange}
{allowSetToDefault && (
<>
<Skeleton
as={Label}
htmlFor="hiddenSwitch"
className="mt-2 cursor-pointer self-center pr-2 sm:inline"
waitForTranslation={!isPlatform}>
{t("set_to_default")}
</Skeleton>
<Controller
control={form.control}
name="isDefault"
render={({ field: { value, onChange } }) => (
<Switch
classNames={{
container: cn(customClassNames?.hiddenSwitchClassname?.container),
thumb: cn(customClassNames?.hiddenSwitchClassname?.thumb),
}}
id="hiddenSwitch"
disabled={isSaving || value}
checked={value}
onCheckedChange={onChange}
/>
)}
/>
)}
/>
</>
)}
</div>

<div className="min-w-40 col-span-3 space-y-2 px-2 py-4 lg:col-span-1">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ type AvailabilitySettingsPlatformWrapperProps = {
disableEditableHeading?: boolean;
enableOverrides?: boolean;
onBeforeUpdate?: (updateBody: UpdateScheduleInput_2024_06_11) => boolean | Promise<boolean>;
allowDelete?: boolean;
allowSetToDefault?: boolean;
};

export const AvailabilitySettingsPlatformWrapper = ({
Expand All @@ -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();
Expand Down Expand Up @@ -142,6 +146,8 @@ export const AvailabilitySettingsPlatformWrapper = ({
backPath=""
isPlatform={true}
customClassNames={customClassNames}
allowDelete={allowDelete}
allowSetToDefault={allowSetToDefault}
/>
</AtomsWrapper>
);
Expand Down
2 changes: 1 addition & 1 deletion packages/platform/atoms/booker/BookerPlatformWrapper.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -401,7 +401,7 @@ export const BookerPlatformWrapper = (
}, [view, isOverlayCalendarEnabled]);

return (
<AtomsWrapper>
<AtomsWrapper customClassName={props?.customClassNames?.atomsWrapper}>
<BookerComponent
customClassNames={props.customClassNames}
eventSlug={props.eventSlug}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,9 @@ export type EventTypePlatformWrapperProps = {
onDeleteSuccess?: () => void;
onDeleteError?: (msg: string) => void;
allowDelete: boolean;
customClassNames?: {
atomsWrapper?: string;
};
};

const EventType = ({
Expand All @@ -45,6 +48,7 @@ const EventType = ({
onDeleteError,
id,
allowDelete = true,
customClassNames,
...props
}: EventTypeSetupProps & EventTypePlatformWrapperProps) => {
const { t } = useLocale();
Expand Down Expand Up @@ -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;
Expand All @@ -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);
},
});

Expand Down Expand Up @@ -185,7 +189,7 @@ const EventType = ({
tabs,
});
return (
<AtomsWrapper>
<AtomsWrapper customClassName={customClassNames?.atomsWrapper}>
<EventTypeComponent
{...props}
tabMap={tabMap}
Expand Down Expand Up @@ -228,6 +232,7 @@ export const EventTypePlatformWrapper = ({
onDeleteSuccess,
onDeleteError,
allowDelete = true,
customClassNames,
}: EventTypePlatformWrapperProps) => {
const { data: eventTypeQueryData } = useAtomsEventTypeById(id);
const queryClient = useQueryClient();
Expand Down Expand Up @@ -258,6 +263,7 @@ export const EventTypePlatformWrapper = ({
onDeleteSuccess={onDeleteSuccess}
onDeleteError={onDeleteError}
allowDelete={allowDelete}
customClassNames={customClassNames}
/>
);
};
16 changes: 14 additions & 2 deletions packages/platform/atoms/src/components/atoms-wrapper.tsx
Original file line number Diff line number Diff line change
@@ -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 <div className={`${CALCOM_ATOMS_WRAPPER_CLASS} m-0 w-auto p-0`}>{children}</div>;
export const AtomsWrapper = ({
children,
customClassName,
}: {
children: ReactNode;
customClassName?: string;
}) => {
return (
<div className={classNames(`${CALCOM_ATOMS_WRAPPER_CLASS} m-0 w-auto p-0`, customClassName)}>
{children}
</div>
);
};
1 change: 1 addition & 0 deletions packages/platform/examples/base/src/pages/availability.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down
1 change: 1 addition & 0 deletions packages/platform/examples/base/src/pages/event-types.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ export default function Bookings(props: { calUsername: string; calEmail: string
{eventTypeId && (
<div>
<EventTypeSettings
customClassNames={{ atomsWrapper: "!w-[50vw] !m-auto" }}
allowDelete={true}
id={eventTypeId}
tabs={["setup", "limits", "recurring", "advanced", "availability"]}
Expand Down
Loading