Skip to content

Commit f004349

Browse files
refactor: rename getEventLocationType to getLocationByType for better clarity (calcom#28567)
* chore: rename getEventLocationType * chore: update imports
1 parent 761b780 commit f004349

10 files changed

Lines changed: 45 additions & 46 deletions

File tree

apps/web/components/dialog/EditLocationDialog.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import { z } from "zod";
77

88
import type { EventLocationType, LocationObject } from "@calcom/app-store/locations";
99
import {
10-
getEventLocationType,
10+
getLocationByType,
1111
getHumanReadableLocationValue,
1212
getMessageForOrganizer,
1313
isAttendeeInputRequired,
@@ -168,7 +168,7 @@ export const EditLocationDialog = (props: ISetLocationDialog) => {
168168
name: "locationAddress",
169169
});
170170

171-
const eventLocationType = getEventLocationType(selectedLocation);
171+
const eventLocationType = getLocationByType(selectedLocation);
172172

173173
const defaultLocation = defaultValues?.find(
174174
(location: { type: EventLocationType["type"]; address?: string }) => {

apps/web/modules/bookings/components/event-meta/AvailableEventLocations.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import type {
33
EventLocationTypeFromApp,
44
LocationObject,
55
} from "@calcom/app-store/locations";
6-
import { getEventLocationType, getTranslatedLocation } from "@calcom/app-store/locations";
6+
import { getLocationByType, getTranslatedLocation } from "@calcom/app-store/locations";
77
import { useIsPlatform } from "@calcom/atoms/hooks/useIsPlatform";
88
import { useLocale } from "@calcom/lib/hooks/useLocale";
99
import invertLogoOnDark from "@calcom/lib/invertLogoOnDark";
@@ -43,7 +43,7 @@ function RenderLocationTooltip({ locations }: { locations: LocationObject[] }) {
4343
Omit<LocationObject, "link" | "address">,
4444
index: number
4545
) => {
46-
const eventLocationType = getEventLocationType(location.type);
46+
const eventLocationType = getLocationByType(location.type);
4747
if (!eventLocationType) {
4848
return null;
4949
}
@@ -70,7 +70,7 @@ export function AvailableEventLocations({ locations }: { locations: LocationObje
7070
location: Pick<Partial<LocationObject>, "link" | "address"> & Omit<LocationObject, "link" | "address">,
7171
index: number
7272
) => {
73-
const eventLocationType = getEventLocationType(location.type);
73+
const eventLocationType = getLocationByType(location.type);
7474
if (!eventLocationType) {
7575
// It's possible that the location app got uninstalled
7676
return null;

apps/web/modules/bookings/components/event-meta/Locations.tsx

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { getEventLocationType, getTranslatedLocation } from "@calcom/app-store/locations";
1+
import { getLocationByType, getTranslatedLocation } from "@calcom/app-store/locations";
22
import type { BookerEvent } from "@calcom/features/bookings/types";
33
import { useLocale } from "@calcom/lib/hooks/useLocale";
44
import { Tooltip } from "@calcom/ui/components/tooltip";
@@ -13,12 +13,12 @@ export const EventLocations = ({ event }: { event: BookerEvent }) => {
1313
if (!locations?.length) return null;
1414

1515
const getLocationToDisplay = (location: BookerEvent["locations"][number]) => {
16-
const eventLocationType = getEventLocationType(location.type);
16+
const eventLocationType = getLocationByType(location.type);
1717
const translatedLocation = getTranslatedLocation(location, eventLocationType, t);
1818

1919
return translatedLocation;
2020
};
21-
const eventLocationType = getEventLocationType(locations[0].type);
21+
const eventLocationType = getLocationByType(locations[0].type);
2222
const iconUrl = locations.length > 1 || !eventLocationType?.iconUrl ? undefined : eventLocationType.iconUrl;
2323
const icon = locations.length > 1 || !eventLocationType?.iconUrl ? "map-pin" : undefined;
2424

@@ -44,14 +44,14 @@ export const EventLocations = ({ event }: { event: BookerEvent }) => {
4444
<li key={`${location.type}-${index}`} className="mt-1">
4545
<div className="flex flex-row items-center">
4646
<img
47-
src={getEventLocationType(location.type)?.iconUrl}
47+
src={getLocationByType(location.type)?.iconUrl}
4848
className={classNames(
4949
"h-3 w-3 opacity-70 ltr:mr-[10px] rtl:ml-[10px] dark:opacity-100 ",
50-
!getEventLocationType(location.type)?.iconUrl?.startsWith("/app-store")
50+
!getLocationByType(location.type)?.iconUrl?.startsWith("/app-store")
5151
? "dark:invert-[.65]"
5252
: ""
5353
)}
54-
alt={`${getEventLocationType(location.type)?.label} icon`}
54+
alt={`${getLocationByType(location.type)?.label} icon`}
5555
/>
5656
<span>{getLocationToDisplay(location)}</span>
5757
</div>

apps/web/modules/event-types/components/locations/DefaultLocationSettings.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { ErrorMessage } from "@hookform/error-message";
22
import { useFieldArray, useFormContext } from "react-hook-form";
33

4-
import { getEventLocationType } from "@calcom/app-store/locations";
4+
import { getLocationByType } from "@calcom/app-store/locations";
55
import type { LocationCustomClassNames } from "@calcom/features/eventtypes/components/locations/types";
66
import type { LocationFormValues, FormValues } from "@calcom/features/eventtypes/lib/types";
77
import CheckboxField from "@calcom/features/form/components/CheckboxField";
@@ -30,7 +30,7 @@ const DefaultLocationSettings = ({
3030
name: "locations",
3131
});
3232
const defaultLocation = field;
33-
const eventLocationType = getEventLocationType(field.type);
33+
const eventLocationType = getLocationByType(field.type);
3434

3535
if (!eventLocationType) return null;
3636

apps/web/modules/event-types/components/locations/HostLocations.tsx

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import { appStoreMetadata } from "@calcom/app-store/appStoreMetaData";
1010
import {
1111
defaultLocations,
1212
getAppSlugFromLocationType,
13-
getEventLocationType,
13+
getLocationByType,
1414
isCalVideoLocation,
1515
isStaticLocationType,
1616
} from "@calcom/app-store/locations";
@@ -84,7 +84,7 @@ const filterOutBookerInputLocations = (options: TLocationOptions): TLocationOpti
8484
.map((group) => ({
8585
...group,
8686
options: group.options.filter((opt) => {
87-
const locationType = getEventLocationType(opt.value);
87+
const locationType = getLocationByType(opt.value);
8888
return !locationType?.attendeeInputType;
8989
}),
9090
}))
@@ -111,7 +111,7 @@ const LocationInputDialog = ({
111111
initialValue = "",
112112
}: LocationInputDialogProps) => {
113113
const { t } = useLocale();
114-
const eventLocationType = locationOption ? getEventLocationType(locationOption.value) : null;
114+
const eventLocationType = locationOption ? getLocationByType(locationOption.value) : null;
115115
const [inputValue, setInputValue] = useState(initialValue);
116116

117117
useEffect(() => {
@@ -211,7 +211,7 @@ const buildHostLocation = (
211211
hostData: HostWithLocationOptions | undefined,
212212
inputValue?: string
213213
): HostLocation => {
214-
const eventLocationType = getEventLocationType(locationOption.value);
214+
const eventLocationType = getLocationByType(locationOption.value);
215215
const credential = findHostCredential(hostData, locationOption.value);
216216

217217
const location: HostLocation = {
@@ -287,7 +287,7 @@ const HostLocationRow = ({
287287
[currentLocation, hostData, locationOptions]
288288
);
289289

290-
const currentLocationEventType = currentLocation ? getEventLocationType(currentLocation.type) : null;
290+
const currentLocationEventType = currentLocation ? getLocationByType(currentLocation.type) : null;
291291
const hasOrganizerInput = !!currentLocationEventType?.organizerInputType;
292292

293293
const currentLocationValue = useMemo(() => {
@@ -303,7 +303,7 @@ const HostLocationRow = ({
303303
onLocationChange(host.userId, null);
304304
return;
305305
}
306-
if (getEventLocationType(option.value)?.organizerInputType) {
306+
if (getLocationByType(option.value)?.organizerInputType) {
307307
setPendingLocationOption(option);
308308
setIsDialogOpen(true);
309309
return;
@@ -454,13 +454,13 @@ const MassApplyLocationDialog = ({ isOpen, onClose, onApply, isApplying }: MassA
454454
const { selectedType, setSelectedType, inputValue, setInputValue, reset } = useMassApplyDialogState(isOpen);
455455
const allLocationOptions = useMemo(() => {
456456
return getAllLocationOptions().filter((opt) => {
457-
const locationType = getEventLocationType(opt.value);
457+
const locationType = getLocationByType(opt.value);
458458
return !locationType?.attendeeInputType;
459459
});
460460
}, []);
461461

462462
const selectedOption = allLocationOptions.find((o) => o.value === selectedType);
463-
const eventLocationType = selectedType ? getEventLocationType(selectedType) : null;
463+
const eventLocationType = selectedType ? getLocationByType(selectedType) : null;
464464
const needsInput = eventLocationType?.organizerInputType;
465465

466466
const handleClose = () => {
@@ -551,7 +551,7 @@ const MassApplyLocationDialog = ({ isOpen, onClose, onApply, isApplying }: MassA
551551
};
552552

553553
type LocationInputFieldProps = {
554-
eventLocationType: ReturnType<typeof getEventLocationType>;
554+
eventLocationType: ReturnType<typeof getLocationByType>;
555555
inputValue: string;
556556
setInputValue: (value: string) => void;
557557
};
@@ -620,7 +620,7 @@ const buildFullLocationOptions = (
620620
const locationData = app.appData?.location;
621621
if (!locationData || existingValues.has(locationData.type)) continue;
622622

623-
const locationType = getEventLocationType(locationData.type);
623+
const locationType = getLocationByType(locationData.type);
624624
if (locationType?.attendeeInputType) continue;
625625

626626
existingValues.add(locationData.type);
@@ -789,7 +789,7 @@ const useMassApplyMutation = (
789789
});
790790

791791
const handleMassApply = (locationType: string, inputValue?: string) => {
792-
const evtLocType = getEventLocationType(locationType);
792+
const evtLocType = getLocationByType(locationType);
793793
const link = evtLocType?.defaultValueVariable === "link" ? inputValue : undefined;
794794
const address = evtLocType?.defaultValueVariable === "address" ? inputValue : undefined;
795795
const phoneNumber = evtLocType?.organizerInputType === "phone" ? inputValue : undefined;

apps/web/modules/event-types/components/locations/Locations.tsx

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import { useFieldArray } from "react-hook-form";
66
import type { UseFormGetValues, UseFormSetValue, Control, FormState } from "react-hook-form";
77

88
import type { EventLocationType } from "@calcom/app-store/locations";
9-
import { getEventLocationType, MeetLocationType } from "@calcom/app-store/locations";
9+
import { getLocationByType, MeetLocationType } from "@calcom/app-store/locations";
1010
import { useIsPlatform } from "@calcom/atoms/hooks/useIsPlatform";
1111
import type { LocationCustomClassNames } from "@calcom/features/eventtypes/components/locations/types";
1212
import type { LocationFormValues, EventTypeSetupProps } from "@calcom/features/eventtypes/lib/types";
@@ -124,7 +124,7 @@ const Locations: React.FC<LocationsProps> = ({
124124

125125
const validLocations =
126126
getValues("locations")?.filter((location) => {
127-
const eventLocation = getEventLocationType(location.type);
127+
const eventLocation = getLocationByType(location.type);
128128
if (!eventLocation) {
129129
// It's possible that the location app in use got uninstalled.
130130
return false;
@@ -169,7 +169,7 @@ const Locations: React.FC<LocationsProps> = ({
169169
<div className={classNames("w-full", customClassNames?.container)}>
170170
<ul ref={animationRef} className={classNames("stack-y-2")}>
171171
{locationFields.map((field, index) => {
172-
const eventLocationType = getEventLocationType(field.type);
172+
const eventLocationType = getLocationByType(field.type);
173173
const defaultLocation = field;
174174

175175
const isCalVideo = field.type === "integrations:daily";
@@ -195,7 +195,7 @@ const Locations: React.FC<LocationsProps> = ({
195195
setShowEmptyLocationSelect(false);
196196
if (e?.value) {
197197
const newLocationType = e.value;
198-
const eventLocationType = getEventLocationType(newLocationType);
198+
const eventLocationType = getLocationByType(newLocationType);
199199
if (!eventLocationType) {
200200
return;
201201
}
@@ -340,7 +340,7 @@ const Locations: React.FC<LocationsProps> = ({
340340
setShowEmptyLocationSelect(false);
341341
if (e?.value) {
342342
const newLocationType = e.value;
343-
const eventLocationType = getEventLocationType(newLocationType);
343+
const eventLocationType = getLocationByType(newLocationType);
344344
if (!eventLocationType) {
345345
return;
346346
}

packages/app-store/locations.ts

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -280,8 +280,7 @@ const locations = [...defaultLocations, ...locationsFromApps];
280280
export const getLocationFromApp = (locationType: string) =>
281281
locationsFromApps.find((l) => l.type === locationType);
282282

283-
// TODO: Rename this to getLocationByType()
284-
export const getEventLocationType = (locationType: string | undefined | null) =>
283+
export const getLocationByType = (locationType: string | undefined | null) =>
285284
locations.find((l) => l.type === locationType);
286285

287286
const getStaticLinkLocationByValue = (value: string | undefined | null) => {
@@ -297,7 +296,7 @@ const getStaticLinkLocationByValue = (value: string | undefined | null) => {
297296
};
298297

299298
export const guessEventLocationType = (locationTypeOrValue: string | undefined | null) =>
300-
getEventLocationType(locationTypeOrValue) || getStaticLinkLocationByValue(locationTypeOrValue);
299+
getLocationByType(locationTypeOrValue) || getStaticLinkLocationByValue(locationTypeOrValue);
301300

302301
export const LocationType = { ...DefaultEventLocationTypeEnum, ...AppStoreLocationType };
303302

@@ -322,7 +321,7 @@ type PrivacyFilteredLocationObject = Optional<LocationObject, "address" | "link"
322321

323322
export const privacyFilteredLocations = (locations: LocationObject[]): PrivacyFilteredLocationObject[] => {
324323
const locationsAfterPrivacyFilter = locations.map((location) => {
325-
const eventLocationType = getEventLocationType(location.type);
324+
const eventLocationType = getLocationByType(location.type);
326325
if (!eventLocationType) {
327326
logger.debug(`Couldn't find location type. App might be uninstalled: ${location.type} `);
328327
}
@@ -372,7 +371,7 @@ export const getHumanReadableLocationValue = (
372371
}
373372

374373
// Just in case linkValue is a `locationType.type`(for old bookings)
375-
const eventLocationType = getEventLocationType(linkValue);
374+
const eventLocationType = getLocationByType(linkValue);
376375
const isDefault = eventLocationType?.default;
377376
if (eventLocationType) {
378377
// 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 = (
384383
};
385384

386385
export const locationKeyToString = (location: LocationObject) => {
387-
const eventLocationType = getEventLocationType(location.type);
386+
const eventLocationType = getLocationByType(location.type);
388387
if (!eventLocationType) {
389388
return null;
390389
}
@@ -418,7 +417,7 @@ export const getLocationValueForDB = (
418417

419418
eventLocations.forEach((location) => {
420419
if (location.type === bookingLocationTypeOrValue) {
421-
const eventLocationType = getEventLocationType(bookingLocationTypeOrValue);
420+
const eventLocationType = getLocationByType(bookingLocationTypeOrValue);
422421
conferenceCredentialId = location.credentialId;
423422
if (!eventLocationType) {
424423
return;
@@ -441,7 +440,7 @@ export const getLocationValueForDB = (
441440
};
442441

443442
export const getEventLocationValue = (eventLocations: LocationObject[], bookingLocation: LocationObject) => {
444-
const eventLocationType = getEventLocationType(bookingLocation?.type);
443+
const eventLocationType = getLocationByType(bookingLocation?.type);
445444
if (!eventLocationType) {
446445
return "";
447446
}
@@ -470,7 +469,7 @@ export function getSuccessPageLocationMessage(
470469
t: TFunction,
471470
bookingStatus?: BookingStatus
472471
) {
473-
const eventLocationType = getEventLocationType(location);
472+
const eventLocationType = getLocationByType(location);
474473
let locationToDisplay = location;
475474
if (eventLocationType && !eventLocationType.default && eventLocationType.linkType === "dynamic") {
476475
const isConfirmed = bookingStatus === BookingStatus.ACCEPTED;
@@ -490,7 +489,7 @@ export function getSuccessPageLocationMessage(
490489

491490
export const getTranslatedLocation = (
492491
location: PrivacyFilteredLocationObject,
493-
eventLocationType: ReturnType<typeof getEventLocationType>,
492+
eventLocationType: ReturnType<typeof getLocationByType>,
494493
t: TFunction
495494
) => {
496495
if (!eventLocationType) return null;
@@ -546,7 +545,7 @@ export const locationsResolver = (t: TFunction) => {
546545
.superRefine((val, ctx) => {
547546
if (val?.link) {
548547
const link = val.link;
549-
const eventLocationType = getEventLocationType(val.type);
548+
const eventLocationType = getLocationByType(val.type);
550549
if (
551550
eventLocationType &&
552551
!eventLocationType.default &&

packages/features/apps/components/AppSetDefaultLinkDialog.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import { useForm } from "react-hook-form";
44
import { z } from "zod";
55

66
import type { EventLocationType } from "@calcom/app-store/locations";
7-
import { getEventLocationType } from "@calcom/app-store/locations";
7+
import { getLocationByType } from "@calcom/app-store/locations";
88
import { Dialog } from "@calcom/features/components/controlled-dialog";
99
import { useLocale } from "@calcom/lib/hooks/useLocale";
1010
import { Button } from "@calcom/ui/components/button";
@@ -37,7 +37,7 @@ export function AppSetDefaultLinkDialog({
3737
handleUpdateUserDefaultConferencingApp: (params: UpdateUsersDefaultConferencingAppParams) => void;
3838
}) {
3939
const { t } = useLocale();
40-
const eventLocationTypeOptions = getEventLocationType(locationType.type);
40+
const eventLocationTypeOptions = getLocationByType(locationType.type);
4141

4242
const form = useForm<LocationTypeSetLinkDialogFormProps>({
4343
resolver: zodResolver(

packages/features/bookings/lib/getLocationOptionsForSelect.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import type { LocationObject } from "@calcom/app-store/locations";
22
import { locationKeyToString } from "@calcom/app-store/locations";
3-
import { getEventLocationType } from "@calcom/app-store/locations";
3+
import { getLocationByType } from "@calcom/app-store/locations";
44
import { getTranslatedLocation } from "@calcom/app-store/locations";
55
import type { useLocale } from "@calcom/lib/hooks/useLocale";
66
import notEmpty from "@calcom/lib/notEmpty";
@@ -11,7 +11,7 @@ export default function getLocationsOptionsForSelect(
1111
) {
1212
return locations
1313
.map((location) => {
14-
const eventLocation = getEventLocationType(location.type);
14+
const eventLocation = getLocationByType(location.type);
1515
const locationString = locationKeyToString(location);
1616

1717
if (typeof locationString !== "string" || !eventLocation) {

packages/trpc/server/routers/viewer/bookings/editLocation.handler.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { getUsersCredentialsIncludeServiceAccountKey } from "@calcom/app-store/delegationCredential";
2-
import { getEventLocationType, OrganizerDefaultConferencingAppType } from "@calcom/app-store/locations";
2+
import { getLocationByType, OrganizerDefaultConferencingAppType } from "@calcom/app-store/locations";
33
import { getAppFromSlug } from "@calcom/app-store/utils";
44
import { sendLocationChangeEmailsAndSMS } from "@calcom/emails/email-manager";
55
import EventManager from "@calcom/features/bookings/lib/EventManager";
@@ -243,7 +243,7 @@ export function getLocationForOrganizerDefaultConferencingAppInEvtFormat({
243243
}
244244

245245
const location = defaultConferencingAppLocationType;
246-
const locationType = getEventLocationType(location);
246+
const locationType = getLocationByType(location);
247247
if (!locationType) {
248248
throw new SystemError(`Location type not found: ${location}`);
249249
}

0 commit comments

Comments
 (0)