fix: hide cal branding on platform workflows (#27385)
* fix: hide cal branding on platform workflows * refactor: rely on existing with platform variables code * revert: comment * fix e2e * chore: remove unit results
This commit is contained in:
1 parent
f66fffd13b
commit
edf9cd70dd
9 files changed
+90
-32
No files matched your search
@@ -2615,7 +2615,7 @@ async function handler(
|
||||
workflows,
|
||||
smsReminderNumber: smsReminderNumber || null,
|
||||
calendarEvent: calendarEventForWorkflow,
|
||||
hideBranding: !!eventType.owner?.hideBranding,
|
||||
hideBranding: !!eventType.owner?.hideBranding || !!platformClientId,
|
||||
seatReferenceUid: evt.attendeeSeatId,
|
||||
isDryRun,
|
||||
triggers: [WorkflowTriggerEvents.BOOKING_PAYMENT_INITIATED],
|
||||
@@ -2790,7 +2790,7 @@ async function handler(
|
||||
evt: evtWithMetadata,
|
||||
workflows,
|
||||
requiresConfirmation: !isConfirmedByDefault,
|
||||
hideBranding: !!eventType.owner?.hideBranding,
|
||||
hideBranding: !!eventType.owner?.hideBranding || !!platformClientId,
|
||||
seatReferenceUid: evt.attendeeSeatId,
|
||||
isPlatformNoEmail: noEmail && Boolean(platformClientId),
|
||||
isDryRun,
|
||||
@@ -2805,7 +2805,7 @@ async function handler(
|
||||
workflows,
|
||||
smsReminderNumber: smsReminderNumber || null,
|
||||
calendarEvent: evtWithMetadata,
|
||||
hideBranding: !!eventType.owner?.hideBranding,
|
||||
hideBranding: !!eventType.owner?.hideBranding || !!platformClientId,
|
||||
seatReferenceUid: evt.attendeeSeatId,
|
||||
isDryRun,
|
||||
isConfirmedByDefault,
|
||||
|
||||
@@ -36,7 +36,7 @@ import customTemplate from "../lib/reminders/templates/customTemplate";
|
||||
import emailRatingTemplate from "../lib/reminders/templates/emailRatingTemplate";
|
||||
import emailReminderTemplate from "../lib/reminders/templates/emailReminderTemplate";
|
||||
|
||||
export async function handler(req: NextRequest) {
|
||||
async function handler(req: NextRequest) {
|
||||
const apiKey = req.headers.get("authorization") || req.nextUrl.searchParams.get("apiKey");
|
||||
|
||||
if (process.env.CRON_API_KEY !== apiKey) {
|
||||
@@ -243,9 +243,7 @@ export async function handler(req: NextRequest) {
|
||||
eventEndTimeInAttendeeTimezone: dayjs(reminder.booking?.endTime).tz(targetAttendee?.timeZone),
|
||||
};
|
||||
const emailLocale = locale || "en";
|
||||
const brandingDisabled = reminder.booking.eventType?.team
|
||||
? !!reminder.booking.eventType?.team?.hideBranding
|
||||
: !!reminder.booking.user?.hideBranding;
|
||||
const brandingDisabled = shouldHideBranding(reminder.booking);
|
||||
|
||||
const emailSubject = customTemplate(
|
||||
reminder.workflowStep.emailSubject || "",
|
||||
@@ -271,9 +269,7 @@ export async function handler(req: NextRequest) {
|
||||
getTimeFormatStringFromUserTimeFormat(reminder.booking.user?.timeFormat)
|
||||
).text.length === 0;
|
||||
} else if (reminder.workflowStep.template === WorkflowTemplates.REMINDER) {
|
||||
const brandingDisabled = reminder.booking.eventType?.team
|
||||
? !!reminder.booking.eventType?.team?.hideBranding
|
||||
: !!reminder.booking.user?.hideBranding;
|
||||
const brandingDisabled = shouldHideBranding(reminder.booking);
|
||||
emailContent = emailReminderTemplate({
|
||||
isEditingMode: false,
|
||||
locale: reminder.booking.user?.locale || "en",
|
||||
@@ -301,6 +297,7 @@ export async function handler(req: NextRequest) {
|
||||
const bookerUrl = await getBookerBaseUrl(
|
||||
reminder.booking.eventType?.team?.parentId ?? organizerOrganizationId ?? null
|
||||
);
|
||||
const brandingDisabled = shouldHideBranding(reminder.booking);
|
||||
emailContent = emailRatingTemplate({
|
||||
isEditingMode: true,
|
||||
locale: reminder.booking.user?.locale || "en",
|
||||
@@ -313,6 +310,7 @@ export async function handler(req: NextRequest) {
|
||||
timeZone: timeZone || "",
|
||||
organizer: reminder.booking.user?.name || "",
|
||||
name: name || "",
|
||||
isBrandingDisabled: brandingDisabled,
|
||||
ratingUrl: `${bookerUrl}/booking/${reminder.booking.uid}?rating`,
|
||||
noShowUrl: `${bookerUrl}/booking/${reminder.booking.uid}?noShow=true`,
|
||||
});
|
||||
@@ -430,9 +428,7 @@ export async function handler(req: NextRequest) {
|
||||
|
||||
const emailBodyEmpty = false;
|
||||
|
||||
const brandingDisabled = reminder.booking.eventType?.team
|
||||
? !!reminder.booking.eventType?.team?.hideBranding
|
||||
: !!reminder.booking.user?.hideBranding;
|
||||
const brandingDisabled = shouldHideBranding(reminder.booking);
|
||||
|
||||
emailContent = emailReminderTemplate({
|
||||
isEditingMode: false,
|
||||
@@ -516,3 +512,23 @@ export async function handler(req: NextRequest) {
|
||||
|
||||
return NextResponse.json({ message: `${unscheduledReminders.length} Emails to schedule` }, { status: 200 });
|
||||
}
|
||||
|
||||
function shouldHideBranding(booking: {
|
||||
metadata: unknown;
|
||||
eventType?: { team?: { hideBranding?: boolean } | null } | null;
|
||||
user?: { hideBranding?: boolean } | null;
|
||||
}): boolean {
|
||||
const bookingMetadata = bookingMetadataSchema.parse(booking.metadata || {});
|
||||
|
||||
if (bookingMetadata?.platformClientId) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if (booking.eventType?.team) {
|
||||
return !!booking.eventType.team.hideBranding;
|
||||
}
|
||||
|
||||
return !!booking.user?.hideBranding;
|
||||
}
|
||||
|
||||
export {handler};
|
||||
@@ -87,9 +87,10 @@ export class EmailWorkflowService {
|
||||
creditCheckFn,
|
||||
});
|
||||
|
||||
const hideBranding = await getHideBranding({
|
||||
userId: workflow.userId ?? undefined,
|
||||
teamId: workflow.teamId ?? undefined,
|
||||
const hideBranding = await this.shouldHideBranding({
|
||||
platformClientId: evt.platformClientId,
|
||||
userId: workflow.userId,
|
||||
teamId: workflow.teamId,
|
||||
});
|
||||
|
||||
const emailWorkflowContentParams = await this.generateParametersToBuildEmailWorkflowContent({
|
||||
@@ -237,6 +238,27 @@ export class EmailWorkflowService {
|
||||
} as const;
|
||||
}
|
||||
|
||||
private async shouldHideBranding({
|
||||
platformClientId,
|
||||
userId,
|
||||
teamId,
|
||||
}: {
|
||||
platformClientId?: string | null;
|
||||
userId?: number | null;
|
||||
teamId?: number | null;
|
||||
}): Promise<boolean> {
|
||||
if (platformClientId) {
|
||||
return true;
|
||||
}
|
||||
|
||||
const hideBranding = await getHideBranding({
|
||||
userId: userId ?? undefined,
|
||||
teamId: teamId ?? undefined,
|
||||
});
|
||||
|
||||
return hideBranding;
|
||||
}
|
||||
|
||||
async generateEmailPayloadForEvtWorkflow({
|
||||
evt,
|
||||
sendTo,
|
||||
@@ -412,6 +434,7 @@ export class EmailWorkflowService {
|
||||
meetingUrl,
|
||||
otherPerson: attendeeName,
|
||||
name,
|
||||
isBrandingDisabled: hideBranding,
|
||||
});
|
||||
} else if (matchedTemplate === WorkflowTemplates.RATING) {
|
||||
emailContent = emailRatingTemplate({
|
||||
@@ -426,6 +449,7 @@ export class EmailWorkflowService {
|
||||
timeZone,
|
||||
organizer: evt.organizer.name,
|
||||
name,
|
||||
isBrandingDisabled: hideBranding,
|
||||
ratingUrl: `${bookerUrl}/booking/${evt.uid}?rating`,
|
||||
noShowUrl: `${bookerUrl}/booking/${evt.uid}?noShow=true`,
|
||||
});
|
||||
@@ -554,4 +578,4 @@ export class EmailWorkflowService {
|
||||
sender,
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -89,6 +89,7 @@ export type BookingInfo = {
|
||||
videoCallData?: {
|
||||
url?: string;
|
||||
};
|
||||
platformClientId?: string | null;
|
||||
};
|
||||
|
||||
export type WorkflowContextData =
|
||||
|
||||
@@ -49,14 +49,17 @@ export async function sendWorkflowEmails(payload: string): Promise<void> {
|
||||
throw new Error("Booking not found");
|
||||
}
|
||||
|
||||
const calendarEvent = (await CalendarEventBuilder.fromBooking(booking, {})).build();
|
||||
const bookingMetadata = bookingMetadataSchema.parse(booking.metadata || {});
|
||||
|
||||
const calendarEvent = (await CalendarEventBuilder.fromBooking(booking, {
|
||||
platformClientId: bookingMetadata?.platformClientId,
|
||||
})).build();
|
||||
|
||||
if (!calendarEvent) {
|
||||
throw new Error("Calendar event could not be built");
|
||||
}
|
||||
|
||||
// Check if videoCallUrl exists in booking metadata and add it to evt.metadata
|
||||
const bookingMetadata = bookingMetadataSchema.parse(booking.metadata || {});
|
||||
const metadata = bookingMetadata?.videoCallUrl
|
||||
? {
|
||||
videoCallUrl: bookingMetadata.videoCallUrl,
|
||||
|
||||
@@ -523,6 +523,7 @@ export const teamMetadataStrictSchema = baseTeamMetadataSchema
|
||||
export const bookingMetadataSchema = z
|
||||
.object({
|
||||
videoCallUrl: z.string().optional(),
|
||||
platformClientId: z.string().optional(),
|
||||
})
|
||||
.and(z.record(z.string()))
|
||||
.nullable()
|
||||
|
||||
Reference in new issue
Block a user