diff --git a/apps/web/components/dialog/EditLocationDialog.tsx b/apps/web/components/dialog/EditLocationDialog.tsx index 9b95ebdc15..3e05262027 100644 --- a/apps/web/components/dialog/EditLocationDialog.tsx +++ b/apps/web/components/dialog/EditLocationDialog.tsx @@ -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 }) => { diff --git a/apps/web/modules/bookings/components/event-meta/AvailableEventLocations.tsx b/apps/web/modules/bookings/components/event-meta/AvailableEventLocations.tsx index 1e349ee231..36b991dd36 100644 --- a/apps/web/modules/bookings/components/event-meta/AvailableEventLocations.tsx +++ b/apps/web/modules/bookings/components/event-meta/AvailableEventLocations.tsx @@ -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, 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, "link" | "address"> & Omit, 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; diff --git a/apps/web/modules/bookings/components/event-meta/Locations.tsx b/apps/web/modules/bookings/components/event-meta/Locations.tsx index 3c344a4b7e..d421ae374d 100644 --- a/apps/web/modules/bookings/components/event-meta/Locations.tsx +++ b/apps/web/modules/bookings/components/event-meta/Locations.tsx @@ -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 }) => {
  • {`${getEventLocationType(location.type)?.label} {getLocationToDisplay(location)}
    diff --git a/apps/web/modules/event-types/components/locations/DefaultLocationSettings.tsx b/apps/web/modules/event-types/components/locations/DefaultLocationSettings.tsx index 0b21a47b46..8364136823 100644 --- a/apps/web/modules/event-types/components/locations/DefaultLocationSettings.tsx +++ b/apps/web/modules/event-types/components/locations/DefaultLocationSettings.tsx @@ -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; diff --git a/apps/web/modules/event-types/components/locations/HostLocations.tsx b/apps/web/modules/event-types/components/locations/HostLocations.tsx index 86de74e4d5..fe211c4d8e 100644 --- a/apps/web/modules/event-types/components/locations/HostLocations.tsx +++ b/apps/web/modules/event-types/components/locations/HostLocations.tsx @@ -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; + eventLocationType: ReturnType; 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; diff --git a/apps/web/modules/event-types/components/locations/Locations.tsx b/apps/web/modules/event-types/components/locations/Locations.tsx index 359c946558..920e764bdb 100644 --- a/apps/web/modules/event-types/components/locations/Locations.tsx +++ b/apps/web/modules/event-types/components/locations/Locations.tsx @@ -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 = ({ 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 = ({
      {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 = ({ 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 = ({ setShowEmptyLocationSelect(false); if (e?.value) { const newLocationType = e.value; - const eventLocationType = getEventLocationType(newLocationType); + const eventLocationType = getLocationByType(newLocationType); if (!eventLocationType) { return; } diff --git a/packages/app-store/locations.ts b/packages/app-store/locations.ts index 8d60b58034..7c0b55ccde 100644 --- a/packages/app-store/locations.ts +++ b/packages/app-store/locations.ts @@ -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 { 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, + eventLocationType: ReturnType, 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 && diff --git a/packages/features/apps/components/AppSetDefaultLinkDialog.tsx b/packages/features/apps/components/AppSetDefaultLinkDialog.tsx index e4f501c742..bc8da5cc9d 100644 --- a/packages/features/apps/components/AppSetDefaultLinkDialog.tsx +++ b/packages/features/apps/components/AppSetDefaultLinkDialog.tsx @@ -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({ resolver: zodResolver( diff --git a/packages/features/bookings/lib/getLocationOptionsForSelect.ts b/packages/features/bookings/lib/getLocationOptionsForSelect.ts index 00c6f6cac2..703604e751 100644 --- a/packages/features/bookings/lib/getLocationOptionsForSelect.ts +++ b/packages/features/bookings/lib/getLocationOptionsForSelect.ts @@ -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) { diff --git a/packages/trpc/server/routers/viewer/bookings/editLocation.handler.ts b/packages/trpc/server/routers/viewer/bookings/editLocation.handler.ts index 1565fffd70..cbee96442f 100644 --- a/packages/trpc/server/routers/viewer/bookings/editLocation.handler.ts +++ b/packages/trpc/server/routers/viewer/bookings/editLocation.handler.ts @@ -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}`); }