feat: added customClassnames for event-setup tab (#17240)
* feat: added customClassnames for event-setup tab * Update EventTypePlatformWrapper.tsx * better classnames naming * added classNames to common types * updated classnames to use the common exported types * udpate * better classnames * better classname names * classnames -> classNames * added default styling * Update Locations.tsx * Update event-types.tsx * update * locationSelectCustomClassNames -> LocationSelectCustomClassNames * Update documentation.json * fix: better classnames * Update types.ts
This commit is contained in:
1 parent
ad44ca9f2a
commit
e477e5892c
5 files changed
+321
-42
No files matched your search
@@ -9,10 +9,18 @@ import type { UseFormGetValues, UseFormSetValue, Control, FormState } from "reac
|
||||
import type { EventLocationType } from "@calcom/app-store/locations";
|
||||
import { getEventLocationType, MeetLocationType } from "@calcom/app-store/locations";
|
||||
import { useIsPlatform } from "@calcom/atoms/monorepo";
|
||||
import type { LocationFormValues, EventTypeSetupProps } from "@calcom/features/eventtypes/lib/types";
|
||||
import type {
|
||||
LocationFormValues,
|
||||
EventTypeSetupProps,
|
||||
CheckboxClassNames,
|
||||
} from "@calcom/features/eventtypes/lib/types";
|
||||
import CheckboxField from "@calcom/features/form/components/CheckboxField";
|
||||
import type { SingleValueLocationOption } from "@calcom/features/form/components/LocationSelect";
|
||||
import type {
|
||||
LocationSelectCustomClassNames,
|
||||
SingleValueLocationOption,
|
||||
} from "@calcom/features/form/components/LocationSelect";
|
||||
import LocationSelect from "@calcom/features/form/components/LocationSelect";
|
||||
import { classNames } from "@calcom/lib";
|
||||
import { WEBAPP_URL } from "@calcom/lib/constants";
|
||||
import { useLocale } from "@calcom/lib/hooks/useLocale";
|
||||
import { Icon, Input, PhoneInput, Button, showToast } from "@calcom/ui";
|
||||
@@ -22,6 +30,24 @@ export type TLocationOptions = Pick<EventTypeSetupProps, "locationOptions">["loc
|
||||
export type TDestinationCalendar = { integration: string } | null;
|
||||
export type TPrefillLocation = { credentialId?: number; type: string };
|
||||
|
||||
type LocationInputCustomClassNames = {
|
||||
addressInput?: string;
|
||||
phoneInput?: string;
|
||||
};
|
||||
|
||||
export type LocationCustomClassNames = {
|
||||
container?: string;
|
||||
locationSelect?: LocationSelectCustomClassNames;
|
||||
removeLocationButton?: string;
|
||||
removeLocationIcon?: string;
|
||||
addLocationButton?: string;
|
||||
organizerContactInput?: {
|
||||
errorMessage?: string;
|
||||
locationInput?: LocationInputCustomClassNames;
|
||||
publicDisplayCheckbox?: CheckboxClassNames;
|
||||
};
|
||||
};
|
||||
|
||||
type LocationsProps = {
|
||||
team: { id: number } | null;
|
||||
destinationCalendar: TDestinationCalendar;
|
||||
@@ -36,6 +62,7 @@ type LocationsProps = {
|
||||
eventType: TEventTypeLocation;
|
||||
locationOptions: TLocationOptions;
|
||||
prefillLocation?: SingleValueLocationOption;
|
||||
customClassNames?: LocationCustomClassNames;
|
||||
};
|
||||
|
||||
const getLocationFromType = (type: EventLocationType["type"], locationOptions: TLocationOptions) => {
|
||||
@@ -84,6 +111,7 @@ const Locations: React.FC<LocationsProps> = ({
|
||||
team,
|
||||
eventType,
|
||||
prefillLocation,
|
||||
customClassNames,
|
||||
...props
|
||||
}) => {
|
||||
const { t } = useLocale();
|
||||
@@ -135,8 +163,9 @@ const Locations: React.FC<LocationsProps> = ({
|
||||
eventLocationType: EventLocationType;
|
||||
defaultValue?: string;
|
||||
index: number;
|
||||
customClassNames?: LocationInputCustomClassNames;
|
||||
}) => {
|
||||
const { eventLocationType, index, ...remainingProps } = props;
|
||||
const { eventLocationType, index, customClassNames, ...remainingProps } = props;
|
||||
if (eventLocationType?.organizerInputType === "text") {
|
||||
const { defaultValue, ...rest } = remainingProps;
|
||||
|
||||
@@ -154,7 +183,7 @@ const Locations: React.FC<LocationsProps> = ({
|
||||
onChange={onChange}
|
||||
value={value}
|
||||
{...(disableLocationProp ? { disabled: true } : {})}
|
||||
className="my-0"
|
||||
className={classNames("my-0", customClassNames?.addressInput)}
|
||||
{...rest}
|
||||
/>
|
||||
);
|
||||
@@ -175,6 +204,7 @@ const Locations: React.FC<LocationsProps> = ({
|
||||
disabled={disableLocationProp}
|
||||
placeholder={t(eventLocationType.organizerInputPlaceholder || "")}
|
||||
name={`locations[${index}].${eventLocationType.defaultValueVariable}`}
|
||||
className={customClassNames?.phoneInput}
|
||||
value={value}
|
||||
onChange={onChange}
|
||||
{...rest}
|
||||
@@ -213,8 +243,8 @@ const Locations: React.FC<LocationsProps> = ({
|
||||
const isPlatorm = useIsPlatform();
|
||||
|
||||
return (
|
||||
<div className="w-full">
|
||||
<ul ref={animationRef} className="space-y-2">
|
||||
<div className={classNames("w-full", customClassNames?.container)}>
|
||||
<ul ref={animationRef} className={classNames("space-y-2")}>
|
||||
{locationFields.map((field, index) => {
|
||||
const eventLocationType = getEventLocationType(field.type);
|
||||
const defaultLocation = field;
|
||||
@@ -230,7 +260,11 @@ const Locations: React.FC<LocationsProps> = ({
|
||||
isDisabled={disableLocationProp}
|
||||
defaultValue={option}
|
||||
isSearchable={false}
|
||||
className="block min-w-0 flex-1 rounded-sm text-sm"
|
||||
className={classNames(
|
||||
"block min-w-0 flex-1 rounded-sm text-sm",
|
||||
customClassNames?.locationSelect?.selectWrapper
|
||||
)}
|
||||
customClassNames={customClassNames?.locationSelect}
|
||||
menuPlacement="auto"
|
||||
onChange={(e: SingleValueLocationOption) => {
|
||||
setShowEmptyLocationSelect(false);
|
||||
@@ -275,12 +309,18 @@ const Locations: React.FC<LocationsProps> = ({
|
||||
{!(disableLocationProp && isChildrenManagedEventType) && (
|
||||
<button
|
||||
data-testid={`delete-locations.${index}.type`}
|
||||
className="min-h-9 block h-9 px-2"
|
||||
className={classNames("min-h-9 block h-9 px-2", customClassNames?.removeLocationButton)}
|
||||
type="button"
|
||||
onClick={() => remove(index)}
|
||||
aria-label={t("remove")}>
|
||||
<div className="h-4 w-4">
|
||||
<Icon name="x" className="border-l-1 hover:text-emphasis text-subtle h-4 w-4" />
|
||||
<Icon
|
||||
name="x"
|
||||
className={classNames(
|
||||
"border-l-1 hover:text-emphasis text-subtle h-4 w-4",
|
||||
customClassNames?.removeLocationIcon
|
||||
)}
|
||||
/>
|
||||
</div>
|
||||
</button>
|
||||
)}
|
||||
@@ -302,23 +342,32 @@ const Locations: React.FC<LocationsProps> = ({
|
||||
}
|
||||
eventLocationType={eventLocationType}
|
||||
index={index}
|
||||
customClassNames={customClassNames?.organizerContactInput?.locationInput}
|
||||
/>
|
||||
</div>
|
||||
<ErrorMessage
|
||||
errors={formState.errors?.locations?.[index]}
|
||||
name={eventLocationType.defaultValueVariable}
|
||||
className="text-error my-1 ml-6 text-sm"
|
||||
className={classNames(
|
||||
"text-error my-1 ml-6 text-sm",
|
||||
customClassNames?.organizerContactInput?.errorMessage
|
||||
)}
|
||||
as="div"
|
||||
id="location-error"
|
||||
/>
|
||||
</div>
|
||||
<div className="ml-6">
|
||||
<div
|
||||
className={classNames(
|
||||
"ml-6",
|
||||
customClassNames?.organizerContactInput?.publicDisplayCheckbox?.container
|
||||
)}>
|
||||
<CheckboxField
|
||||
name={`locations[${index}].displayLocationPublicly`}
|
||||
data-testid="display-location"
|
||||
disabled={disableLocationProp}
|
||||
defaultChecked={defaultLocation?.displayLocationPublicly}
|
||||
description={t("display_location_label")}
|
||||
className={customClassNames?.organizerContactInput?.publicDisplayCheckbox?.checkbox}
|
||||
onChange={(e) => {
|
||||
const fieldValues = getValues("locations")[index];
|
||||
updateLocationField(index, {
|
||||
@@ -344,7 +393,11 @@ const Locations: React.FC<LocationsProps> = ({
|
||||
isDisabled={disableLocationProp}
|
||||
defaultValue={defaultValue}
|
||||
isSearchable={false}
|
||||
className="block w-full min-w-0 flex-1 rounded-sm text-sm"
|
||||
className={classNames(
|
||||
"block w-full min-w-0 flex-1 rounded-sm text-sm",
|
||||
customClassNames?.locationSelect?.selectWrapper
|
||||
)}
|
||||
customClassNames={customClassNames?.locationSelect}
|
||||
menuPlacement="auto"
|
||||
onChange={(e: SingleValueLocationOption) => {
|
||||
setShowEmptyLocationSelect(false);
|
||||
@@ -413,6 +466,7 @@ const Locations: React.FC<LocationsProps> = ({
|
||||
StartIcon="plus"
|
||||
color="minimal"
|
||||
disabled={seatsEnabled}
|
||||
className={classNames(customClassNames?.addLocationButton)}
|
||||
tooltip={seatsEnabled ? t("seats_option_doesnt_support_multi_location") : undefined}
|
||||
onClick={() => setShowEmptyLocationSelect(true)}>
|
||||
{t("add_location")}
|
||||
|
||||
@@ -5,26 +5,59 @@ import type { MultiValue } from "react-select";
|
||||
|
||||
import { useIsPlatform } from "@calcom/atoms/monorepo";
|
||||
import useLockedFieldsManager from "@calcom/features/ee/managed-event-types/hooks/useLockedFieldsManager";
|
||||
import type { LocationCustomClassNames } from "@calcom/features/eventtypes/components/Locations";
|
||||
import Locations from "@calcom/features/eventtypes/components/Locations";
|
||||
import type { EventTypeSetupProps } from "@calcom/features/eventtypes/lib/types";
|
||||
import type {
|
||||
EventTypeSetupProps,
|
||||
InputClassNames,
|
||||
SelectClassNames,
|
||||
SettingsToggleClassNames,
|
||||
} from "@calcom/features/eventtypes/lib/types";
|
||||
import type { FormValues, LocationFormValues } from "@calcom/features/eventtypes/lib/types";
|
||||
import { classNames } from "@calcom/lib";
|
||||
import { useLocale } from "@calcom/lib/hooks/useLocale";
|
||||
import { md } from "@calcom/lib/markdownIt";
|
||||
import { slugify } from "@calcom/lib/slugify";
|
||||
import turndown from "@calcom/lib/turndownService";
|
||||
import { Label, Select, SettingsToggle, Skeleton, TextField, Editor, TextAreaField } from "@calcom/ui";
|
||||
|
||||
export type EventSetupTabCustomClassNames = {
|
||||
wrapper?: string;
|
||||
titleSection?: {
|
||||
container?: string;
|
||||
titleInput?: InputClassNames;
|
||||
urlInput?: InputClassNames;
|
||||
descriptionInput?: Pick<InputClassNames, "input" | "label">;
|
||||
};
|
||||
durationSection?: {
|
||||
container?: string;
|
||||
singleDurationInput?: InputClassNames;
|
||||
multipleDuration?: {
|
||||
container?: string;
|
||||
availableDurationsSelect?: SelectClassNames;
|
||||
defaultDurationSelect?: SelectClassNames;
|
||||
};
|
||||
selectDurationToggle?: SettingsToggleClassNames;
|
||||
};
|
||||
locationSection?: LocationCustomClassNames & {
|
||||
container?: string;
|
||||
label?: string;
|
||||
};
|
||||
};
|
||||
|
||||
export type EventSetupTabProps = Pick<
|
||||
EventTypeSetupProps,
|
||||
"eventType" | "locationOptions" | "team" | "teamMembers" | "destinationCalendar"
|
||||
>;
|
||||
> & {
|
||||
customClassNames?: EventSetupTabCustomClassNames;
|
||||
};
|
||||
export const EventSetupTab = (
|
||||
props: EventSetupTabProps & { urlPrefix: string; hasOrgBranding: boolean; orgId?: number }
|
||||
) => {
|
||||
const { t } = useLocale();
|
||||
const isPlatform = useIsPlatform();
|
||||
const formMethods = useFormContext<FormValues>();
|
||||
const { eventType, team, urlPrefix, hasOrgBranding, orgId } = props;
|
||||
const { eventType, team, urlPrefix, hasOrgBranding, customClassNames, orgId } = props;
|
||||
const [multipleDuration, setMultipleDuration] = useState(
|
||||
formMethods.getValues("metadata")?.multipleDuration
|
||||
);
|
||||
@@ -60,10 +93,17 @@ export const EventSetupTab = (
|
||||
|
||||
return (
|
||||
<div>
|
||||
<div className="space-y-4">
|
||||
<div className="border-subtle space-y-6 rounded-lg border p-6">
|
||||
<div className={classNames("space-y-4", customClassNames?.wrapper)}>
|
||||
<div
|
||||
className={classNames(
|
||||
"border-subtle space-y-6 rounded-lg border p-6",
|
||||
customClassNames?.titleSection?.container
|
||||
)}>
|
||||
<TextField
|
||||
required
|
||||
containerClassName={classNames(customClassNames?.titleSection?.titleInput?.container)}
|
||||
labelClassName={classNames(customClassNames?.titleSection?.titleInput?.label)}
|
||||
className={classNames(customClassNames?.titleSection?.titleInput?.input)}
|
||||
label={t("title")}
|
||||
{...(isManagedEventType || isChildrenManagedEventType ? titleLockedProps : {})}
|
||||
defaultValue={eventType.title}
|
||||
@@ -77,6 +117,10 @@ export const EventSetupTab = (
|
||||
disabled: descriptionLockedProps.disabled,
|
||||
})}
|
||||
placeholder={t("quick_video_meeting")}
|
||||
className={customClassNames?.titleSection?.descriptionInput?.input}
|
||||
labelProps={{
|
||||
className: customClassNames?.titleSection?.descriptionInput?.label,
|
||||
}}
|
||||
/>
|
||||
) : (
|
||||
<>
|
||||
@@ -115,6 +159,9 @@ export const EventSetupTab = (
|
||||
{...(isManagedEventType || isChildrenManagedEventType ? urlLockedProps : {})}
|
||||
defaultValue={eventType.slug}
|
||||
data-testid="event-slug"
|
||||
containerClassName={classNames(customClassNames?.titleSection?.urlInput?.container)}
|
||||
labelClassName={classNames(customClassNames?.titleSection?.urlInput?.label)}
|
||||
className={classNames(customClassNames?.titleSection?.urlInput?.input)}
|
||||
addOnLeading={
|
||||
isPlatform ? undefined : (
|
||||
<>
|
||||
@@ -133,11 +180,24 @@ export const EventSetupTab = (
|
||||
})}
|
||||
/>
|
||||
</div>
|
||||
<div className="border-subtle rounded-lg border p-6">
|
||||
<div
|
||||
className={classNames(
|
||||
"border-subtle rounded-lg border p-6",
|
||||
customClassNames?.durationSection?.container
|
||||
)}>
|
||||
{multipleDuration ? (
|
||||
<div className="space-y-6">
|
||||
<div
|
||||
className={classNames(
|
||||
"space-y-6",
|
||||
customClassNames?.durationSection?.multipleDuration?.availableDurationsSelect?.container
|
||||
)}>
|
||||
<div>
|
||||
<Skeleton as={Label} loadingClassName="w-16">
|
||||
<Skeleton
|
||||
as={Label}
|
||||
loadingClassName="w-16"
|
||||
className={
|
||||
customClassNames?.durationSection?.multipleDuration?.availableDurationsSelect?.label
|
||||
}>
|
||||
{t("available_durations")}
|
||||
</Skeleton>
|
||||
<Select
|
||||
@@ -146,7 +206,14 @@ export const EventSetupTab = (
|
||||
name="metadata.multipleDuration"
|
||||
isSearchable={false}
|
||||
isDisabled={lengthLockedProps.disabled}
|
||||
className="h-auto !min-h-[36px] text-sm"
|
||||
className={classNames(
|
||||
"h-auto !min-h-[36px] text-sm",
|
||||
customClassNames?.durationSection?.multipleDuration?.availableDurationsSelect?.select
|
||||
)}
|
||||
innerClassNames={
|
||||
customClassNames?.durationSection?.multipleDuration?.availableDurationsSelect
|
||||
?.innerClassNames
|
||||
}
|
||||
options={multipleDurationOptions}
|
||||
value={selectedMultipleDuration}
|
||||
onChange={(options) => {
|
||||
@@ -173,8 +240,16 @@ export const EventSetupTab = (
|
||||
}}
|
||||
/>
|
||||
</div>
|
||||
<div>
|
||||
<Skeleton as={Label} loadingClassName="w-16">
|
||||
<div
|
||||
className={
|
||||
customClassNames?.durationSection?.multipleDuration?.defaultDurationSelect?.container
|
||||
}>
|
||||
<Skeleton
|
||||
as={Label}
|
||||
loadingClassName="w-16"
|
||||
className={
|
||||
customClassNames?.durationSection?.multipleDuration?.defaultDurationSelect?.label
|
||||
}>
|
||||
{t("default_duration")}
|
||||
{shouldLockIndicator("length")}
|
||||
</Skeleton>
|
||||
@@ -182,7 +257,14 @@ export const EventSetupTab = (
|
||||
value={defaultDuration}
|
||||
isSearchable={false}
|
||||
name="length"
|
||||
className="text-sm"
|
||||
className={classNames(
|
||||
"text-sm",
|
||||
customClassNames?.durationSection?.multipleDuration?.defaultDurationSelect?.select
|
||||
)}
|
||||
innerClassNames={
|
||||
customClassNames?.durationSection?.multipleDuration?.defaultDurationSelect
|
||||
?.innerClassNames
|
||||
}
|
||||
isDisabled={lengthLockedProps.disabled}
|
||||
noOptionsMessage={() => t("default_duration_no_options")}
|
||||
options={selectedMultipleDuration}
|
||||
@@ -199,6 +281,11 @@ export const EventSetupTab = (
|
||||
<TextField
|
||||
required
|
||||
type="number"
|
||||
containerClassName={classNames(
|
||||
customClassNames?.durationSection?.singleDurationInput?.container
|
||||
)}
|
||||
labelClassName={classNames(customClassNames?.durationSection?.singleDurationInput?.label)}
|
||||
className={classNames(customClassNames?.durationSection?.singleDurationInput?.input)}
|
||||
data-testid="duration"
|
||||
{...(isManagedEventType || isChildrenManagedEventType ? lengthLockedProps : {})}
|
||||
label={t("duration")}
|
||||
@@ -215,6 +302,10 @@ export const EventSetupTab = (
|
||||
checked={multipleDuration !== undefined}
|
||||
disabled={seatsEnabled}
|
||||
tooltip={seatsEnabled ? t("seat_options_doesnt_multiple_durations") : undefined}
|
||||
labelClassName={customClassNames?.durationSection?.selectDurationToggle?.label}
|
||||
descriptionClassName={customClassNames?.durationSection?.selectDurationToggle?.description}
|
||||
switchContainerClassName={customClassNames?.durationSection?.selectDurationToggle?.container}
|
||||
childrenClassName={customClassNames?.durationSection?.selectDurationToggle?.children}
|
||||
onCheckedChange={() => {
|
||||
if (multipleDuration !== undefined) {
|
||||
setMultipleDuration(undefined);
|
||||
@@ -232,9 +323,17 @@ export const EventSetupTab = (
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
<div className="border-subtle rounded-lg border p-6">
|
||||
<div
|
||||
className={classNames(
|
||||
"border-subtle rounded-lg border p-6",
|
||||
customClassNames?.locationSection?.container
|
||||
)}>
|
||||
<div>
|
||||
<Skeleton as={Label} loadingClassName="w-16" htmlFor="locations">
|
||||
<Skeleton
|
||||
as={Label}
|
||||
loadingClassName="w-16"
|
||||
htmlFor="locations"
|
||||
className={customClassNames?.locationSection?.label}>
|
||||
{t("location")}
|
||||
{/*improve shouldLockIndicator function to also accept eventType and then conditionally render
|
||||
based on Managed Event type or not.*/}
|
||||
@@ -255,6 +354,7 @@ export const EventSetupTab = (
|
||||
control={formMethods.control as unknown as Control<LocationFormValues>}
|
||||
formState={formMethods.formState as unknown as FormState<LocationFormValues>}
|
||||
{...props}
|
||||
customClassNames={customClassNames?.locationSection}
|
||||
/>
|
||||
)}
|
||||
/>
|
||||
|
||||
Reference in new issue
Block a user