| 
									
										
										
										
											2022-02-11 22:20:10 +00:00
										 |  |  | import { Prisma } from "@prisma/client"; | 
					
						
							| 
									
										
										
										
											2021-09-22 19:52:38 +00:00
										 |  |  | import { GetServerSidePropsContext } from "next"; | 
					
						
							| 
									
										
										
										
											2022-02-01 21:48:40 +00:00
										 |  |  | import { JSONObject } from "superjson/dist/types"; | 
					
						
							| 
									
										
										
										
											2021-09-22 19:52:38 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-04-05 18:03:22 +00:00
										 |  |  | import { getLocationLabels } from "@calcom/app-store/utils"; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-09-22 18:36:13 +00:00
										 |  |  | import { asStringOrThrow } from "@lib/asStringOrNull"; | 
					
						
							| 
									
										
										
										
											2022-04-14 21:25:24 +00:00
										 |  |  | import getBooking, { GetBookingType } from "@lib/getBooking"; | 
					
						
							| 
									
										
										
										
											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
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-04-05 18:03:22 +00:00
										 |  |  | import { getTranslation } from "@server/lib/i18n"; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											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, | 
					
						
							| 
									
										
										
										
											2022-02-01 21:48:40 +00:00
										 |  |  |       metadata: true, | 
					
						
							| 
									
										
										
										
											2021-09-14 08:45:28 +00:00
										 |  |  |       team: { | 
					
						
							|  |  |  |         select: { | 
					
						
							|  |  |  |           slug: true, | 
					
						
							|  |  |  |           name: true, | 
					
						
							|  |  |  |           logo: true, | 
					
						
							|  |  |  |         }, | 
					
						
							|  |  |  |       }, | 
					
						
							|  |  |  |       users: { | 
					
						
							|  |  |  |         select: { | 
					
						
							| 
									
										
										
										
											2022-04-14 21:25:24 +00:00
										 |  |  |           id: true, | 
					
						
							| 
									
										
										
										
											2021-09-14 08:45:28 +00:00
										 |  |  |           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, | 
					
						
							| 
									
										
										
										
											2022-02-01 21:48:40 +00:00
										 |  |  |       metadata: (eventType.metadata || {}) as JSONObject, | 
					
						
							| 
									
										
										
										
											2021-09-14 08:45:28 +00:00
										 |  |  |       periodStartDate: e.periodStartDate?.toString() ?? null, | 
					
						
							|  |  |  |       periodEndDate: e.periodEndDate?.toString() ?? null, | 
					
						
							|  |  |  |     }; | 
					
						
							|  |  |  |   })[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) { | 
					
						
							| 
									
										
										
										
											2022-04-14 21:25:24 +00:00
										 |  |  |     booking = await getBooking(prisma, context.query.rescheduleUid as string); | 
					
						
							| 
									
										
										
										
											2022-02-10 17:42:06 +00:00
										 |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-04-05 18:03:22 +00:00
										 |  |  |   const t = await getTranslation(context.locale ?? "en", "common"); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-09-14 08:45:28 +00:00
										 |  |  |   return { | 
					
						
							|  |  |  |     props: { | 
					
						
							| 
									
										
										
										
											2022-04-05 18:03:22 +00:00
										 |  |  |       locationLabels: getLocationLabels(t), | 
					
						
							| 
									
										
										
										
											2021-09-14 08:45:28 +00:00
										 |  |  |       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 */, | 
					
						
							| 
									
										
										
										
											2022-03-05 15:37:46 +00:00
										 |  |  |         darkBrandColor: null /* Teams don't have a darkBrandColor, and `BookingPage` uses it */, | 
					
						
							| 
									
										
										
										
											2022-04-08 16:50:10 +00:00
										 |  |  |         eventName: null, | 
					
						
							| 
									
										
										
										
											2021-09-14 08:45:28 +00:00
										 |  |  |       }, | 
					
						
							|  |  |  |       eventType: eventTypeObject, | 
					
						
							|  |  |  |       booking, | 
					
						
							| 
									
										
										
										
											2022-04-06 17:20:30 +00:00
										 |  |  |       isDynamicGroupBooking: false, | 
					
						
							| 
									
										
										
										
											2021-09-14 08:45:28 +00:00
										 |  |  |     }, | 
					
						
							|  |  |  |   }; | 
					
						
							|  |  |  | } |