From 10dde1bbf3d406a296598f3a47d383f18b4ddaa7 Mon Sep 17 00:00:00 2001 From: zomars Date: Tue, 1 Mar 2022 16:17:02 -0700 Subject: [PATCH] Adds getLocationOptions --- apps/web/lib/apps/utils/AppUtils.ts | 23 ++++++++++++ apps/web/pages/event-types/[type].tsx | 35 +++++++------------ packages/app-store/zoomvideo/lib/index.ts | 1 + .../app-store/zoomvideo/lib/locationOption.ts | 9 +++++ packages/lib/location.ts | 1 + 5 files changed, 46 insertions(+), 23 deletions(-) create mode 100644 packages/app-store/zoomvideo/lib/locationOption.ts diff --git a/apps/web/lib/apps/utils/AppUtils.ts b/apps/web/lib/apps/utils/AppUtils.ts index 5e914eb1f4..4ba01276e4 100644 --- a/apps/web/lib/apps/utils/AppUtils.ts +++ b/apps/web/lib/apps/utils/AppUtils.ts @@ -2,6 +2,7 @@ import { Prisma } from "@prisma/client"; import _ from "lodash"; import appStore from "@calcom/app-store"; +import { LocationType } from "@calcom/lib/location"; import type { App } from "@calcom/types/App"; import { APPS as CalendarApps } from "@lib/apps/calendar/config"; @@ -23,6 +24,28 @@ type CredentialData = Prisma.CredentialGetPayload; export const ALL_APPS = Object.values(ALL_APPS_MAP); +type OptionTypeBase = { + label: string; + value: LocationType; + disabled?: boolean; +}; + +export function getLocationOptions() { + const defaultLocations: OptionTypeBase[] = [ + { value: LocationType.InPerson, label: "in_person_meeting" }, + { value: LocationType.Jitsi, label: "Jitsi Meet" }, + { value: LocationType.Phone, label: "phone_call" }, + ]; + + Object.values(appStore).forEach((app) => { + if ("locationOption" in app.lib) { + defaultLocations.push(app.lib.locationOption); + } + }); + + return defaultLocations; +} + function getApps(userCredentials: CredentialData[]) { const apps = ALL_APPS.map((app) => { const credentials = userCredentials diff --git a/apps/web/pages/event-types/[type].tsx b/apps/web/pages/event-types/[type].tsx index 379f9b17fe..9c44fb76f3 100644 --- a/apps/web/pages/event-types/[type].tsx +++ b/apps/web/pages/event-types/[type].tsx @@ -28,7 +28,7 @@ import { JSONObject } from "superjson/dist/types"; import { StripeData } from "@ee/lib/stripe/server"; -import getApps, { hasIntegration } from "@lib/apps/utils/AppUtils"; +import getApps, { getLocationOptions, hasIntegration } from "@lib/apps/utils/AppUtils"; import { asStringOrThrow, asStringOrUndefined } from "@lib/asStringOrNull"; import { getSession } from "@lib/auth"; import { HttpError } from "@lib/core/http/error"; @@ -108,19 +108,17 @@ const EventTypePage = (props: inferSSRProps) => { prefix: t("indefinitely_into_future"), }, ]; - const { eventType, locationOptions, availability, team, teamMembers, hasPaymentIntegration, currency } = - props; - - /** Appending default locations */ - - const defaultLocations = [ - { value: LocationType.InPerson, label: t("in_person_meeting") }, - { value: LocationType.Jitsi, label: "Jitsi Meet" }, - { value: LocationType.Phone, label: t("phone_call") }, - ]; - - addDefaultLocationOptions(defaultLocations, locationOptions); + const { + eventType, + locationOptions: untraslatedLocationOptions, + availability, + team, + teamMembers, + hasPaymentIntegration, + currency, + } = props; + const locationOptions = untraslatedLocationOptions.map((l) => ({ ...l, label: t(l.label) })); const router = useRouter(); const updateMutation = trpc.useMutation("viewer.eventTypes.update", { @@ -1665,17 +1663,8 @@ export const getServerSideProps = async (context: GetServerSidePropsContext) => } const integrations = getApps(credentials); + const locationOptions = getLocationOptions(); - /** TODO: Find a way to get locations dynamically */ - const locationOptions: OptionTypeBase[] = []; - - if (hasIntegration(integrations, "zoom_video")) { - locationOptions.push({ - value: LocationType.Zoom, - label: "Zoom Video", - disabled: true, - }); - } const hasPaymentIntegration = hasIntegration(integrations, "stripe_payment"); if (hasIntegration(integrations, "google_calendar")) { locationOptions.push({ diff --git a/packages/app-store/zoomvideo/lib/index.ts b/packages/app-store/zoomvideo/lib/index.ts index dc61768d60..74e5f8f971 100644 --- a/packages/app-store/zoomvideo/lib/index.ts +++ b/packages/app-store/zoomvideo/lib/index.ts @@ -1 +1,2 @@ +export { default as locationOption } from "./locationOption"; export { default as VideoApiAdapter } from "./VideoApiAdapter"; diff --git a/packages/app-store/zoomvideo/lib/locationOption.ts b/packages/app-store/zoomvideo/lib/locationOption.ts new file mode 100644 index 0000000000..890531ec56 --- /dev/null +++ b/packages/app-store/zoomvideo/lib/locationOption.ts @@ -0,0 +1,9 @@ +import { LocationType } from "@calcom/lib/location"; + +const locationOption = { + value: LocationType.Zoom, + label: "Zoom Video", + disabled: false, +}; + +export default locationOption; diff --git a/packages/lib/location.ts b/packages/lib/location.ts index 5401d88820..cba40aa3ae 100644 --- a/packages/lib/location.ts +++ b/packages/lib/location.ts @@ -1,3 +1,4 @@ +/** TODO: These should all come from each individual App Store package, and merge them here. */ export enum LocationType { InPerson = "inPerson", Phone = "phone",