calcom/pages/[user]/book.tsx
Omar López 0861d7cc61
Ends the war between tRPC and next-i18next (#939)
* Ends the war between tRPC and next-i18next

* Locale fixes

* Linting

* Linting

* trpc i18n (not working) (#942)

* simplify i18n handler and remove redundant(?) fn check

* split up viewer to a "logged in only" and "public"

* wip -- skip first render

Co-authored-by: Omar López <zomars@me.com>

* Linting

* I18n fixes

* We don't need serverSideTranslations in every page anymore

Co-authored-by: kodiakhq[bot] <49736102+kodiakhq[bot]@users.noreply.github.com>
Co-authored-by: Alex Johansson <alexander@n1s.se>
2021-10-14 13:57:49 +03:00

112 lines
2.5 KiB
TypeScript

import dayjs from "dayjs";
import timezone from "dayjs/plugin/timezone";
import utc from "dayjs/plugin/utc";
import { GetServerSidePropsContext } from "next";
import { asStringOrThrow } from "@lib/asStringOrNull";
import prisma from "@lib/prisma";
import { inferSSRProps } from "@lib/types/inferSSRProps";
import BookingPage from "@components/booking/pages/BookingPage";
dayjs.extend(utc);
dayjs.extend(timezone);
export type BookPageProps = inferSSRProps<typeof getServerSideProps>;
export default function Book(props: BookPageProps) {
return <BookingPage {...props} />;
}
export async function getServerSideProps(context: GetServerSidePropsContext) {
const user = await prisma.user.findUnique({
where: {
username: asStringOrThrow(context.query.user),
},
select: {
username: true,
name: true,
email: true,
bio: true,
avatar: true,
theme: true,
},
});
if (!user) return { notFound: true };
const eventType = await prisma.eventType.findUnique({
where: {
id: parseInt(asStringOrThrow(context.query.type)),
},
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,
price: true,
currency: true,
disableGuests: true,
users: {
select: {
username: true,
name: true,
email: true,
bio: true,
avatar: true,
theme: true,
},
},
},
});
if (!eventType) return { notFound: true };
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: {
uid: asStringOrThrow(context.query.rescheduleUid),
},
select: {
description: true,
attendees: {
select: {
email: true,
name: true,
},
},
},
});
}
return {
props: {
profile: {
slug: user.username,
name: user.name,
image: user.avatar,
theme: user.theme,
},
eventType: eventTypeObject,
booking,
},
};
}