refactor: rename getEventLocationType to getLocationByType for better clarity (#28567)

* chore: rename getEventLocationType

* chore: update imports
This commit is contained in:
Anirban Singha
2026-07-09 09:22:35 +00:00
committed by GitHub
parent 761b780aa2
commit f004349273
10 changed files with 45 additions and 46 deletions
@@ -7,7 +7,7 @@ import { z } from "zod";
import type { EventLocationType, LocationObject } from "@calcom/app-store/locations";
import {
getEventLocationType,
getLocationByType,
getHumanReadableLocationValue,
getMessageForOrganizer,
isAttendeeInputRequired,
@@ -168,7 +168,7 @@ export const EditLocationDialog = (props: ISetLocationDialog) => {
name: "locationAddress",
});
const eventLocationType = getEventLocationType(selectedLocation);
const eventLocationType = getLocationByType(selectedLocation);
const defaultLocation = defaultValues?.find(
(location: { type: EventLocationType["type"]; address?: string }) => {
@@ -3,7 +3,7 @@ import type {
EventLocationTypeFromApp,
LocationObject,
} from "@calcom/app-store/locations";
import { getEventLocationType, getTranslatedLocation } from "@calcom/app-store/locations";
import { getLocationByType, getTranslatedLocation } from "@calcom/app-store/locations";
import { useIsPlatform } from "@calcom/atoms/hooks/useIsPlatform";
import { useLocale } from "@calcom/lib/hooks/useLocale";
import invertLogoOnDark from "@calcom/lib/invertLogoOnDark";
@@ -43,7 +43,7 @@ function RenderLocationTooltip({ locations }: { locations: LocationObject[] }) {
Omit<LocationObject, "link" | "address">,
index: number
) => {
const eventLocationType = getEventLocationType(location.type);
const eventLocationType = getLocationByType(location.type);
if (!eventLocationType) {
return null;
}
@@ -70,7 +70,7 @@ export function AvailableEventLocations({ locations }: { locations: LocationObje
location: Pick<Partial<LocationObject>, "link" | "address"> & Omit<LocationObject, "link" | "address">,
index: number
) => {
const eventLocationType = getEventLocationType(location.type);
const eventLocationType = getLocationByType(location.type);
if (!eventLocationType) {
// It's possible that the location app got uninstalled
return null;
@@ -1,4 +1,4 @@
import { getEventLocationType, getTranslatedLocation } from "@calcom/app-store/locations";
import { getLocationByType, getTranslatedLocation } from "@calcom/app-store/locations";
import type { BookerEvent } from "@calcom/features/bookings/types";
import { useLocale } from "@calcom/lib/hooks/useLocale";
import { Tooltip } from "@calcom/ui/components/tooltip";
@@ -13,12 +13,12 @@ export const EventLocations = ({ event }: { event: BookerEvent }) => {
if (!locations?.length) return null;
const getLocationToDisplay = (location: BookerEvent["locations"][number]) => {
const eventLocationType = getEventLocationType(location.type);
const eventLocationType = getLocationByType(location.type);
const translatedLocation = getTranslatedLocation(location, eventLocationType, t);
return translatedLocation;
};
const eventLocationType = getEventLocationType(locations[0].type);
const eventLocationType = getLocationByType(locations[0].type);
const iconUrl = locations.length > 1 || !eventLocationType?.iconUrl ? undefined : eventLocationType.iconUrl;
const icon = locations.length > 1 || !eventLocationType?.iconUrl ? "map-pin" : undefined;
@@ -44,14 +44,14 @@ export const EventLocations = ({ event }: { event: BookerEvent }) => {
<li key={`${location.type}-${index}`} className="mt-1">
<div className="flex flex-row items-center">
<img
src={getEventLocationType(location.type)?.iconUrl}
src={getLocationByType(location.type)?.iconUrl}
className={classNames(
"h-3 w-3 opacity-70 ltr:mr-[10px] rtl:ml-[10px] dark:opacity-100 ",
!getEventLocationType(location.type)?.iconUrl?.startsWith("/app-store")
!getLocationByType(location.type)?.iconUrl?.startsWith("/app-store")
? "dark:invert-[.65]"
: ""
)}
alt={`${getEventLocationType(location.type)?.label} icon`}
alt={`${getLocationByType(location.type)?.label} icon`}
/>
<span>{getLocationToDisplay(location)}</span>
</div>
@@ -1,7 +1,7 @@
import { ErrorMessage } from "@hookform/error-message";
import { useFieldArray, useFormContext } from "react-hook-form";
import { getEventLocationType } from "@calcom/app-store/locations";
import { getLocationByType } from "@calcom/app-store/locations";
import type { LocationCustomClassNames } from "@calcom/features/eventtypes/components/locations/types";
import type { LocationFormValues, FormValues } from "@calcom/features/eventtypes/lib/types";
import CheckboxField from "@calcom/features/form/components/CheckboxField";
@@ -30,7 +30,7 @@ const DefaultLocationSettings = ({
name: "locations",
});
const defaultLocation = field;
const eventLocationType = getEventLocationType(field.type);
const eventLocationType = getLocationByType(field.type);
if (!eventLocationType) return null;
@@ -10,7 +10,7 @@ import { appStoreMetadata } from "@calcom/app-store/appStoreMetaData";
import {
defaultLocations,
getAppSlugFromLocationType,
getEventLocationType,
getLocationByType,
isCalVideoLocation,
isStaticLocationType,
} from "@calcom/app-store/locations";
@@ -84,7 +84,7 @@ const filterOutBookerInputLocations = (options: TLocationOptions): TLocationOpti
.map((group) => ({
...group,
options: group.options.filter((opt) => {
const locationType = getEventLocationType(opt.value);
const locationType = getLocationByType(opt.value);
return !locationType?.attendeeInputType;
}),
}))
@@ -111,7 +111,7 @@ const LocationInputDialog = ({
initialValue = "",
}: LocationInputDialogProps) => {
const { t } = useLocale();
const eventLocationType = locationOption ? getEventLocationType(locationOption.value) : null;
const eventLocationType = locationOption ? getLocationByType(locationOption.value) : null;
const [inputValue, setInputValue] = useState(initialValue);
useEffect(() => {
@@ -211,7 +211,7 @@ const buildHostLocation = (
hostData: HostWithLocationOptions | undefined,
inputValue?: string
): HostLocation => {
const eventLocationType = getEventLocationType(locationOption.value);
const eventLocationType = getLocationByType(locationOption.value);
const credential = findHostCredential(hostData, locationOption.value);
const location: HostLocation = {
@@ -287,7 +287,7 @@ const HostLocationRow = ({
[currentLocation, hostData, locationOptions]
);
const currentLocationEventType = currentLocation ? getEventLocationType(currentLocation.type) : null;
const currentLocationEventType = currentLocation ? getLocationByType(currentLocation.type) : null;
const hasOrganizerInput = !!currentLocationEventType?.organizerInputType;
const currentLocationValue = useMemo(() => {
@@ -303,7 +303,7 @@ const HostLocationRow = ({
onLocationChange(host.userId, null);
return;
}
if (getEventLocationType(option.value)?.organizerInputType) {
if (getLocationByType(option.value)?.organizerInputType) {
setPendingLocationOption(option);
setIsDialogOpen(true);
return;
@@ -454,13 +454,13 @@ const MassApplyLocationDialog = ({ isOpen, onClose, onApply, isApplying }: MassA
const { selectedType, setSelectedType, inputValue, setInputValue, reset } = useMassApplyDialogState(isOpen);
const allLocationOptions = useMemo(() => {
return getAllLocationOptions().filter((opt) => {
const locationType = getEventLocationType(opt.value);
const locationType = getLocationByType(opt.value);
return !locationType?.attendeeInputType;
});
}, []);
const selectedOption = allLocationOptions.find((o) => o.value === selectedType);
const eventLocationType = selectedType ? getEventLocationType(selectedType) : null;
const eventLocationType = selectedType ? getLocationByType(selectedType) : null;
const needsInput = eventLocationType?.organizerInputType;
const handleClose = () => {
@@ -551,7 +551,7 @@ const MassApplyLocationDialog = ({ isOpen, onClose, onApply, isApplying }: MassA
};
type LocationInputFieldProps = {
eventLocationType: ReturnType<typeof getEventLocationType>;
eventLocationType: ReturnType<typeof getLocationByType>;
inputValue: string;
setInputValue: (value: string) => void;
};
@@ -620,7 +620,7 @@ const buildFullLocationOptions = (
const locationData = app.appData?.location;
if (!locationData || existingValues.has(locationData.type)) continue;
const locationType = getEventLocationType(locationData.type);
const locationType = getLocationByType(locationData.type);
if (locationType?.attendeeInputType) continue;
existingValues.add(locationData.type);
@@ -789,7 +789,7 @@ const useMassApplyMutation = (
});
const handleMassApply = (locationType: string, inputValue?: string) => {
const evtLocType = getEventLocationType(locationType);
const evtLocType = getLocationByType(locationType);
const link = evtLocType?.defaultValueVariable === "link" ? inputValue : undefined;
const address = evtLocType?.defaultValueVariable === "address" ? inputValue : undefined;
const phoneNumber = evtLocType?.organizerInputType === "phone" ? inputValue : undefined;
@@ -6,7 +6,7 @@ import { useFieldArray } 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 { getLocationByType, MeetLocationType } from "@calcom/app-store/locations";
import { useIsPlatform } from "@calcom/atoms/hooks/useIsPlatform";
import type { LocationCustomClassNames } from "@calcom/features/eventtypes/components/locations/types";
import type { LocationFormValues, EventTypeSetupProps } from "@calcom/features/eventtypes/lib/types";
@@ -124,7 +124,7 @@ const Locations: React.FC<LocationsProps> = ({
const validLocations =
getValues("locations")?.filter((location) => {
const eventLocation = getEventLocationType(location.type);
const eventLocation = getLocationByType(location.type);
if (!eventLocation) {
// It's possible that the location app in use got uninstalled.
return false;
@@ -169,7 +169,7 @@ const Locations: React.FC<LocationsProps> = ({
<div className={classNames("w-full", customClassNames?.container)}>
<ul ref={animationRef} className={classNames("stack-y-2")}>
{locationFields.map((field, index) => {
const eventLocationType = getEventLocationType(field.type);
const eventLocationType = getLocationByType(field.type);
const defaultLocation = field;
const isCalVideo = field.type === "integrations:daily";
@@ -195,7 +195,7 @@ const Locations: React.FC<LocationsProps> = ({
setShowEmptyLocationSelect(false);
if (e?.value) {
const newLocationType = e.value;
const eventLocationType = getEventLocationType(newLocationType);
const eventLocationType = getLocationByType(newLocationType);
if (!eventLocationType) {
return;
}
@@ -340,7 +340,7 @@ const Locations: React.FC<LocationsProps> = ({
setShowEmptyLocationSelect(false);
if (e?.value) {
const newLocationType = e.value;
const eventLocationType = getEventLocationType(newLocationType);
const eventLocationType = getLocationByType(newLocationType);
if (!eventLocationType) {
return;
}
+10 -11
View File
@@ -280,8 +280,7 @@ const locations = [...defaultLocations, ...locationsFromApps];
export const getLocationFromApp = (locationType: string) =>
locationsFromApps.find((l) => l.type === locationType);
// TODO: Rename this to getLocationByType()
export const getEventLocationType = (locationType: string | undefined | null) =>
export const getLocationByType = (locationType: string | undefined | null) =>
locations.find((l) => l.type === locationType);
const getStaticLinkLocationByValue = (value: string | undefined | null) => {
@@ -297,7 +296,7 @@ const getStaticLinkLocationByValue = (value: string | undefined | null) => {
};
export const guessEventLocationType = (locationTypeOrValue: string | undefined | null) =>
getEventLocationType(locationTypeOrValue) || getStaticLinkLocationByValue(locationTypeOrValue);
getLocationByType(locationTypeOrValue) || getStaticLinkLocationByValue(locationTypeOrValue);
export const LocationType = { ...DefaultEventLocationTypeEnum, ...AppStoreLocationType };
@@ -322,7 +321,7 @@ type PrivacyFilteredLocationObject = Optional<LocationObject, "address" | "link"
export const privacyFilteredLocations = (locations: LocationObject[]): PrivacyFilteredLocationObject[] => {
const locationsAfterPrivacyFilter = locations.map((location) => {
const eventLocationType = getEventLocationType(location.type);
const eventLocationType = getLocationByType(location.type);
if (!eventLocationType) {
logger.debug(`Couldn't find location type. App might be uninstalled: ${location.type} `);
}
@@ -372,7 +371,7 @@ export const getHumanReadableLocationValue = (
}
// Just in case linkValue is a `locationType.type`(for old bookings)
const eventLocationType = getEventLocationType(linkValue);
const eventLocationType = getLocationByType(linkValue);
const isDefault = eventLocationType?.default;
if (eventLocationType) {
// If we can find a video location based on linkValue then it means that the linkValue is something like integrations:google-meet and in that case we don't have the meeting URL to show.
@@ -384,7 +383,7 @@ export const getHumanReadableLocationValue = (
};
export const locationKeyToString = (location: LocationObject) => {
const eventLocationType = getEventLocationType(location.type);
const eventLocationType = getLocationByType(location.type);
if (!eventLocationType) {
return null;
}
@@ -418,7 +417,7 @@ export const getLocationValueForDB = (
eventLocations.forEach((location) => {
if (location.type === bookingLocationTypeOrValue) {
const eventLocationType = getEventLocationType(bookingLocationTypeOrValue);
const eventLocationType = getLocationByType(bookingLocationTypeOrValue);
conferenceCredentialId = location.credentialId;
if (!eventLocationType) {
return;
@@ -441,7 +440,7 @@ export const getLocationValueForDB = (
};
export const getEventLocationValue = (eventLocations: LocationObject[], bookingLocation: LocationObject) => {
const eventLocationType = getEventLocationType(bookingLocation?.type);
const eventLocationType = getLocationByType(bookingLocation?.type);
if (!eventLocationType) {
return "";
}
@@ -470,7 +469,7 @@ export function getSuccessPageLocationMessage(
t: TFunction,
bookingStatus?: BookingStatus
) {
const eventLocationType = getEventLocationType(location);
const eventLocationType = getLocationByType(location);
let locationToDisplay = location;
if (eventLocationType && !eventLocationType.default && eventLocationType.linkType === "dynamic") {
const isConfirmed = bookingStatus === BookingStatus.ACCEPTED;
@@ -490,7 +489,7 @@ export function getSuccessPageLocationMessage(
export const getTranslatedLocation = (
location: PrivacyFilteredLocationObject,
eventLocationType: ReturnType<typeof getEventLocationType>,
eventLocationType: ReturnType<typeof getLocationByType>,
t: TFunction
) => {
if (!eventLocationType) return null;
@@ -546,7 +545,7 @@ export const locationsResolver = (t: TFunction) => {
.superRefine((val, ctx) => {
if (val?.link) {
const link = val.link;
const eventLocationType = getEventLocationType(val.type);
const eventLocationType = getLocationByType(val.type);
if (
eventLocationType &&
!eventLocationType.default &&
@@ -4,7 +4,7 @@ import { useForm } from "react-hook-form";
import { z } from "zod";
import type { EventLocationType } from "@calcom/app-store/locations";
import { getEventLocationType } from "@calcom/app-store/locations";
import { getLocationByType } from "@calcom/app-store/locations";
import { Dialog } from "@calcom/features/components/controlled-dialog";
import { useLocale } from "@calcom/lib/hooks/useLocale";
import { Button } from "@calcom/ui/components/button";
@@ -37,7 +37,7 @@ export function AppSetDefaultLinkDialog({
handleUpdateUserDefaultConferencingApp: (params: UpdateUsersDefaultConferencingAppParams) => void;
}) {
const { t } = useLocale();
const eventLocationTypeOptions = getEventLocationType(locationType.type);
const eventLocationTypeOptions = getLocationByType(locationType.type);
const form = useForm<LocationTypeSetLinkDialogFormProps>({
resolver: zodResolver(
@@ -1,6 +1,6 @@
import type { LocationObject } from "@calcom/app-store/locations";
import { locationKeyToString } from "@calcom/app-store/locations";
import { getEventLocationType } from "@calcom/app-store/locations";
import { getLocationByType } from "@calcom/app-store/locations";
import { getTranslatedLocation } from "@calcom/app-store/locations";
import type { useLocale } from "@calcom/lib/hooks/useLocale";
import notEmpty from "@calcom/lib/notEmpty";
@@ -11,7 +11,7 @@ export default function getLocationsOptionsForSelect(
) {
return locations
.map((location) => {
const eventLocation = getEventLocationType(location.type);
const eventLocation = getLocationByType(location.type);
const locationString = locationKeyToString(location);
if (typeof locationString !== "string" || !eventLocation) {
@@ -1,5 +1,5 @@
import { getUsersCredentialsIncludeServiceAccountKey } from "@calcom/app-store/delegationCredential";
import { getEventLocationType, OrganizerDefaultConferencingAppType } from "@calcom/app-store/locations";
import { getLocationByType, OrganizerDefaultConferencingAppType } from "@calcom/app-store/locations";
import { getAppFromSlug } from "@calcom/app-store/utils";
import { sendLocationChangeEmailsAndSMS } from "@calcom/emails/email-manager";
import EventManager from "@calcom/features/bookings/lib/EventManager";
@@ -243,7 +243,7 @@ export function getLocationForOrganizerDefaultConferencingAppInEvtFormat({
}
const location = defaultConferencingAppLocationType;
const locationType = getEventLocationType(location);
const locationType = getLocationByType(location);
if (!locationType) {
throw new SystemError(`Location type not found: ${location}`);
}