diff --git a/.env.example b/.env.example index 99636771..a0006420 100644 --- a/.env.example +++ b/.env.example @@ -32,3 +32,5 @@ EMAIL_SERVER_PORT=587 EMAIL_SERVER_USER='' # Keep in mind that if you have 2FA enabled, you will need to provision an App Password. EMAIL_SERVER_PASSWORD='' +# ApiKey for cronjobs +CRON_API_KEY='0cc0e6c35519bba620c9360cfe3e68d0' diff --git a/components/ui/PoweredByCalendso.tsx b/components/ui/PoweredByCalendso.tsx index a06e258a..6f2596c8 100644 --- a/components/ui/PoweredByCalendso.tsx +++ b/components/ui/PoweredByCalendso.tsx @@ -2,8 +2,8 @@ import Link from "next/link"; const PoweredByCalendso = () => (
- - + + powered by{" "} => { const parser: CalEventParser = new CalEventParser(calEvent); const newUid: string = parser.getUid(); @@ -626,12 +626,4 @@ const deleteEvent = (credential: Credential, uid: string): Promise => { return Promise.resolve({}); }; -export { - getBusyCalendarTimes, - createEvent, - updateEvent, - deleteEvent, - CalendarEvent, - listCalendars, - IntegrationCalendar, -}; +export { getBusyCalendarTimes, createEvent, updateEvent, deleteEvent, listCalendars }; diff --git a/lib/emails/EventOrganizerMail.ts b/lib/emails/EventOrganizerMail.ts index 1680ad9e..184a062d 100644 --- a/lib/emails/EventOrganizerMail.ts +++ b/lib/emails/EventOrganizerMail.ts @@ -46,6 +46,31 @@ export default class EventOrganizerMail extends EventMail { return icsEvent.value; } + protected getBodyHeader(): string { + return "A new event has been scheduled."; + } + + protected getBodyText(): string { + return "You and any other attendees have been emailed with this information."; + } + + protected getImage(): string { + return ` + + `; + } + /** * Returns the email text as HTML representation. * @@ -67,22 +92,9 @@ export default class EventOrganizerMail extends EventMail { margin-top: 40px; " > - - - -

A new event has been scheduled.

-

You and any other attendees have been emailed with this information.

+ ${this.getImage()} +

${this.getBodyHeader()}

+

${this.getBodyText()}


@@ -165,8 +177,6 @@ export default class EventOrganizerMail extends EventMail { * @protected */ protected getNodeMailerPayload(): Record { - const organizerStart: Dayjs = dayjs(this.calEvent.startTime).tz(this.calEvent.organizer.timeZone); - return { icalEvent: { filename: "event.ics", @@ -174,14 +184,19 @@ export default class EventOrganizerMail extends EventMail { }, from: `Calendso <${this.getMailerOptions().from}>`, to: this.calEvent.organizer.email, - subject: `New event: ${this.calEvent.attendees[0].name} - ${organizerStart.format("LT dddd, LL")} - ${ - this.calEvent.type - }`, + subject: this.getSubject(), html: this.getHtmlRepresentation(), text: this.getPlainTextRepresentation(), }; } + protected getSubject(): string { + const organizerStart: Dayjs = dayjs(this.calEvent.startTime).tz(this.calEvent.organizer.timeZone); + return `New event: ${this.calEvent.attendees[0].name} - ${organizerStart.format("LT dddd, LL")} - ${ + this.calEvent.type + }`; + } + protected printNodeMailerError(error: string): void { console.error("SEND_NEW_EVENT_NOTIFICATION_ERROR", this.calEvent.organizer.email, error); } diff --git a/lib/emails/EventOrganizerRequestMail.ts b/lib/emails/EventOrganizerRequestMail.ts new file mode 100644 index 00000000..dbd2f4d4 --- /dev/null +++ b/lib/emails/EventOrganizerRequestMail.ts @@ -0,0 +1,50 @@ +import dayjs, { Dayjs } from "dayjs"; + +import utc from "dayjs/plugin/utc"; +import timezone from "dayjs/plugin/timezone"; +import toArray from "dayjs/plugin/toArray"; +import localizedFormat from "dayjs/plugin/localizedFormat"; +import EventOrganizerMail from "@lib/emails/EventOrganizerMail"; + +dayjs.extend(utc); +dayjs.extend(timezone); +dayjs.extend(toArray); +dayjs.extend(localizedFormat); + +export default class EventOrganizerRequestMail extends EventOrganizerMail { + protected getBodyHeader(): string { + return "A new event is waiting for your approval."; + } + + protected getBodyText(): string { + return "Check your bookings page to confirm or reject the booking."; + } + + protected getAdditionalBody(): string { + return `Confirm or reject the booking`; + } + + protected getImage(): string { + return ` + + `; + } + + protected getSubject(): string { + const organizerStart: Dayjs = dayjs(this.calEvent.startTime).tz(this.calEvent.organizer.timeZone); + return `New event request: ${this.calEvent.attendees[0].name} - ${organizerStart.format( + "LT dddd, LL" + )} - ${this.calEvent.type}`; + } +} diff --git a/lib/emails/EventOrganizerRequestReminderMail.ts b/lib/emails/EventOrganizerRequestReminderMail.ts new file mode 100644 index 00000000..1f935943 --- /dev/null +++ b/lib/emails/EventOrganizerRequestReminderMail.ts @@ -0,0 +1,25 @@ +import dayjs, { Dayjs } from "dayjs"; + +import utc from "dayjs/plugin/utc"; +import timezone from "dayjs/plugin/timezone"; +import toArray from "dayjs/plugin/toArray"; +import localizedFormat from "dayjs/plugin/localizedFormat"; +import EventOrganizerRequestMail from "@lib/emails/EventOrganizerRequestMail"; + +dayjs.extend(utc); +dayjs.extend(timezone); +dayjs.extend(toArray); +dayjs.extend(localizedFormat); + +export default class EventOrganizerRequestReminderMail extends EventOrganizerRequestMail { + protected getBodyHeader(): string { + return "An event is still waiting for your approval."; + } + + protected getSubject(): string { + const organizerStart: Dayjs = dayjs(this.calEvent.startTime).tz(this.calEvent.organizer.timeZone); + return `Event request is still waiting: ${this.calEvent.attendees[0].name} - ${organizerStart.format( + "LT dddd, LL" + )} - ${this.calEvent.type}`; + } +} diff --git a/lib/emails/EventRejectionMail.ts b/lib/emails/EventRejectionMail.ts new file mode 100644 index 00000000..f52c7eb6 --- /dev/null +++ b/lib/emails/EventRejectionMail.ts @@ -0,0 +1,91 @@ +import dayjs, { Dayjs } from "dayjs"; +import EventMail from "./EventMail"; + +import utc from "dayjs/plugin/utc"; +import timezone from "dayjs/plugin/timezone"; +import localizedFormat from "dayjs/plugin/localizedFormat"; + +dayjs.extend(utc); +dayjs.extend(timezone); +dayjs.extend(localizedFormat); + +export default class EventRejectionMail extends EventMail { + /** + * Returns the email text as HTML representation. + * + * @protected + */ + protected getHtmlRepresentation(): string { + return ( + ` + +
+ + + +

Your meeting request has been rejected

+

You and any other attendees have been emailed with this information.

+
+ ` + + ` +
+
+ Calendso Logo
+ + ` + ); + } + + /** + * Returns the payload object for the nodemailer. + * + * @protected + */ + protected getNodeMailerPayload(): Record { + return { + to: `${this.calEvent.attendees[0].name} <${this.calEvent.attendees[0].email}>`, + from: `${this.calEvent.organizer.name} <${this.getMailerOptions().from}>`, + replyTo: this.calEvent.organizer.email, + subject: `Rejected: ${this.calEvent.type} with ${ + this.calEvent.organizer.name + } on ${this.getInviteeStart().format("dddd, LL")}`, + html: this.getHtmlRepresentation(), + text: this.getPlainTextRepresentation(), + }; + } + + protected printNodeMailerError(error: string): void { + console.error("SEND_BOOKING_CONFIRMATION_ERROR", this.calEvent.attendees[0].email, error); + } + + /** + * Returns the inviteeStart value used at multiple points. + * + * @private + */ + protected getInviteeStart(): Dayjs { + return dayjs(this.calEvent.startTime).tz(this.calEvent.attendees[0].timeZone); + } +} diff --git a/lib/events/EventManager.ts b/lib/events/EventManager.ts index 6c254c3c..50087a22 100644 --- a/lib/events/EventManager.ts +++ b/lib/events/EventManager.ts @@ -2,6 +2,7 @@ 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; @@ -12,13 +13,18 @@ export interface EventResult { originalEvent: CalendarEvent; } +export interface CreateUpdateResult { + results: Array; + referencesToCreate: Array; +} + export interface PartialBooking { id: number; references: Array; } export interface PartialReference { - id: number; + id?: number; type: string; uid: string; } @@ -32,7 +38,7 @@ export default class EventManager { this.videoCredentials = credentials.filter((cred) => cred.type.endsWith("_video")); } - public async create(event: CalendarEvent): Promise> { + public async create(event: CalendarEvent): Promise { const isVideo = EventManager.isIntegration(event.location); // First, create all calendar events. If this is a video event, don't send a mail right here. @@ -43,10 +49,37 @@ export default class EventManager { results.push(await this.createVideoEvent(event)); } - return results; + const referencesToCreate: Array = results.map((result) => { + return { + type: result.type, + uid: result.createdEvent.id.toString(), + }; + }); + + return { + results, + referencesToCreate, + }; } - public async update(event: CalendarEvent, booking: PartialBooking): Promise> { + public async update(event: CalendarEvent, rescheduleUid: string): Promise { + // 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. @@ -57,7 +90,30 @@ export default class EventManager { 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], + }; } /** diff --git a/pages/api/availability/eventtype.ts b/pages/api/availability/eventtype.ts index 5ceb333d..3add13cd 100644 --- a/pages/api/availability/eventtype.ts +++ b/pages/api/availability/eventtype.ts @@ -16,6 +16,7 @@ export default async function handler(req: NextApiRequest, res: NextApiResponse) description: req.body.description, length: parseInt(req.body.length), hidden: req.body.hidden, + requiresConfirmation: req.body.requiresConfirmation, locations: req.body.locations, eventName: req.body.eventName, customInputs: !req.body.customInputs diff --git a/pages/api/book/[user].ts b/pages/api/book/[user].ts index e5863cb5..f086bf3f 100644 --- a/pages/api/book/[user].ts +++ b/pages/api/book/[user].ts @@ -10,12 +10,14 @@ import { LocationType } from "@lib/location"; 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"; import dayjsBusinessDays from "dayjs-business-days"; +import { Exception } from "handlebars"; +import EventOrganizerRequestMail from "@lib/emails/EventOrganizerRequestMail"; dayjs.extend(dayjsBusinessDays); dayjs.extend(utc); @@ -116,6 +118,25 @@ const getLocationRequestFromIntegration = ({ location }: GetLocationRequestFromI return null; }; +export async function handleLegacyConfirmationMail( + results: Array, + 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 { const { user } = req.query; log.debug(`Booking ${user} started`); @@ -210,6 +231,7 @@ export default async function handler(req: NextApiRequest, res: NextApiResponse) periodStartDate: true, periodEndDate: true, periodCountCalendarDays: true, + requiresConfirmation: true, }, }); @@ -303,25 +325,8 @@ export default async function handler(req: NextApiRequest, res: NextApiResponse) 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, - }, - }, - }, - }); - // 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 = { @@ -333,30 +338,12 @@ export default async function handler(req: NextApiRequest, res: NextApiResponse) return res.status(500).json(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]); - } else { + // Forward results + results = updateResults.results; + referencesToCreate = updateResults.referencesToCreate; + } else if (!selectedEventType.requiresConfirmation) { // 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 = { @@ -368,30 +355,21 @@ export default async function handler(req: NextApiRequest, res: NextApiResponse) return res.status(500).json(error); } - 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].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 { @@ -410,6 +388,7 @@ export default async function handler(req: NextApiRequest, res: NextApiResponse) attendees: { create: evt.attendees, }, + confirmed: !selectedEventType.requiresConfirmation, }, }); } catch (e) { @@ -418,6 +397,10 @@ export default async function handler(req: NextApiRequest, res: NextApiResponse) return; } + if (selectedEventType.requiresConfirmation) { + await new EventOrganizerRequestMail(evt, hashUID).sendEmail(); + } + log.debug(`Booking ${user} completed`); return res.status(204).json({ message: "Booking completed" }); } catch (reason) { diff --git a/pages/api/book/confirm.ts b/pages/api/book/confirm.ts new file mode 100644 index 00000000..fb8b961a --- /dev/null +++ b/pages/api/book/confirm.ts @@ -0,0 +1,106 @@ +import type { NextApiRequest, NextApiResponse } from "next"; +import { getSession } from "next-auth/client"; +import prisma from "../../../lib/prisma"; +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 { + 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 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 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 --git a/pages/api/cron/bookingReminder.ts b/pages/api/cron/bookingReminder.ts new file mode 100644 index 00000000..a31bde97 --- /dev/null +++ b/pages/api/cron/bookingReminder.ts @@ -0,0 +1,74 @@ +import type { NextApiRequest, NextApiResponse } from "next"; +import prisma from "@lib/prisma"; +import dayjs from "dayjs"; +import { ReminderType } from "@prisma/client"; +import EventOrganizerRequestReminderMail from "@lib/emails/EventOrganizerRequestReminderMail"; +import { CalendarEvent } from "@lib/calendarClient"; + +export default async function handler(req: NextApiRequest, res: NextApiResponse): Promise { + const apiKey = req.query.apiKey; + if (process.env.CRON_API_KEY != apiKey) { + return res.status(401).json({ message: "Not authenticated" }); + } + + if (req.method == "POST") { + const reminderIntervalMinutes = [48 * 60, 24 * 60, 3 * 60]; + let notificationsSent = 0; + for (const interval of reminderIntervalMinutes) { + const bookings = await prisma.booking.findMany({ + where: { + confirmed: false, + rejected: false, + createdAt: { + lte: dayjs().add(-interval, "minutes").toDate(), + }, + }, + select: { + title: true, + description: true, + startTime: true, + endTime: true, + attendees: true, + user: true, + id: true, + uid: true, + }, + }); + + const reminders = await prisma.reminderMail.findMany({ + where: { + reminderType: ReminderType.PENDING_BOOKING_CONFIRMATION, + referenceId: { + in: bookings.map((b) => b.id), + }, + elapsedMinutes: { + gte: interval, + }, + }, + }); + + for (const booking of bookings.filter((b) => !reminders.some((r) => r.referenceId == b.id))) { + const evt: CalendarEvent = { + type: booking.title, + title: booking.title, + description: booking.description, + startTime: booking.startTime.toISOString(), + endTime: booking.endTime.toISOString(), + organizer: { email: booking.user.email, name: booking.user.name, timeZone: booking.user.timeZone }, + attendees: booking.attendees, + }; + + await new EventOrganizerRequestReminderMail(evt, booking.uid).sendEmail(); + await prisma.reminderMail.create({ + data: { + referenceId: booking.id, + reminderType: ReminderType.PENDING_BOOKING_CONFIRMATION, + elapsedMinutes: interval, + }, + }); + notificationsSent++; + } + } + res.status(200).json({ notificationsSent }); + } +} diff --git a/pages/availability/event/[type].tsx b/pages/availability/event/[type].tsx index 87e57ac2..ae15a1a2 100644 --- a/pages/availability/event/[type].tsx +++ b/pages/availability/event/[type].tsx @@ -66,6 +66,7 @@ type EventTypeInput = { periodStartDate?: Date | string; periodEndDate?: Date | string; periodCountCalendarDays?: boolean; + enteredRequiresConfirmation: boolean; }; const PERIOD_TYPES = [ @@ -172,6 +173,7 @@ export default function EventTypePage({ const descriptionRef = useRef(); const lengthRef = useRef(); const isHiddenRef = useRef(); + const requiresConfirmationRef = useRef(); const eventNameRef = useRef(); const periodDaysRef = useRef(); const periodDaysTypeRef = useRef(); @@ -188,6 +190,7 @@ export default function EventTypePage({ const enteredDescription: string = descriptionRef.current.value; const enteredLength: number = parseInt(lengthRef.current.value); const enteredIsHidden: boolean = isHiddenRef.current.checked; + const enteredRequiresConfirmation: boolean = requiresConfirmationRef.current.checked; const enteredEventName: string = eventNameRef.current.value; const type = periodType.type; @@ -223,6 +226,7 @@ export default function EventTypePage({ periodStartDate: enteredPeriodStartDate, periodEndDate: enteredPeriodEndDate, periodCountCalendarDays: enteredPeriodDaysType, + requiresConfirmation: enteredRequiresConfirmation, }; if (enteredAvailability) { @@ -641,6 +645,29 @@ export default function EventTypePage({ +
+
+
+ +
+
+ +

+ The booking needs to be confirmed, before it is pushed to the integrations and a + confirmation mail is sent. +

+
+
+
When can people book this event? @@ -991,6 +1018,7 @@ export const getServerSideProps: GetServerSideProps = async ({ req, query periodStartDate: true, periodEndDate: true, periodCountCalendarDays: true, + requiresConfirmation: true, }, }); diff --git a/pages/bookings/index.tsx b/pages/bookings/index.tsx index adb75ae7..422eaede 100644 --- a/pages/bookings/index.tsx +++ b/pages/bookings/index.tsx @@ -2,14 +2,29 @@ import Head from "next/head"; import prisma from "../../lib/prisma"; import { getSession, useSession } from "next-auth/client"; import Shell from "../../components/Shell"; +import { useRouter } from "next/router"; export default function Bookings({ bookings }) { const [, loading] = useSession(); + const router = useRouter(); if (loading) { return

Loading...

; } + async function confirmBookingHandler(booking, confirm: boolean) { + const res = await fetch("/api/book/confirm", { + method: "PATCH", + body: JSON.stringify({ id: booking.id, confirmed: confirm }), + headers: { + "Content-Type": "application/json", + }, + }); + if (res.ok) { + await router.replace(router.asPath); + } + } + return (
@@ -45,35 +60,72 @@ export default function Bookings({ bookings }) {
- {bookings.map((booking) => ( - - - - {/* + + + {/* */} - - - ))} + + + ))}
-
{booking.attendees[0].name}
-
{booking.attendees[0].email}
-
-
{booking.title}
-
{booking.description}
-
+ {bookings + .filter((booking) => !booking.confirmed && !booking.rejected) + .concat(bookings.filter((booking) => booking.confirmed || booking.rejected)) + .map((booking) => ( +
+ {!booking.confirmed && !booking.rejected && ( + + Unconfirmed + + )} +
+ {booking.attendees[0].name} +
+
{booking.attendees[0].email}
+
+
{booking.title}
+
{booking.description}
+
{dayjs(booking.startTime).format("D MMMM YYYY HH:mm")}
- - Reschedule - - - Cancel - -
+ {!booking.confirmed && !booking.rejected && ( + <> + confirmBookingHandler(booking, true)} + className="cursor-pointer text-blue-600 hover:text-blue-900"> + Confirm + + confirmBookingHandler(booking, false)} + className="cursor-pointer ml-4 text-blue-600 hover:text-blue-900"> + Reject + + + )} + {booking.confirmed && !booking.rejected && ( + <> + + Reschedule + + + Cancel + + + )} + {!booking.confirmed && booking.rejected && ( +
Rejected
+ )} +
@@ -110,6 +162,9 @@ export async function getServerSideProps(context) { title: true, description: true, attendees: true, + confirmed: true, + rejected: true, + id: true, }, orderBy: { startTime: "desc", diff --git a/pages/settings/embed.tsx b/pages/settings/embed.tsx index 01dd7eae..67958f92 100644 --- a/pages/settings/embed.tsx +++ b/pages/settings/embed.tsx @@ -1,103 +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
; - } + if (loading) { + return
; + } - return( - - - Embed | Calendso - - - -
-
-

Iframe Embed

-

- The easiest way to embed Calendso on your website. -

-
-
-
- -
-