Handle booking flow for dynamic default events (#7094)
* Handle booking flow for default events * Cleanup * Update packages/lib/defaultEvents.ts * Fix naming conventions * Fix prettier error --------- Co-authored-by: zomars <[email protected]>
This commit is contained in:
1 parent
9d3540511b
commit
ea34545d72
5 files changed
+109
-9
No files matched your search
@@ -188,6 +188,10 @@ export function getAppType(name: string): string {
|
||||
return "Unknown";
|
||||
}
|
||||
|
||||
export function getAppFromSlug(slug: string | undefined): AppMeta | undefined {
|
||||
return ALL_APPS.find((app) => app.slug === slug);
|
||||
}
|
||||
|
||||
export const getEventTypeAppData = <T extends EventTypeAppsList>(
|
||||
eventType: Pick<z.infer<typeof EventTypeModel>, "price" | "currency" | "metadata">,
|
||||
appId: T,
|
||||
|
||||
@@ -19,7 +19,7 @@ import { metadata as GoogleMeetMetadata } from "@calcom/app-store/googlevideo/_m
|
||||
import { getLocationValueForDB, LocationObject } from "@calcom/app-store/locations";
|
||||
import { MeetLocationType } from "@calcom/app-store/locations";
|
||||
import { handleEthSignature } from "@calcom/app-store/rainbow/utils/ethereum";
|
||||
import { EventTypeAppsList, getEventTypeAppData } from "@calcom/app-store/utils";
|
||||
import { EventTypeAppsList, getAppFromSlug, getEventTypeAppData } from "@calcom/app-store/utils";
|
||||
import { cancelScheduledJobs, scheduleTrigger } from "@calcom/app-store/zapier/lib/nodeScheduler";
|
||||
import EventManager from "@calcom/core/EventManager";
|
||||
import { getEventName } from "@calcom/core/event";
|
||||
@@ -50,6 +50,7 @@ import {
|
||||
customInputSchema,
|
||||
EventTypeMetaDataSchema,
|
||||
extendedBookingCreateBody,
|
||||
userMetadata as userMetadataSchema,
|
||||
} from "@calcom/prisma/zod-utils";
|
||||
import type { BufferedBusyTime } from "@calcom/types/BufferedBusyTime";
|
||||
import type { AdditionalInformation, AppsStatus, CalendarEvent } from "@calcom/types/Calendar";
|
||||
@@ -376,7 +377,10 @@ async function handler(req: NextApiRequest & { userId?: number | undefined }) {
|
||||
in: dynamicUserList,
|
||||
},
|
||||
},
|
||||
...userSelect,
|
||||
select: {
|
||||
...userSelect.select,
|
||||
metadata: true,
|
||||
},
|
||||
})
|
||||
: !!eventType.hosts?.length
|
||||
? eventType.hosts.map(({ user, isFixed }) => ({
|
||||
@@ -385,7 +389,10 @@ async function handler(req: NextApiRequest & { userId?: number | undefined }) {
|
||||
}))
|
||||
: eventType.users;
|
||||
// loadUsers allows type inferring
|
||||
let users: (Awaited<ReturnType<typeof loadUsers>>[number] & { isFixed?: boolean })[] = await loadUsers();
|
||||
let users: (Awaited<ReturnType<typeof loadUsers>>[number] & {
|
||||
isFixed?: boolean;
|
||||
metadata?: Prisma.JsonValue;
|
||||
})[] = await loadUsers();
|
||||
|
||||
const isDynamicAllowed = !users.some((user) => !user.allowDynamicBooking);
|
||||
if (!isDynamicAllowed && !eventTypeId) {
|
||||
@@ -497,8 +504,21 @@ async function handler(req: NextApiRequest & { userId?: number | undefined }) {
|
||||
const seed = `${organizerUser.username}:${dayjs(reqBody.start).utc().format()}:${new Date().getTime()}`;
|
||||
const uid = translator.fromUUID(uuidv5(seed, uuidv5.URL));
|
||||
|
||||
const bookingLocation = getLocationValueForDB(reqBody.location, eventType.locations);
|
||||
let locationBodyString = reqBody.location;
|
||||
let defaultLocationUrl = undefined;
|
||||
if (dynamicUserList.length > 1) {
|
||||
users = users.sort((a, b) => {
|
||||
const aIndex = (a.username && dynamicUserList.indexOf(a.username)) || 0;
|
||||
const bIndex = (b.username && dynamicUserList.indexOf(b.username)) || 0;
|
||||
return aIndex - bIndex;
|
||||
});
|
||||
const firstUsersMetadata = userMetadataSchema.parse(users[0].metadata);
|
||||
const app = getAppFromSlug(firstUsersMetadata?.defaultConferencingApp?.appSlug);
|
||||
locationBodyString = app?.appData?.location?.type || locationBodyString;
|
||||
defaultLocationUrl = firstUsersMetadata?.defaultConferencingApp?.appLink;
|
||||
}
|
||||
|
||||
const bookingLocation = getLocationValueForDB(locationBodyString, eventType.locations);
|
||||
const customInputs = {} as NonNullable<CalendarEvent["customInputs"]>;
|
||||
|
||||
const teamMemberPromises =
|
||||
@@ -1040,7 +1060,7 @@ async function handler(req: NextApiRequest & { userId?: number | undefined }) {
|
||||
metadata.conferenceData = results[0].createdEvent?.conferenceData;
|
||||
metadata.entryPoints = results[0].createdEvent?.entryPoints;
|
||||
handleAppsStatus(results, booking);
|
||||
videoCallUrl = metadata.hangoutLink || videoCallUrl;
|
||||
videoCallUrl = metadata.hangoutLink || defaultLocationUrl || videoCallUrl;
|
||||
}
|
||||
if (noEmail !== true) {
|
||||
await sendScheduledEmails({
|
||||
|
||||
Reference in new issue
Block a user