feat: add LocationSelect component (#6571)
* feat: add LocationSelect component Signed-off-by: Udit Takkar <[email protected]> * fix: type error Signed-off-by: Udit Takkar <[email protected]> * chore: type error Signed-off-by: Udit Takkar <[email protected]> Signed-off-by: Udit Takkar <[email protected]>
This commit is contained in:
1 parent
0e04f5d338
commit
5bb6904ffd
5 files changed
+103
-84
No files matched your search
@@ -10,6 +10,13 @@ import { EventTypeModel } from "@calcom/prisma/zod";
|
||||
import { EventTypeMetaDataSchema } from "@calcom/prisma/zod-utils";
|
||||
import type { App, AppMeta } from "@calcom/types/App";
|
||||
|
||||
type LocationOption = {
|
||||
label: string;
|
||||
value: EventLocationType["type"];
|
||||
icon?: string;
|
||||
disabled?: boolean;
|
||||
};
|
||||
|
||||
export type EventTypeApps = NonNullable<NonNullable<z.infer<typeof EventTypeMetaDataSchema>>["apps"]>;
|
||||
export type EventTypeAppsList = keyof EventTypeApps;
|
||||
|
||||
@@ -48,36 +55,6 @@ export const InstalledAppVariants = [
|
||||
|
||||
export const ALL_APPS = Object.values(ALL_APPS_MAP);
|
||||
|
||||
type OptionTypeBase = {
|
||||
label: string;
|
||||
value: EventLocationType["type"];
|
||||
disabled?: boolean;
|
||||
};
|
||||
|
||||
function translateLocations(locations: OptionTypeBase[], t: TFunction) {
|
||||
return locations.map((l) => ({
|
||||
...l,
|
||||
label: t(l.label),
|
||||
}));
|
||||
}
|
||||
|
||||
export function getLocationOptions(integrations: ReturnType<typeof getApps>, t: TFunction) {
|
||||
const locations: OptionTypeBase[] = [];
|
||||
defaultLocations.forEach((l) => {
|
||||
locations.push({
|
||||
label: l.label,
|
||||
value: l.type,
|
||||
});
|
||||
});
|
||||
integrations.forEach((app) => {
|
||||
if (app.locationOption) {
|
||||
locations.push(app.locationOption);
|
||||
}
|
||||
});
|
||||
|
||||
return translateLocations(locations, t);
|
||||
}
|
||||
|
||||
export function getLocationGroupedOptions(integrations: ReturnType<typeof getApps>, t: TFunction) {
|
||||
const apps: Record<string, { label: string; value: string; disabled?: boolean; icon?: string }[]> = {};
|
||||
integrations.forEach((app) => {
|
||||
@@ -147,7 +124,7 @@ export function getLocationGroupedOptions(integrations: ReturnType<typeof getApp
|
||||
function getApps(userCredentials: CredentialData[]) {
|
||||
const apps = ALL_APPS.map((appMeta) => {
|
||||
const credentials = userCredentials.filter((credential) => credential.type === appMeta.type);
|
||||
let locationOption: OptionTypeBase | null = null;
|
||||
let locationOption: LocationOption | null = null;
|
||||
|
||||
/** If the app is a globally installed one, let's inject it's key */
|
||||
if (appMeta.isGlobal) {
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import { Prisma, PrismaClient } from "@prisma/client";
|
||||
|
||||
import { StripeData } from "@calcom/app-store/stripepayment/lib/server";
|
||||
import { getEventTypeAppData, getLocationOptions } from "@calcom/app-store/utils";
|
||||
import { getEventTypeAppData, getLocationGroupedOptions } from "@calcom/app-store/utils";
|
||||
import { LocationObject } from "@calcom/core/location";
|
||||
import { parseBookingLimit, parseRecurringEvent } from "@calcom/lib";
|
||||
import getEnabledApps from "@calcom/lib/apps/getEnabledApps";
|
||||
@@ -251,7 +251,7 @@ export default async function getEventTypeById({
|
||||
const currentUser = eventType.users.find((u) => u.id === userId);
|
||||
const t = await getTranslation(currentUser?.locale ?? "en", "common");
|
||||
const integrations = await getEnabledApps(credentials);
|
||||
const locationOptions = getLocationOptions(integrations, t);
|
||||
const locationOptions = getLocationGroupedOptions(integrations, t);
|
||||
|
||||
const eventTypeObject = Object.assign({}, eventType, {
|
||||
periodStartDate: eventType.periodStartDate?.toString() ?? null,
|
||||
|
||||
Reference in new issue
Block a user