Skip to content

Scheduling infrastructure for absolutely everyone.

Resolved conflicts; included reference creation into EventManager; use EventManager everywhere

nicolas86e2add30f68
diff --cc lib/calendarClient.ts
index bfe0f472d6f,3891feab718..baa47349d39
--- a/lib/calendarClient.ts
+++ b/lib/calendarClient.ts
@@@ -573,9 -551,8 +573,9 @@@ const createEvent = async
const updateEvent = async (
credential: Credential,
uidToUpdate: string,
- calEvent: CalendarEvent
-): Promise<unknown> => {
+ calEvent: CalendarEvent,
- noMail: false
++ noMail = false
+): Promise<EventResult> => {
const parser: CalEventParser = new CalEventParser(calEvent);
const newUid: string = parser.getUid();
const richEvent: CalendarEvent = parser.asRichEvent();
@@@ -626,12 -591,12 +626,4 @@@ const deleteEvent = (credential: Creden
return Promise.resolve({});
};
--export {
-- getBusyCalendarTimes,
-- createEvent,
-- updateEvent,
-- deleteEvent,
-- CalendarEvent,
-- listCalendars,
-- IntegrationCalendar,
--};
++export { getBusyCalendarTimes, createEvent, updateEvent, deleteEvent, listCalendars };
diff --cc lib/events/EventManager.ts
index 6c254c3c2b0,00000000000..50087a22b54
mode 100644,000000..100644
--- a/lib/events/EventManager.ts
+++ b/lib/events/EventManager.ts
@@@ -1,149 -1,0 +1,205 @@@
+import { CalendarEvent, createEvent, updateEvent } from "@lib/calendarClient";
+import { Credential } from "@prisma/client";
+import async from "async";
+import { createMeeting, updateMeeting } from "@lib/videoClient";
++import prisma from "@lib/prisma";
+
+export interface EventResult {
+ type: string;
+ success: boolean;
+ uid: string;
+ createdEvent?: unknown;
+ updatedEvent?: unknown;
+ originalEvent: CalendarEvent;
+}
+
++export interface CreateUpdateResult {
++ results: Array<EventResult>;
++ referencesToCreate: Array<PartialReference>;
++}
++
+export interface PartialBooking {
+ id: number;
+ references: Array<PartialReference>;
+}
+
+export interface PartialReference {
- id: number;
++ id?: number;
+ type: string;
+ uid: string;
+}
+
+export default class EventManager {
+ calendarCredentials: Array<Credential>;
+ videoCredentials: Array<Credential>;
+
+ constructor(credentials: Array<Credential>) {
+ this.calendarCredentials = credentials.filter((cred) => cred.type.endsWith("_calendar"));
+ this.videoCredentials = credentials.filter((cred) => cred.type.endsWith("_video"));
+ }
+
- public async create(event: CalendarEvent): Promise<Array<EventResult>> {
++ public async create(event: CalendarEvent): Promise<CreateUpdateResult> {
+ const isVideo = EventManager.isIntegration(event.location);
+
+ // First, create all calendar events. If this is a video event, don't send a mail right here.
+ const results: Array<EventResult> = await this.createAllCalendarEvents(event, isVideo);
+
+ // If and only if event type is a video meeting, create a video meeting as well.
+ if (isVideo) {
+ results.push(await this.createVideoEvent(event));
+ }
+
- return results;
++ const referencesToCreate: Array<PartialReference> = results.map((result) => {
++ return {
++ type: result.type,
++ uid: result.createdEvent.id.toString(),
++ };
++ });
++
++ return {
++ results,
++ referencesToCreate,
++ };
+ }
+
- public async update(event: CalendarEvent, booking: PartialBooking): Promise<Array<EventResult>> {
++ public async update(event: CalendarEvent, rescheduleUid: string): Promise<CreateUpdateResult> {
++ // Get details of existing booking.
++ const booking = await prisma.booking.findFirst({
++ where: {
++ uid: rescheduleUid,
++ },
++ select: {
++ id: true,
++ references: {
++ select: {
++ id: true,
++ type: true,
++ uid: true,
++ },
++ },
++ },
++ });
++
+ const isVideo = EventManager.isIntegration(event.location);
+
+ // First, update all calendar events. If this is a video event, don't send a mail right here.
+ const results: Array<EventResult> = await this.updateAllCalendarEvents(event, booking, isVideo);
+
+ // If and only if event type is a video meeting, update the video meeting as well.
+ if (isVideo) {
+ results.push(await this.updateVideoEvent(event, booking));
+ }
+
- return results;
++ // Now we can delete the old booking and its references.
++ const bookingReferenceDeletes = prisma.bookingReference.deleteMany({
++ where: {
++ bookingId: booking.id,
++ },
++ });
++ const attendeeDeletes = prisma.attendee.deleteMany({
++ where: {
++ bookingId: booking.id,
++ },
++ });
++ const bookingDeletes = prisma.booking.delete({
++ where: {
++ uid: rescheduleUid,
++ },
++ });
++
++ // Wait for all deletions to be applied.
++ await Promise.all([bookingReferenceDeletes, attendeeDeletes, bookingDeletes]);
++
++ return {
++ results,
++ referencesToCreate: [...booking.references],
++ };
+ }
+
+ /**
+ * Creates event entries for all calendar integrations given in the credentials.
+ * When noMail is true, no mails will be sent. This is used when the event is
+ * a video meeting because then the mail containing the video credentials will be
+ * more important than the mails created for these bare calendar events.
+ *
+ * @param event
+ * @param noMail
+ * @private
+ */
+ private createAllCalendarEvents(event: CalendarEvent, noMail: boolean): Promise<Array<EventResult>> {
+ return async.mapLimit(this.calendarCredentials, 5, async (credential: Credential) => {
+ return createEvent(credential, event, noMail);
+ });
+ }
+
+ private getVideoCredential(event: CalendarEvent): Credential | undefined {
+ const integrationName = event.location.replace("integrations:", "");
+ return this.videoCredentials.find((credential: Credential) => credential.type.includes(integrationName));
+ }
+
+ /**
+ * Creates a video event entry for the selected integration location.
+ *
+ * @param event
+ * @private
+ */
+ private createVideoEvent(event: CalendarEvent): Promise<EventResult> {
+ const credential = this.getVideoCredential(event);
+
+ if (credential) {
+ return createMeeting(credential, event);
+ } else {
+ return Promise.reject("No suitable credentials given for the requested integration name.");
+ }
+ }
+
+ /**
+ * Updates the event entries for all calendar integrations given in the credentials.
+ * When noMail is true, no mails will be sent. This is used when the event is
+ * a video meeting because then the mail containing the video credentials will be
+ * more important than the mails created for these bare calendar events.
+ *
+ * @param event
+ * @param booking
+ * @param noMail
+ * @private
+ */
+ private updateAllCalendarEvents(
+ event: CalendarEvent,
+ booking: PartialBooking,
+ noMail: boolean
+ ): Promise<Array<EventResult>> {
+ return async.mapLimit(this.calendarCredentials, 5, async (credential) => {
+ const bookingRefUid = booking.references.filter((ref) => ref.type === credential.type)[0]?.uid;
+ return updateEvent(credential, bookingRefUid, event, noMail);
+ });
+ }
+
+ /**
+ * Updates a single video event.
+ *
+ * @param event
+ * @param booking
+ * @private
+ */
+ private updateVideoEvent(event: CalendarEvent, booking: PartialBooking) {
+ const credential = this.getVideoCredential(event);
+
+ if (credential) {
+ const bookingRefUid = booking.references.filter((ref) => ref.type === credential.type)[0].uid;
+ return updateMeeting(credential, bookingRefUid, event);
+ } else {
+ return Promise.reject("No suitable credentials given for the requested integration name.");
+ }
+ }
+
+ /**
+ * Returns true if the given location describes an integration that delivers meeting credentials.
+ *
+ * @param location
+ * @private
+ */
+ private static isIntegration(location: string): boolean {
+ return location.includes("integrations:");
+ }
+}
diff --cc pages/api/book/[user].ts
index e5863cb5547,2a5c2273de8..f086bf3f697
--- a/pages/api/book/[user].ts
+++ b/pages/api/book/[user].ts
@@@ -10,8 -11,6 +10,8 @@@ import { LocationType } from "@lib/loca
import merge from "lodash.merge";
import dayjs from "dayjs";
import logger from "../../../lib/logger";
- import EventManager, { EventResult } from "@lib/events/EventManager";
++import EventManager, { CreateUpdateResult, EventResult } from "@lib/events/EventManager";
+import { User } from "@prisma/client";
import utc from "dayjs/plugin/utc";
import timezone from "dayjs/plugin/timezone";
@@@ -98,24 -99,170 +100,43 @@@ const getLocationRequestFromIntegratio
requestId: requestId,
},
},
+ location,
};
- }
-
- return null;
-};
+ } else if (location === LocationType.Zoom.valueOf()) {
+ const requestId = uuidv5(location, uuidv5.URL);
-async function rescheduleEvent(
- rescheduleUid: string | string[],
- results: unknown[],
- calendarCredentials: unknown[],
- evt: CalendarEvent,
- videoCredentials: unknown[],
- referencesToCreate: { type: string; uid: string }[]
-): Promise<{
- referencesToCreate: { type: string; uid: string }[];
- results: unknown[];
- error: { errorCode: string; message: string } | null;
-}> {
- // Reschedule event
- const booking = await prisma.booking.findFirst({
- where: {
- uid: rescheduleUid,
- },
- select: {
- id: true,
- references: {
- select: {
- id: true,
- type: true,
- uid: true,
+ return {
+ conferenceData: {
+ createRequest: {
+ requestId: requestId,
},
},
- },
- });
-
- // Use all integrations
- results = results.concat(
- await async.mapLimit(calendarCredentials, 5, async (credential) => {
- const bookingRefUid = booking.references.filter((ref) => ref.type === credential.type)[0].uid;
- return updateEvent(credential, bookingRefUid, evt)
- .then((response) => ({ type: credential.type, success: true, response }))
- .catch((e) => {
- log.error("updateEvent failed", e, evt);
- return { type: credential.type, success: false };
- });
- })
- );
-
- results = results.concat(
- await async.mapLimit(videoCredentials, 5, async (credential) => {
- const bookingRefUid = booking.references.filter((ref) => ref.type === credential.type)[0].uid;
- return updateMeeting(credential, bookingRefUid, evt)
- .then((response) => ({ type: credential.type, success: true, response }))
- .catch((e) => {
- log.error("updateMeeting failed", e, evt);
- return { type: credential.type, success: false };
- });
- })
- );
-
- if (results.length > 0 && results.every((res) => !res.success)) {
- const error = {
- errorCode: "BookingReschedulingMeetingFailed",
- message: "Booking Rescheduling failed",
+ location,
};
-
- return { referencesToCreate: [], results: [], error: error };
- }
-
- // Clone elements
- referencesToCreate = [...booking.references];
-
- // Now we can delete the old booking and its references.
- const bookingReferenceDeletes = prisma.bookingReference.deleteMany({
- where: {
- bookingId: booking.id,
- },
- });
- const attendeeDeletes = prisma.attendee.deleteMany({
- where: {
- bookingId: booking.id,
- },
- });
- const bookingDeletes = prisma.booking.delete({
- where: {
- uid: rescheduleUid,
- },
- });
-
- await Promise.all([bookingReferenceDeletes, attendeeDeletes, bookingDeletes]);
- return { error: undefined, results, referencesToCreate };
-}
-
-export async function scheduleEvent(
- results: unknown[],
- calendarCredentials: unknown[],
- evt: CalendarEvent,
- videoCredentials: unknown[],
- referencesToCreate: { type: string; uid: string }[]
-): Promise<{
- referencesToCreate: { type: string; uid: string }[];
- results: unknown[];
- error: { errorCode: string; message: string } | null;
-}> {
- // Schedule event
- results = results.concat(
- await async.mapLimit(calendarCredentials, 5, async (credential) => {
- return createEvent(credential, evt)
- .then((response) => ({ type: credential.type, success: true, response }))
- .catch((e) => {
- log.error("createEvent failed", e, evt);
- return { type: credential.type, success: false };
- });
- })
- );
-
- results = results.concat(
- await async.mapLimit(videoCredentials, 5, async (credential) => {
- return createMeeting(credential, evt)
- .then((response) => ({ type: credential.type, success: true, response }))
- .catch((e) => {
- log.error("createMeeting failed", e, evt);
- return { type: credential.type, success: false };
- });
- })
- );
-
- if (results.length > 0 && results.every((res) => !res.success)) {
- const error = {
- errorCode: "BookingCreatingMeetingFailed",
- message: "Booking failed",
- };
-
- return { referencesToCreate: [], results: [], error: error };
}
- referencesToCreate = results.map((result) => {
- return {
- type: result.type,
- uid: result.response.createdEvent.id.toString(),
- };
- });
- return { error: undefined, results, referencesToCreate };
-}
+ return null;
+};
+ export async function handleLegacyConfirmationMail(
- results: unknown[],
++ results: Array<EventResult>,
+ selectedEventType: { requiresConfirmation: boolean },
+ evt: CalendarEvent,
+ hashUID: string
+ ): Promise<{ error: Exception; message: string | null }> {
+ if (results.length === 0 && !selectedEventType.requiresConfirmation) {
+ // Legacy as well, as soon as we have a separate email integration class. Just used
+ // to send an email even if there is no integration at all.
+ try {
+ const mail = new EventAttendeeMail(evt, hashUID);
+ await mail.sendEmail();
+ } catch (e) {
+ return { error: e, message: "Booking failed" };
+ }
+ }
+ return null;
+ }
+
export default async function handler(req: NextApiRequest, res: NextApiResponse): Promise<void> {
const { user } = req.query;
log.debug(`Booking ${user} started`);
@@@ -303,95 -459,48 +325,51 @@@
let referencesToCreate = [];
if (rescheduleUid) {
- // Reschedule event
- const booking = await prisma.booking.findFirst({
- where: {
- uid: rescheduleUid,
- },
- select: {
- id: true,
- references: {
- select: {
- id: true,
- type: true,
- uid: true,
- },
- },
- },
- });
-
- const __ret = await rescheduleEvent(
- rescheduleUid,
- results,
- calendarCredentials,
- evt,
- videoCredentials,
- referencesToCreate
- );
- if (__ret.error) {
- log.error(`Booking ${user} failed`, __ret.error, results);
- return res.status(500).json(__ret.error);
+ // Use EventManager to conditionally use all needed integrations.
- results = await eventManager.update(evt, booking);
++ const updateResults: CreateUpdateResult = await eventManager.update(evt, rescheduleUid);
+
+ if (results.length > 0 && results.every((res) => !res.success)) {
+ const error = {
+ errorCode: "BookingReschedulingMeetingFailed",
+ message: "Booking Rescheduling failed",
+ };
+
+ log.error(`Booking ${user} failed`, error, results);
+ return res.status(500).json(error);
}
- results = __ret.results;
- referencesToCreate = __ret.referencesToCreate;
+
- // Clone elements
- referencesToCreate = [...booking.references];
-
- // Now we can delete the old booking and its references.
- const bookingReferenceDeletes = prisma.bookingReference.deleteMany({
- where: {
- bookingId: booking.id,
- },
- });
- const attendeeDeletes = prisma.attendee.deleteMany({
- where: {
- bookingId: booking.id,
- },
- });
- const bookingDeletes = prisma.booking.delete({
- where: {
- uid: rescheduleUid,
- },
- });
-
- await Promise.all([bookingReferenceDeletes, attendeeDeletes, bookingDeletes]);
- } else {
++ // Forward results
++ results = updateResults.results;
++ referencesToCreate = updateResults.referencesToCreate;
+ } else if (!selectedEventType.requiresConfirmation) {
- const __ret = await scheduleEvent(
- results,
- calendarCredentials,
- evt,
- videoCredentials,
- referencesToCreate
- );
- if (__ret.error) {
- log.error(`Booking ${user} failed`, __ret.error, results);
- return res.status(500).json(__ret.error);
+ // Use EventManager to conditionally use all needed integrations.
- results = await eventManager.create(evt);
++ const createResults: CreateUpdateResult = await eventManager.create(evt);
+
+ if (results.length > 0 && results.every((res) => !res.success)) {
+ const error = {
+ errorCode: "BookingCreatingMeetingFailed",
+ message: "Booking failed",
+ };
+
+ log.error(`Booking ${user} failed`, error, results);
+ return res.status(500).json(error);
}
- results = __ret.results;
- referencesToCreate = __ret.referencesToCreate;
+
- referencesToCreate = results.map((result) => {
- return {
- type: result.type,
- uid: result.createdEvent.id.toString(),
- };
- });
++ // Forward results
++ results = createResults.results;
++ referencesToCreate = createResults.referencesToCreate;
}
const hashUID =
- results.length > 0
- ? results[0].response.uid
- : translator.fromUUID(uuidv5(JSON.stringify(evt), uuidv5.URL));
+ results.length > 0 ? results[0].uid : translator.fromUUID(uuidv5(JSON.stringify(evt), uuidv5.URL));
// TODO Should just be set to the true case as soon as we have a "bare email" integration class.
// UID generation should happen in the integration itself, not here.
- if (results.length === 0) {
- // Legacy as well, as soon as we have a separate email integration class. Just used
- // to send an email even if there is no integration at all.
- try {
- const mail = new EventAttendeeMail(evt, hashUID);
- await mail.sendEmail();
- } catch (e) {
- log.error("Sending legacy event mail failed", e);
- log.error(`Booking ${user} failed`);
- res.status(500).json({ message: "Booking failed" });
- return;
- }
+ const legacyMailError = await handleLegacyConfirmationMail(results, selectedEventType, evt, hashUID);
+ if (legacyMailError) {
+ log.error("Sending legacy event mail failed", legacyMailError.error);
+ log.error(`Booking ${user} failed`);
+ res.status(500).json({ message: legacyMailError.message });
+ return;
}
try {
diff --cc pages/api/book/confirm.ts
index 00000000000,e685db10c07..fb8b961abae
mode 000000,100644..100644
--- a/pages/api/book/confirm.ts
+++ b/pages/api/book/confirm.ts
@@@ -1,0 -1,107 +1,106 @@@
+ import type { NextApiRequest, NextApiResponse } from "next";
+ import { getSession } from "next-auth/client";
+ import prisma from "../../../lib/prisma";
-import { handleLegacyConfirmationMail, scheduleEvent } from "./[user]";
++import { handleLegacyConfirmationMail } from "./[user]";
+ import { CalendarEvent } from "@lib/calendarClient";
+ import EventRejectionMail from "@lib/emails/EventRejectionMail";
++import EventManager from "@lib/events/EventManager";
+
+ export default async function handler(req: NextApiRequest, res: NextApiResponse): Promise<void> {
+ const session = await getSession({ req: req });
+ if (!session) {
+ return res.status(401).json({ message: "Not authenticated" });
+ }
+
+ const bookingId = req.body.id;
+ if (!bookingId) {
+ return res.status(400).json({ message: "bookingId missing" });
+ }
+
+ const currentUser = await prisma.user.findFirst({
+ where: {
+ id: session.user.id,
+ },
+ select: {
+ id: true,
+ credentials: true,
+ timeZone: true,
+ email: true,
+ name: true,
+ },
+ });
+
+ if (req.method == "PATCH") {
+ const booking = await prisma.booking.findFirst({
+ where: {
+ id: bookingId,
+ },
+ select: {
+ title: true,
+ description: true,
+ startTime: true,
+ endTime: true,
+ confirmed: true,
+ attendees: true,
+ userId: true,
+ id: true,
+ uid: true,
+ },
+ });
+
+ if (!booking || booking.userId != currentUser.id) {
+ return res.status(404).json({ message: "booking not found" });
+ }
+ if (booking.confirmed) {
+ return res.status(400).json({ message: "booking already confirmed" });
+ }
+
- const calendarCredentials = currentUser.credentials.filter((cred) => cred.type.endsWith("_calendar"));
- const videoCredentials = currentUser.credentials.filter((cred) => cred.type.endsWith("_video"));
-
+ const evt: CalendarEvent = {
+ type: booking.title,
+ title: booking.title,
+ description: booking.description,
+ startTime: booking.startTime.toISOString(),
+ endTime: booking.endTime.toISOString(),
+ organizer: { email: currentUser.email, name: currentUser.name, timeZone: currentUser.timeZone },
+ attendees: booking.attendees,
+ };
+
+ if (req.body.confirmed) {
- const scheduleResult = await scheduleEvent([], calendarCredentials, evt, videoCredentials, []);
++ const eventManager = new EventManager(currentUser.credentials);
++ const scheduleResult = await eventManager.create(evt);
+
+ await handleLegacyConfirmationMail(
+ scheduleResult.results,
+ { requiresConfirmation: false },
+ evt,
+ booking.uid
+ );
+
+ await prisma.booking.update({
+ where: {
+ id: bookingId,
+ },
+ data: {
+ confirmed: true,
+ references: {
+ create: scheduleResult.referencesToCreate,
+ },
+ },
+ });
+
+ res.status(204).json({ message: "ok" });
+ } else {
+ await prisma.booking.update({
+ where: {
+ id: bookingId,
+ },
+ data: {
+ rejected: true,
+ },
+ });
+ const attendeeMail = new EventRejectionMail(evt, booking.uid);
+ await attendeeMail.sendEmail();
+ res.status(204).json({ message: "ok" });
+ }
+ }
+ }
diff --cc pages/settings/embed.tsx
index 01dd7eae253,99ec1c89f74..67958f92ea3
--- a/pages/settings/embed.tsx
+++ b/pages/settings/embed.tsx
@@@ -1,103 -1,105 +1,110 @@@
--import Head from 'next/head';
--import Link from 'next/link';
--import { useState } from 'react';
--import { useRouter } from 'next/router';
--import prisma from '../../lib/prisma';
--import Modal from '../../components/Modal';
--import Shell from '../../components/Shell';
--import SettingsShell from '../../components/Settings';
--import Avatar from '../../components/Avatar';
--import { signIn, useSession, getSession } from 'next-auth/client';
--import TimezoneSelect from 'react-timezone-select';
++import Head from "next/head";
++import prisma from "../../lib/prisma";
++import Shell from "../../components/Shell";
++import SettingsShell from "../../components/Settings";
++import { getSession, useSession } from "next-auth/client";
export default function Embed(props) {
-- const [ session, loading ] = useSession();
-- const router = useRouter();
++ const [session, loading] = useSession();
-- if (loading) {
-- return <div className="loader"></div>;
-- }
++ if (loading) {
++ return <div className="loader"></div>;
++ }
-- return(
-- <Shell heading="Embed">
-- <Head>
-- <title>Embed | Calendso</title>
-- <link rel="icon" href="/favicon.ico" />
-- </Head>
-- <SettingsShell>
-- <div className="py-6 px-4 sm:p-6 lg:pb-8 lg:col-span-9">
-- <div className="mb-6">
-- <h2 className="text-lg leading-6 font-medium text-gray-900">Iframe Embed</h2>
-- <p className="mt-1 text-sm text-gray-500">
-- The easiest way to embed Calendso on your website.
-- </p>
-- </div>
-- <div className="grid grid-cols-2 space-x-4">
-- <div>
-- <label htmlFor="iframe" className="block text-sm font-medium text-gray-700">
-- Standard iframe
-- </label>
-- <div className="mt-1">
-- <textarea
-- id="iframe"
-- className="h-32 shadow-sm focus:ring-blue-500 focus:border-blue-500 block w-full sm:text-sm border-gray-300 rounded-md"
-- placeholder="Loading..."
- defaultValue={'<iframe src="https://calendso.com/' + session.user.username + '" frameborder="0" allowfullscreen></iframe>'}
- defaultValue={'<iframe src="' + props.BASE_URL + '/' + session.user.username + '" frameborder="0" allowfullscreen></iframe>'}
-- readOnly
-- />
-- </div>
-- </div>
-- <div>
-- <label htmlFor="fullscreen" className="block text-sm font-medium text-gray-700">
-- Responsive full screen iframe
-- </label>
-- <div className="mt-1">
-- <textarea
-- id="fullscreen"
-- className="h-32 shadow-sm focus:ring-blue-500 focus:border-blue-500 block w-full sm:text-sm border-gray-300 rounded-md"
-- placeholder="Loading..."
- defaultValue={'<!DOCTYPE html><html lang="en"><head><meta charset="UTF-8"><meta http-equiv="X-UA-Compatible" content="IE=edge"><meta name="viewport" content="width=device-width, initial-scale=1.0"><title>Schedule a meeting</title><style>body {margin: 0;}iframe {height: calc(100vh - 4px);width: calc(100vw - 4px);box-sizing: border-box;}</style></head><body><iframe src="https://calendso.com/' + session.user.username + '" frameborder="0" allowfullscreen></iframe></body></html>'}
- defaultValue={'<!DOCTYPE html><html lang="en"><head><meta charset="UTF-8"><meta http-equiv="X-UA-Compatible" content="IE=edge"><meta name="viewport" content="width=device-width, initial-scale=1.0"><title>Schedule a meeting</title><style>body {margin: 0;}iframe {height: calc(100vh - 4px);width: calc(100vw - 4px);box-sizing: border-box;}</style></head><body><iframe src="' + props.BASE_URL + '/' + session.user.username + '" frameborder="0" allowfullscreen></iframe></body></html>'}
-- readOnly
-- />
-- </div>
-- </div>
-- </div>
-- <div className="my-6">
-- <h2 className="text-lg leading-6 font-medium text-gray-900">Calendso API</h2>
-- <p className="mt-1 text-sm text-gray-500">
-- Leverage our API for full control and customizability.
-- </p>
-- </div>
-- <a href="https://api.docs.calendso.com" className="btn btn-primary">Browse our API documentation</a>
-- </div>
-- </SettingsShell>
-- </Shell>
-- );
++ return (
++ <Shell heading="Embed">
++ <Head>
++ <title>Embed | Calendso</title>
++ <link rel="icon" href="/favicon.ico" />
++ </Head>
++ <SettingsShell>
++ <div className="py-6 px-4 sm:p-6 lg:pb-8 lg:col-span-9">
++ <div className="mb-6">
++ <h2 className="text-lg leading-6 font-medium text-gray-900">Iframe Embed</h2>
++ <p className="mt-1 text-sm text-gray-500">The easiest way to embed Calendso on your website.</p>
++ </div>
++ <div className="grid grid-cols-2 space-x-4">
++ <div>
++ <label htmlFor="iframe" className="block text-sm font-medium text-gray-700">
++ Standard iframe
++ </label>
++ <div className="mt-1">
++ <textarea
++ id="iframe"
++ className="h-32 shadow-sm focus:ring-blue-500 focus:border-blue-500 block w-full sm:text-sm border-gray-300 rounded-md"
++ placeholder="Loading..."
++ defaultValue={
++ '<iframe src="' +
++ props.BASE_URL +
++ "/" +
++ session.user.username +
++ '" frameborder="0" allowfullscreen></iframe>'
++ }
++ readOnly
++ />
++ </div>
++ </div>
++ <div>
++ <label htmlFor="fullscreen" className="block text-sm font-medium text-gray-700">
++ Responsive full screen iframe
++ </label>
++ <div className="mt-1">
++ <textarea
++ id="fullscreen"
++ className="h-32 shadow-sm focus:ring-blue-500 focus:border-blue-500 block w-full sm:text-sm border-gray-300 rounded-md"
++ placeholder="Loading..."
++ defaultValue={
++ '<!DOCTYPE html><html lang="en"><head><meta charset="UTF-8"><meta http-equiv="X-UA-Compatible" content="IE=edge"><meta name="viewport" content="width=device-width, initial-scale=1.0"><title>Schedule a meeting</title><style>body {margin: 0;}iframe {height: calc(100vh - 4px);width: calc(100vw - 4px);box-sizing: border-box;}</style></head><body><iframe src="' +
++ props.BASE_URL +
++ "/" +
++ session.user.username +
++ '" frameborder="0" allowfullscreen></iframe></body></html>'
++ }
++ readOnly
++ />
++ </div>
++ </div>
++ </div>
++ <div className="my-6">
++ <h2 className="text-lg leading-6 font-medium text-gray-900">Calendso API</h2>
++ <p className="mt-1 text-sm text-gray-500">
++ Leverage our API for full control and customizability.
++ </p>
++ </div>
++ <a href="https://api.docs.calendso.com" className="btn btn-primary">
++ Browse our API documentation
++ </a>
++ </div>
++ </SettingsShell>
++ </Shell>
++ );
}
export async function getServerSideProps(context) {
-- const session = await getSession(context);
-- if (!session) {
-- return { redirect: { permanent: false, destination: '/auth/login' } };
-- }
++ const session = await getSession(context);
++ if (!session) {
++ return { redirect: { permanent: false, destination: "/auth/login" } };
++ }
-- const user = await prisma.user.findFirst({
-- where: {
-- email: session.user.email,
-- },
-- select: {
-- id: true,
-- username: true,
-- name: true,
-- email: true,
-- bio: true,
-- avatar: true,
-- timeZone: true,
-- weekStart: true,
-- }
-- });
++ const user = await prisma.user.findFirst({
++ where: {
++ email: session.user.email,
++ },
++ select: {
++ id: true,
++ username: true,
++ name: true,
++ email: true,
++ bio: true,
++ avatar: true,
++ timeZone: true,
++ weekStart: true,
++ },
++ });
- return {
- props: {user}, // will be passed to the page component as props
- }
- }
- const BASE_URL = process.env.BASE_URL;
++ const BASE_URL = process.env.BASE_URL;
+
- return {
- props: {user, BASE_URL}, // will be passed to the page component as props
- }
++ return {
++ props: { user, BASE_URL }, // will be passed to the page component as props
++ };
+ }