2023-02-16 22:39:57 +00:00
|
|
|
import type { GetServerSidePropsContext } from "next";
|
2021-09-22 19:52:38 +00:00
|
|
|
|
2023-02-16 22:39:57 +00:00
|
|
|
import type { LocationObject } from "@calcom/app-store/locations";
|
|
|
|
import { privacyFilteredLocations } from "@calcom/app-store/locations";
|
2023-03-02 18:15:28 +00:00
|
|
|
import { getBookingFieldsWithSystemFields } from "@calcom/features/bookings/lib/getBookingFields";
|
2022-06-10 00:32:34 +00:00
|
|
|
import { parseRecurringEvent } from "@calcom/lib";
|
2022-07-28 19:58:26 +00:00
|
|
|
import prisma from "@calcom/prisma";
|
2023-03-02 18:15:28 +00:00
|
|
|
import { customInputSchema, eventTypeBookingFields, EventTypeMetaDataSchema } from "@calcom/prisma/zod-utils";
|
2022-04-05 18:03:22 +00:00
|
|
|
|
2022-05-17 20:43:27 +00:00
|
|
|
import { asStringOrNull, asStringOrThrow } from "@lib/asStringOrNull";
|
2023-02-16 22:39:57 +00:00
|
|
|
import type { GetBookingType } from "@lib/getBooking";
|
|
|
|
import getBooking from "@lib/getBooking";
|
|
|
|
import type { inferSSRProps } from "@lib/types/inferSSRProps";
|
2021-09-22 19:52:38 +00:00
|
|
|
|
|
|
|
import BookingPage from "@components/booking/pages/BookingPage";
|
2021-09-14 08:45:28 +00:00
|
|
|
|
2023-03-02 18:15:28 +00:00
|
|
|
import { ssrInit } from "@server/lib/ssr";
|
|
|
|
|
2021-09-22 18:36:13 +00:00
|
|
|
export type TeamBookingPageProps = inferSSRProps<typeof getServerSideProps>;
|
|
|
|
|
|
|
|
export default function TeamBookingPage(props: TeamBookingPageProps) {
|
2022-08-26 00:48:50 +00:00
|
|
|
return <BookingPage {...props} />;
|
2021-09-14 08:45:28 +00:00
|
|
|
}
|
|
|
|
|
2022-07-26 08:27:57 +00:00
|
|
|
TeamBookingPage.isThemeSupported = true;
|
|
|
|
|
2021-09-22 18:36:13 +00:00
|
|
|
export async function getServerSideProps(context: GetServerSidePropsContext) {
|
2023-03-02 18:15:28 +00:00
|
|
|
const ssr = await ssrInit(context);
|
2021-09-22 18:36:13 +00:00
|
|
|
const eventTypeId = parseInt(asStringOrThrow(context.query.type));
|
2022-05-05 21:16:25 +00:00
|
|
|
const recurringEventCountQuery = asStringOrNull(context.query.count);
|
2021-09-14 08:45:28 +00:00
|
|
|
if (typeof eventTypeId !== "number" || eventTypeId % 1 !== 0) {
|
|
|
|
return {
|
|
|
|
notFound: true,
|
|
|
|
} as const;
|
|
|
|
}
|
|
|
|
|
2022-05-05 21:16:25 +00:00
|
|
|
const eventTypeRaw = await prisma.eventType.findUnique({
|
2021-09-14 08:45:28 +00:00
|
|
|
where: {
|
|
|
|
id: eventTypeId,
|
|
|
|
},
|
|
|
|
select: {
|
|
|
|
id: true,
|
|
|
|
title: true,
|
|
|
|
slug: true,
|
|
|
|
description: true,
|
|
|
|
length: true,
|
|
|
|
locations: true,
|
|
|
|
customInputs: true,
|
|
|
|
periodType: true,
|
|
|
|
periodDays: true,
|
|
|
|
periodStartDate: true,
|
|
|
|
periodEndDate: true,
|
|
|
|
periodCountCalendarDays: true,
|
2022-05-05 21:16:25 +00:00
|
|
|
recurringEvent: true,
|
2022-06-10 23:32:54 +00:00
|
|
|
requiresConfirmation: true,
|
2021-09-22 11:04:32 +00:00
|
|
|
disableGuests: true,
|
2021-12-21 00:59:06 +00:00
|
|
|
price: true,
|
|
|
|
currency: true,
|
2022-02-01 21:48:40 +00:00
|
|
|
metadata: true,
|
2022-05-24 13:19:12 +00:00
|
|
|
seatsPerTimeSlot: true,
|
2022-08-15 19:52:01 +00:00
|
|
|
schedulingType: true,
|
2023-03-02 18:15:28 +00:00
|
|
|
bookingFields: true,
|
2022-07-14 00:10:45 +00:00
|
|
|
workflows: {
|
|
|
|
include: {
|
|
|
|
workflow: {
|
|
|
|
include: {
|
|
|
|
steps: true,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
2021-09-14 08:45:28 +00:00
|
|
|
team: {
|
|
|
|
select: {
|
|
|
|
slug: true,
|
|
|
|
name: true,
|
|
|
|
logo: true,
|
2023-02-01 18:27:26 +00:00
|
|
|
theme: true,
|
|
|
|
brandColor: true,
|
|
|
|
darkBrandColor: true,
|
2021-09-14 08:45:28 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
users: {
|
|
|
|
select: {
|
2022-04-14 21:25:24 +00:00
|
|
|
id: true,
|
2022-05-17 20:43:27 +00:00
|
|
|
username: true,
|
2021-09-14 08:45:28 +00:00
|
|
|
avatar: true,
|
|
|
|
name: true,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
});
|
|
|
|
|
2022-05-05 21:16:25 +00:00
|
|
|
if (!eventTypeRaw) return { notFound: true };
|
|
|
|
|
|
|
|
const eventType = {
|
|
|
|
...eventTypeRaw,
|
2022-08-26 00:48:50 +00:00
|
|
|
//TODO: Use zodSchema to verify it instead of using Type Assertion
|
2022-11-10 11:07:16 +00:00
|
|
|
locations: privacyFilteredLocations((eventTypeRaw.locations || []) as LocationObject[]),
|
2022-06-10 00:32:34 +00:00
|
|
|
recurringEvent: parseRecurringEvent(eventTypeRaw.recurringEvent),
|
2023-03-02 18:15:28 +00:00
|
|
|
bookingFields: eventTypeBookingFields.parse(eventTypeRaw.bookingFields || []),
|
2022-05-05 21:16:25 +00:00
|
|
|
};
|
2021-09-14 08:45:28 +00:00
|
|
|
const eventTypeObject = [eventType].map((e) => {
|
|
|
|
return {
|
|
|
|
...e,
|
2023-03-02 18:15:28 +00:00
|
|
|
metadata: EventTypeMetaDataSchema.parse(e.metadata || {}),
|
|
|
|
bookingFields: getBookingFieldsWithSystemFields(eventType),
|
2021-09-14 08:45:28 +00:00
|
|
|
periodStartDate: e.periodStartDate?.toString() ?? null,
|
|
|
|
periodEndDate: e.periodEndDate?.toString() ?? null,
|
2022-12-01 21:53:52 +00:00
|
|
|
customInputs: customInputSchema.array().parse(e.customInputs || []),
|
2022-08-12 19:29:29 +00:00
|
|
|
users: eventType.users.map((u) => ({
|
|
|
|
id: u.id,
|
|
|
|
name: u.name,
|
|
|
|
username: u.username,
|
|
|
|
avatar: u.avatar,
|
|
|
|
image: u.avatar,
|
|
|
|
slug: u.username,
|
|
|
|
})),
|
2021-09-14 08:45:28 +00:00
|
|
|
};
|
|
|
|
})[0];
|
|
|
|
|
2022-04-14 21:25:24 +00:00
|
|
|
let booking: GetBookingType | null = null;
|
2022-02-10 17:42:06 +00:00
|
|
|
if (context.query.rescheduleUid) {
|
2023-03-02 18:15:28 +00:00
|
|
|
booking = await getBooking(prisma, context.query.rescheduleUid as string, eventTypeObject.bookingFields);
|
2022-02-10 17:42:06 +00:00
|
|
|
}
|
|
|
|
|
2022-05-05 21:16:25 +00:00
|
|
|
// Checking if number of recurring event ocurrances is valid against event type configuration
|
|
|
|
const recurringEventCount =
|
|
|
|
(eventType.recurringEvent?.count &&
|
|
|
|
recurringEventCountQuery &&
|
|
|
|
(parseInt(recurringEventCountQuery) <= eventType.recurringEvent.count
|
2022-06-10 20:38:06 +00:00
|
|
|
? parseInt(recurringEventCountQuery)
|
2022-05-05 21:16:25 +00:00
|
|
|
: eventType.recurringEvent.count)) ||
|
|
|
|
null;
|
|
|
|
|
2021-09-14 08:45:28 +00:00
|
|
|
return {
|
|
|
|
props: {
|
2023-03-02 18:15:28 +00:00
|
|
|
trpcState: ssr.dehydrate(),
|
2021-09-14 08:45:28 +00:00
|
|
|
profile: {
|
|
|
|
...eventTypeObject.team,
|
2022-06-06 09:41:11 +00:00
|
|
|
// FIXME: This slug is used as username on success page which is wrong. This is correctly set as username for user booking.
|
2021-09-14 08:45:28 +00:00
|
|
|
slug: "team/" + eventTypeObject.slug,
|
2021-09-22 18:36:13 +00:00
|
|
|
image: eventTypeObject.team?.logo || null,
|
2022-04-08 16:50:10 +00:00
|
|
|
eventName: null,
|
2021-09-14 08:45:28 +00:00
|
|
|
},
|
|
|
|
eventType: eventTypeObject,
|
2022-05-05 21:16:25 +00:00
|
|
|
recurringEventCount,
|
2021-09-14 08:45:28 +00:00
|
|
|
booking,
|
2022-04-06 17:20:30 +00:00
|
|
|
isDynamicGroupBooking: false,
|
2022-04-28 15:44:26 +00:00
|
|
|
hasHashedBookingLink: false,
|
|
|
|
hashedLink: null,
|
2022-10-19 21:25:03 +00:00
|
|
|
isEmbed: typeof context.query.embed === "string",
|
2021-09-14 08:45:28 +00:00
|
|
|
},
|
|
|
|
};
|
|
|
|
}
|