feat: platform toggle calendar event creation (#21788)
* feat: add areCalendarEventsEnabled to PlatformOAuthClient table * feat: areCalendarEvents enabled in handleNewBooking and v2 * feat: v2 handle areCalendarEventsEnabled * feat: toggle areCalendarEventsEnabled on frontend * feat: enable areCalendarEventsEnabled for recurring,confirm,paid * refactor: use placeholder calendar event * remove merge conflicts * chore: bump libraries * chore: bump libraries
This commit is contained in:
1 parent
d7fd055171
commit
4a53ec0b74
33 files changed
+525
-22
No files matched your search
@@ -14,7 +14,7 @@ import sendPayload from "@calcom/features/webhooks/lib/sendOrSchedulePayload";
|
||||
import type { EventPayloadType, EventTypeInfo } from "@calcom/features/webhooks/lib/sendPayload";
|
||||
import { getVideoCallUrlFromCalEvent } from "@calcom/lib/CalEventParser";
|
||||
import type { EventManagerUser } from "@calcom/lib/EventManager";
|
||||
import EventManager from "@calcom/lib/EventManager";
|
||||
import EventManager, { placeholderCreatedEvent } from "@calcom/lib/EventManager";
|
||||
import { getBookerBaseUrl } from "@calcom/lib/getBookerUrl/server";
|
||||
import getOrgIdFromMemberOrTeamId from "@calcom/lib/getOrgIdFromMemberOrTeamId";
|
||||
import { getTeamIdFromEventType } from "@calcom/lib/getTeamIdFromEventType";
|
||||
@@ -88,7 +88,8 @@ export async function handleConfirmation(args: {
|
||||
const eventTypeMetadata = EventTypeMetaDataSchema.parse(eventType?.metadata || {});
|
||||
const apps = eventTypeAppMetadataOptionalSchema.parse(eventTypeMetadata?.apps);
|
||||
const eventManager = new EventManager(user, apps);
|
||||
const scheduleResult = await eventManager.create(evt);
|
||||
const areCalendarEventsEnabled = platformClientParams?.areCalendarEventsEnabled ?? true;
|
||||
const scheduleResult = areCalendarEventsEnabled ? await eventManager.create(evt) : placeholderCreatedEvent;
|
||||
const results = scheduleResult.results;
|
||||
const metadata: AdditionalInformation = {};
|
||||
const workflows = await getAllWorkflowsFromEventType(eventType, booking.userId);
|
||||
|
||||
@@ -43,7 +43,7 @@ import {
|
||||
scheduleTrigger,
|
||||
} from "@calcom/features/webhooks/lib/scheduleTrigger";
|
||||
import { getVideoCallUrlFromCalEvent } from "@calcom/lib/CalEventParser";
|
||||
import EventManager from "@calcom/lib/EventManager";
|
||||
import EventManager, { placeholderCreatedEvent } from "@calcom/lib/EventManager";
|
||||
import { handleAnalyticsEvents } from "@calcom/lib/analyticsManager/handleAnalyticsEvents";
|
||||
import { shouldIgnoreContactOwner } from "@calcom/lib/bookings/routing/utils";
|
||||
import { getUsernameList } from "@calcom/lib/defaultEvents";
|
||||
@@ -373,6 +373,7 @@ export type PlatformParams = {
|
||||
platformBookingUrl?: string;
|
||||
platformRescheduleUrl?: string;
|
||||
platformBookingLocation?: string;
|
||||
areCalendarEventsEnabled?: boolean;
|
||||
};
|
||||
|
||||
export type BookingHandlerInput = {
|
||||
@@ -397,6 +398,7 @@ async function handler(
|
||||
platformBookingLocation,
|
||||
hostname,
|
||||
forcedSlug,
|
||||
areCalendarEventsEnabled = true,
|
||||
} = input;
|
||||
|
||||
const isPlatformBooking = !!platformClientId;
|
||||
@@ -1737,7 +1739,7 @@ async function handler(
|
||||
// Create a booking
|
||||
} else if (isConfirmedByDefault) {
|
||||
// Use EventManager to conditionally use all needed integrations.
|
||||
const createManager = await eventManager.create(evt);
|
||||
const createManager = areCalendarEventsEnabled ? await eventManager.create(evt) : placeholderCreatedEvent;
|
||||
if (evt.location) {
|
||||
booking.location = evt.location;
|
||||
}
|
||||
|
||||
@@ -9,6 +9,7 @@ export type PlatformParams = {
|
||||
platformBookingUrl?: string;
|
||||
platformRescheduleUrl?: string;
|
||||
platformBookingLocation?: string;
|
||||
areCalendarEventsEnabled?: boolean;
|
||||
};
|
||||
|
||||
export type BookingHandlerInput = {
|
||||
@@ -45,6 +46,7 @@ export const handleNewRecurringBooking = async (input: BookingHandlerInput): Pro
|
||||
platformCancelUrl: input.platformCancelUrl,
|
||||
platformBookingUrl: input.platformBookingUrl,
|
||||
platformBookingLocation: input.platformBookingLocation,
|
||||
areCalendarEventsEnabled: input.areCalendarEventsEnabled,
|
||||
};
|
||||
|
||||
if (isRoundRobin) {
|
||||
|
||||
@@ -8,7 +8,9 @@ import { doesBookingRequireConfirmation } from "@calcom/features/bookings/lib/do
|
||||
import { getAllCredentialsIncludeServiceAccountKey } from "@calcom/features/bookings/lib/getAllCredentialsForUsersOnEvent/getAllCredentials";
|
||||
import { handleConfirmation } from "@calcom/features/bookings/lib/handleConfirmation";
|
||||
import stripe from "@calcom/features/ee/payments/server/stripe";
|
||||
import EventManager from "@calcom/lib/EventManager";
|
||||
import { getPlatformParams } from "@calcom/features/platform-oauth-client/get-platform-params";
|
||||
import { PlatformOAuthClientRepository } from "@calcom/features/platform-oauth-client/platform-oauth-client.repository";
|
||||
import EventManager, { placeholderCreatedEvent } from "@calcom/lib/EventManager";
|
||||
import { IS_PRODUCTION } from "@calcom/lib/constants";
|
||||
import { getErrorFromUnknown } from "@calcom/lib/errors";
|
||||
import { HttpError as HttpCode } from "@calcom/lib/http-error";
|
||||
@@ -80,9 +82,18 @@ const handleSetupSuccess = async (event: Stripe.Event) => {
|
||||
metadata,
|
||||
});
|
||||
|
||||
const platformOAuthClientRepository = new PlatformOAuthClientRepository();
|
||||
const platformOAuthClient = user.isPlatformManaged
|
||||
? await platformOAuthClientRepository.getByUserId(user.id)
|
||||
: null;
|
||||
const areCalendarEventsEnabled = platformOAuthClient?.areCalendarEventsEnabled ?? true;
|
||||
const areEmailsEnabled = platformOAuthClient?.areEmailsEnabled ?? true;
|
||||
|
||||
if (!requiresConfirmation) {
|
||||
const eventManager = new EventManager({ ...user, credentials: allCredentials }, metadata?.apps);
|
||||
const scheduleResult = await eventManager.create(evt);
|
||||
const scheduleResult = areCalendarEventsEnabled
|
||||
? await eventManager.create(evt)
|
||||
: placeholderCreatedEvent;
|
||||
bookingData.references = { create: scheduleResult.referencesToCreate };
|
||||
bookingData.status = BookingStatus.ACCEPTED;
|
||||
}
|
||||
@@ -114,8 +125,9 @@ const handleSetupSuccess = async (event: Stripe.Event) => {
|
||||
bookingId: booking.id,
|
||||
booking,
|
||||
paid: true,
|
||||
platformClientParams: platformOAuthClient ? getPlatformParams(platformOAuthClient) : undefined,
|
||||
});
|
||||
} else {
|
||||
} else if (areEmailsEnabled) {
|
||||
await sendOrganizerRequestEmail({ ...evt }, eventType.metadata);
|
||||
await sendAttendeeRequestEmailAndSMS({ ...evt }, evt.attendees[0], eventType.metadata);
|
||||
}
|
||||
|
||||
@@ -0,0 +1,12 @@
|
||||
import type { PlatformOAuthClient } from "@prisma/client";
|
||||
|
||||
export function getPlatformParams(platformOAuthClient: PlatformOAuthClient) {
|
||||
return {
|
||||
platformClientId: platformOAuthClient.id,
|
||||
platformCancelUrl: platformOAuthClient.bookingCancelRedirectUri,
|
||||
platformRescheduleUrl: platformOAuthClient.bookingRescheduleRedirectUri,
|
||||
platformBookingUrl: platformOAuthClient.bookingRedirectUri,
|
||||
arePlatformEmailsEnabled: platformOAuthClient.areEmailsEnabled,
|
||||
areCalendarEventsEnabled: platformOAuthClient.areCalendarEventsEnabled,
|
||||
};
|
||||
}
|
||||
@@ -0,0 +1,5 @@
|
||||
import type { PlatformOAuthClient } from "@prisma/client";
|
||||
|
||||
export interface IPlatformOAuthClientRepository {
|
||||
getByUserId(userId: number): Promise<PlatformOAuthClient | null>;
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
import { captureException } from "@sentry/nextjs";
|
||||
|
||||
import prisma from "@calcom/prisma";
|
||||
|
||||
import type { IPlatformOAuthClientRepository } from "./platform-oauth-client.repository.interface";
|
||||
|
||||
export class PlatformOAuthClientRepository implements IPlatformOAuthClientRepository {
|
||||
async getByUserId(userId: number) {
|
||||
try {
|
||||
return prisma.platformOAuthClient.findFirst({
|
||||
where: {
|
||||
users: {
|
||||
some: {
|
||||
id: userId,
|
||||
},
|
||||
},
|
||||
},
|
||||
});
|
||||
} catch (err) {
|
||||
captureException(err);
|
||||
throw err;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user