2021-09-22 19:52:38 +00:00
|
|
|
import { GetServerSidePropsContext } from "next";
|
|
|
|
|
2021-09-22 18:36:13 +00:00
|
|
|
import { asStringOrThrow } from "@lib/asStringOrNull";
|
2021-09-14 08:45:28 +00:00
|
|
|
import prisma from "@lib/prisma";
|
2021-09-22 18:36:13 +00:00
|
|
|
import { 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
|
|
|
|
2021-09-22 18:36:13 +00:00
|
|
|
export type TeamBookingPageProps = inferSSRProps<typeof getServerSideProps>;
|
|
|
|
|
|
|
|
export default function TeamBookingPage(props: TeamBookingPageProps) {
|
2021-09-14 08:45:28 +00:00
|
|
|
return <BookingPage {...props} />;
|
|
|
|
}
|
|
|
|
|
2021-09-22 18:36:13 +00:00
|
|
|
export async function getServerSideProps(context: GetServerSidePropsContext) {
|
|
|
|
const eventTypeId = parseInt(asStringOrThrow(context.query.type));
|
2021-09-14 08:45:28 +00:00
|
|
|
if (typeof eventTypeId !== "number" || eventTypeId % 1 !== 0) {
|
|
|
|
return {
|
|
|
|
notFound: true,
|
|
|
|
} as const;
|
|
|
|
}
|
|
|
|
|
2021-09-22 18:36:13 +00:00
|
|
|
const eventType = 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,
|
2021-09-22 11:04:32 +00:00
|
|
|
disableGuests: true,
|
2021-12-21 00:59:06 +00:00
|
|
|
price: true,
|
|
|
|
currency: true,
|
2021-09-14 08:45:28 +00:00
|
|
|
team: {
|
|
|
|
select: {
|
|
|
|
slug: true,
|
|
|
|
name: true,
|
|
|
|
logo: true,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
users: {
|
|
|
|
select: {
|
|
|
|
avatar: true,
|
|
|
|
name: true,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
});
|
|
|
|
|
2021-09-22 18:36:13 +00:00
|
|
|
if (!eventType) return { notFound: true };
|
|
|
|
|
2021-09-14 08:45:28 +00:00
|
|
|
const eventTypeObject = [eventType].map((e) => {
|
|
|
|
return {
|
|
|
|
...e,
|
|
|
|
periodStartDate: e.periodStartDate?.toString() ?? null,
|
|
|
|
periodEndDate: e.periodEndDate?.toString() ?? null,
|
|
|
|
};
|
|
|
|
})[0];
|
|
|
|
|
|
|
|
let booking = null;
|
|
|
|
|
|
|
|
if (context.query.rescheduleUid) {
|
|
|
|
booking = await prisma.booking.findFirst({
|
|
|
|
where: {
|
2021-09-22 18:36:13 +00:00
|
|
|
uid: asStringOrThrow(context.query.rescheduleUid),
|
2021-09-14 08:45:28 +00:00
|
|
|
},
|
|
|
|
select: {
|
|
|
|
description: true,
|
|
|
|
attendees: {
|
|
|
|
select: {
|
|
|
|
email: true,
|
|
|
|
name: true,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
return {
|
|
|
|
props: {
|
|
|
|
profile: {
|
|
|
|
...eventTypeObject.team,
|
|
|
|
slug: "team/" + eventTypeObject.slug,
|
2021-09-22 18:36:13 +00:00
|
|
|
image: eventTypeObject.team?.logo || null,
|
|
|
|
theme: null /* Teams don't have a theme, and `BookingPage` uses it */,
|
2021-12-21 00:59:06 +00:00
|
|
|
brandColor: null /* Teams don't have a brandColor, and `BookingPage` uses it */,
|
2021-09-14 08:45:28 +00:00
|
|
|
},
|
|
|
|
eventType: eventTypeObject,
|
|
|
|
booking,
|
|
|
|
},
|
|
|
|
};
|
|
|
|
}
|