feat: Add custom label for organizer default app and link meeting (#23114)
* Create `CalVideoSettings` type * Create `LocationOptionContainer` * Extract cal video settings to `CalVideoSettings` * Refactor `<Locations />` component to use `<CalVideoSettings />` * Unify naming * Move location folder back under components * Type fixes * Extract types * Add custom label prop to default app types * Extract `LocationInput` component * Create `DefaultLocationSettings` component * Move `locations` folder * Add custom label field for link and organizer default locations * Type fixes * Save the custom label in db * Include location custom label when querying db * Display custom label on booking page * Add translations * Type fixes * Change `customLabel` to `supportsCustomLabel` * Remove unused code * Show the customLabel on booking page * Fix hover tooltip text as well * Fix displaying exact value on booking page * Add missing translation * Remove default label of "Value" * Replace nullish collescing with OR * Replace nullish collescing with OR --------- Co-authored-by: Hariom Balhara <[email protected]> Co-authored-by: Udit Takkar <[email protected]>
This commit is contained in:
12 files changed
+229
-96
No files matched your search
@@ -0,0 +1,95 @@
|
||||
import { ErrorMessage } from "@hookform/error-message";
|
||||
import { useFieldArray, useFormContext } from "react-hook-form";
|
||||
|
||||
import { getEventLocationType } from "@calcom/app-store/locations";
|
||||
import type { LocationFormValues, FormValues } from "@calcom/features/eventtypes/lib/types";
|
||||
import CheckboxField from "@calcom/features/form/components/CheckboxField";
|
||||
import { useLocale } from "@calcom/lib/hooks/useLocale";
|
||||
import classNames from "@calcom/ui/classNames";
|
||||
import { TextField } from "@calcom/ui/components/form";
|
||||
|
||||
import LocationInput from "./LocationInput";
|
||||
import LocationOptionContainer from "./LocationSettingsContainer";
|
||||
import type { LocationCustomClassNames } from "./types";
|
||||
|
||||
const DefaultLocationSettings = ({
|
||||
field,
|
||||
index,
|
||||
disableLocationProp,
|
||||
customClassNames,
|
||||
}: {
|
||||
field: LocationFormValues["locations"][number];
|
||||
index: number;
|
||||
disableLocationProp?: boolean;
|
||||
customClassNames?: LocationCustomClassNames;
|
||||
}) => {
|
||||
const { t } = useLocale();
|
||||
const { getValues, control, formState } = useFormContext<FormValues>();
|
||||
const { update: updateLocationField } = useFieldArray({
|
||||
control,
|
||||
name: "locations",
|
||||
});
|
||||
const defaultLocation = field;
|
||||
const eventLocationType = getEventLocationType(field.type);
|
||||
|
||||
if (!eventLocationType) return null;
|
||||
|
||||
return (
|
||||
<LocationOptionContainer>
|
||||
<LocationInput
|
||||
label={"organizerInputLabel" in eventLocationType ? eventLocationType?.organizerInputLabel : null}
|
||||
data-testid={`${eventLocationType.type}-location-input`}
|
||||
defaultValue={defaultLocation ? defaultLocation[eventLocationType.defaultValueVariable] : undefined}
|
||||
eventLocationType={eventLocationType}
|
||||
index={index}
|
||||
customClassNames={customClassNames?.organizerContactInput?.locationInput}
|
||||
disableLocationProp={disableLocationProp}
|
||||
/>
|
||||
<ErrorMessage
|
||||
errors={formState.errors?.locations?.[index]}
|
||||
name={eventLocationType.defaultValueVariable}
|
||||
className={classNames(
|
||||
"text-error my-1 ml-6 text-sm",
|
||||
customClassNames?.organizerContactInput?.errorMessage
|
||||
)}
|
||||
as="div"
|
||||
id="location-error"
|
||||
/>
|
||||
{eventLocationType.organizerInputType && (
|
||||
<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, {
|
||||
...fieldValues,
|
||||
displayLocationPublicly: e.target.checked,
|
||||
});
|
||||
}}
|
||||
informationIconText={t("display_location_info_badge")}
|
||||
/>
|
||||
)}
|
||||
{eventLocationType?.supportsCustomLabel && (
|
||||
<TextField
|
||||
label={t("location_custom_label_input_label")}
|
||||
name={`locations[${index}].customLabel`}
|
||||
type="text"
|
||||
defaultValue={defaultLocation?.customLabel}
|
||||
onChange={(e) => {
|
||||
const fieldValues = getValues("locations")[index];
|
||||
updateLocationField(index, {
|
||||
...fieldValues,
|
||||
customLabel: e.target.value,
|
||||
});
|
||||
}}
|
||||
/>
|
||||
)}
|
||||
</LocationOptionContainer>
|
||||
);
|
||||
};
|
||||
|
||||
export default DefaultLocationSettings;
|
||||
@@ -0,0 +1,76 @@
|
||||
import { useFormContext, Controller } from "react-hook-form";
|
||||
|
||||
import type { EventLocationType } from "@calcom/app-store/locations";
|
||||
import PhoneInput from "@calcom/features/components/phone-input";
|
||||
import type { FormValues } from "@calcom/features/eventtypes/lib/types";
|
||||
import { useLocale } from "@calcom/lib/hooks/useLocale";
|
||||
import classNames from "@calcom/ui/classNames";
|
||||
import { TextField } from "@calcom/ui/components/form";
|
||||
|
||||
import type { LocationInputCustomClassNames } from "./types";
|
||||
|
||||
const LocationInput = (props: {
|
||||
eventLocationType: EventLocationType;
|
||||
defaultValue?: string;
|
||||
index: number;
|
||||
customClassNames?: LocationInputCustomClassNames;
|
||||
disableLocationProp?: boolean;
|
||||
label?: string | null;
|
||||
}) => {
|
||||
const { t } = useLocale();
|
||||
const { eventLocationType, index, customClassNames, disableLocationProp, label, ...remainingProps } = props;
|
||||
const formMethods = useFormContext<FormValues>();
|
||||
|
||||
if (eventLocationType?.organizerInputType === "text") {
|
||||
const { defaultValue, ...rest } = remainingProps;
|
||||
|
||||
return (
|
||||
<Controller
|
||||
name={`locations.${index}.${eventLocationType.defaultValueVariable}`}
|
||||
defaultValue={defaultValue}
|
||||
render={({ field: { onChange, value } }) => {
|
||||
return (
|
||||
<TextField
|
||||
label={label ? t(label) : null}
|
||||
name={`locations[${index}].${eventLocationType.defaultValueVariable}`}
|
||||
placeholder={t(eventLocationType.organizerInputPlaceholder || "")}
|
||||
type="text"
|
||||
required
|
||||
onChange={onChange}
|
||||
value={value}
|
||||
{...(disableLocationProp ? { disabled: true } : {})}
|
||||
className={classNames("my-0", customClassNames?.addressInput)}
|
||||
{...rest}
|
||||
/>
|
||||
);
|
||||
}}
|
||||
/>
|
||||
);
|
||||
} else if (eventLocationType?.organizerInputType === "phone") {
|
||||
const { defaultValue, ...rest } = remainingProps;
|
||||
|
||||
return (
|
||||
<Controller
|
||||
name={`locations.${index}.${eventLocationType.defaultValueVariable}`}
|
||||
defaultValue={defaultValue}
|
||||
render={({ field: { onChange, value } }) => {
|
||||
return (
|
||||
<PhoneInput
|
||||
required
|
||||
disabled={disableLocationProp}
|
||||
placeholder={t(eventLocationType.organizerInputPlaceholder || "")}
|
||||
name={`locations[${index}].${eventLocationType.defaultValueVariable}`}
|
||||
className={customClassNames?.phoneInput}
|
||||
value={value}
|
||||
onChange={onChange}
|
||||
{...rest}
|
||||
/>
|
||||
);
|
||||
}}
|
||||
/>
|
||||
);
|
||||
}
|
||||
return null;
|
||||
};
|
||||
|
||||
export default LocationInput;
|
||||
@@ -2,35 +2,32 @@ import { useAutoAnimate } from "@formkit/auto-animate/react";
|
||||
import { ErrorMessage } from "@hookform/error-message";
|
||||
import Link from "next/link";
|
||||
import { useEffect, useState } from "react";
|
||||
import { Controller, useFieldArray, useFormContext } from "react-hook-form";
|
||||
import { useFieldArray, useFormContext } from "react-hook-form";
|
||||
import type { UseFormGetValues, UseFormSetValue, Control, FormState } from "react-hook-form";
|
||||
|
||||
import type { EventLocationType } from "@calcom/app-store/locations";
|
||||
import { getEventLocationType, MeetLocationType } from "@calcom/app-store/locations";
|
||||
import { useIsPlatform } from "@calcom/atoms/hooks/useIsPlatform";
|
||||
import PhoneInput from "@calcom/features/components/phone-input";
|
||||
import type {
|
||||
LocationFormValues,
|
||||
EventTypeSetupProps,
|
||||
CheckboxClassNames,
|
||||
FormValues,
|
||||
} from "@calcom/features/eventtypes/lib/types";
|
||||
import CheckboxField from "@calcom/features/form/components/CheckboxField";
|
||||
import type {
|
||||
LocationSelectCustomClassNames,
|
||||
SingleValueLocationOption,
|
||||
} from "@calcom/features/form/components/LocationSelect";
|
||||
import type { SingleValueLocationOption } from "@calcom/features/form/components/LocationSelect";
|
||||
import LocationSelect from "@calcom/features/form/components/LocationSelect";
|
||||
import ServerTrans from "@calcom/lib/components/ServerTrans";
|
||||
import { WEBAPP_URL } from "@calcom/lib/constants";
|
||||
import { useLocale } from "@calcom/lib/hooks/useLocale";
|
||||
import classNames from "@calcom/ui/classNames";
|
||||
import { Button } from "@calcom/ui/components/button";
|
||||
import { Input } from "@calcom/ui/components/form";
|
||||
import { Icon } from "@calcom/ui/components/icon";
|
||||
import { showToast } from "@calcom/ui/components/toast";
|
||||
|
||||
import CalVideoSettings from "./CalVideoSettings";
|
||||
import DefaultLocationSettings from "./DefaultLocationSettings";
|
||||
import LocationInput from "./LocationInput";
|
||||
import type { LocationCustomClassNames } from "./types";
|
||||
|
||||
export type TEventTypeLocation = Pick<EventTypeSetupProps["eventType"], "locations" | "calVideoSettings">;
|
||||
export type TLocationOptions = Pick<EventTypeSetupProps, "locationOptions">["locationOptions"];
|
||||
@@ -42,19 +39,6 @@ type LocationInputCustomClassNames = {
|
||||
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;
|
||||
@@ -107,66 +91,6 @@ const getLocationInfo = ({
|
||||
return { locationAvailable, locationDetails };
|
||||
};
|
||||
|
||||
const LocationInput = (props: {
|
||||
eventLocationType: EventLocationType;
|
||||
defaultValue?: string;
|
||||
index: number;
|
||||
customClassNames?: LocationInputCustomClassNames;
|
||||
disableLocationProp?: boolean;
|
||||
}) => {
|
||||
const { t } = useLocale();
|
||||
const { eventLocationType, index, customClassNames, disableLocationProp, ...remainingProps } = props;
|
||||
if (eventLocationType?.organizerInputType === "text") {
|
||||
const { defaultValue, ...rest } = remainingProps;
|
||||
|
||||
return (
|
||||
<Controller
|
||||
name={`locations.${index}.${eventLocationType.defaultValueVariable}`}
|
||||
defaultValue={defaultValue}
|
||||
render={({ field: { onChange, value } }) => {
|
||||
return (
|
||||
<Input
|
||||
name={`locations[${index}].${eventLocationType.defaultValueVariable}`}
|
||||
placeholder={t(eventLocationType.organizerInputPlaceholder || "")}
|
||||
type="text"
|
||||
required
|
||||
onChange={onChange}
|
||||
value={value}
|
||||
{...(disableLocationProp ? { disabled: true } : {})}
|
||||
className={classNames("my-0", customClassNames?.addressInput)}
|
||||
{...rest}
|
||||
/>
|
||||
);
|
||||
}}
|
||||
/>
|
||||
);
|
||||
} else if (eventLocationType?.organizerInputType === "phone") {
|
||||
const { defaultValue, ...rest } = remainingProps;
|
||||
|
||||
return (
|
||||
<Controller
|
||||
name={`locations.${index}.${eventLocationType.defaultValueVariable}`}
|
||||
defaultValue={defaultValue}
|
||||
render={({ field: { onChange, value } }) => {
|
||||
return (
|
||||
<PhoneInput
|
||||
required
|
||||
disabled={disableLocationProp}
|
||||
placeholder={t(eventLocationType.organizerInputPlaceholder || "")}
|
||||
name={`locations[${index}].${eventLocationType.defaultValueVariable}`}
|
||||
className={customClassNames?.phoneInput}
|
||||
value={value}
|
||||
onChange={onChange}
|
||||
{...rest}
|
||||
/>
|
||||
);
|
||||
}}
|
||||
/>
|
||||
);
|
||||
}
|
||||
return null;
|
||||
};
|
||||
|
||||
const Locations: React.FC<LocationsProps> = ({
|
||||
isChildrenManagedEventType,
|
||||
disableLocationProp,
|
||||
@@ -343,7 +267,14 @@ const Locations: React.FC<LocationsProps> = ({
|
||||
|
||||
{isCalVideo && !isPlatform && <CalVideoSettings />}
|
||||
|
||||
{eventLocationType?.organizerInputType && (
|
||||
{eventLocationType?.supportsCustomLabel && eventLocationType?.type ? (
|
||||
<DefaultLocationSettings
|
||||
field={field}
|
||||
index={index}
|
||||
disableLocationProp={disableLocationProp}
|
||||
customClassNames={customClassNames}
|
||||
/>
|
||||
) : eventLocationType?.organizerInputType ? (
|
||||
<div className="mt-2 space-y-2">
|
||||
<div className="w-full">
|
||||
<div className="flex gap-2">
|
||||
@@ -397,7 +328,7 @@ const Locations: React.FC<LocationsProps> = ({
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
)}
|
||||
) : null}
|
||||
</li>
|
||||
);
|
||||
})}
|
||||
|
||||
@@ -0,0 +1,19 @@
|
||||
import type { LocationSelectCustomClassNames } from "@calcom/features/form/components/LocationSelect";
|
||||
|
||||
export type LocationCustomClassNames = {
|
||||
container?: string;
|
||||
locationSelect?: LocationSelectCustomClassNames;
|
||||
removeLocationButton?: string;
|
||||
removeLocationIcon?: string;
|
||||
addLocationButton?: string;
|
||||
organizerContactInput?: {
|
||||
errorMessage?: string;
|
||||
locationInput?: LocationInputCustomClassNames;
|
||||
publicDisplayCheckbox?: CheckboxClassNames;
|
||||
};
|
||||
};
|
||||
|
||||
export type LocationInputCustomClassNames = {
|
||||
addressInput?: string;
|
||||
phoneInput?: string;
|
||||
};
|
||||
@@ -26,8 +26,8 @@ import { Select } from "@calcom/ui/components/form";
|
||||
import { SettingsToggle } from "@calcom/ui/components/form";
|
||||
import { Skeleton } from "@calcom/ui/components/skeleton";
|
||||
|
||||
import type { LocationCustomClassNames } from "../../locations/Locations";
|
||||
import Locations from "../../locations/Locations";
|
||||
import type { LocationCustomClassNames } from "../../locations/types";
|
||||
|
||||
export type EventSetupTabCustomClassNames = {
|
||||
wrapper?: string;
|
||||
|
||||
@@ -52,6 +52,7 @@ type EventLocation = {
|
||||
hostDefault?: string;
|
||||
credentialId?: number;
|
||||
teamName?: string;
|
||||
customLabel?: string;
|
||||
};
|
||||
|
||||
type PhoneCallConfig = {
|
||||
|
||||
Reference in new issue
Block a user