
* feat: add crowdin and supported languages * fix: main branch name * feat: test crowdin integration * feat: add crowdin config skeleton * feat: update crowdin.yml * fix: remove ro translation * test: en translation * test: en translation * New Crowdin translations by Github Action (#735) Co-authored-by: Crowdin Bot <support+bot@crowdin.com> * test: en translation * fix: separate upload/download workflows * wip * New Crowdin translations by Github Action (#738) Co-authored-by: Crowdin Bot <support+bot@crowdin.com> * wip * wip * wip * wip * wip * typo * wip * wip * update crowdin config * update * chore: support i18n de,es,fr,it,pt,ru,ro,en * chore: extract i18n strings * chore: extract booking components strings for i18n * wip * extract more strings * wip * fallback to getServerSideProps for now * New Crowdin translations by Github Action (#874) Co-authored-by: Crowdin Bot <support+bot@crowdin.com> * fix: minor fixes on the datepicker * fix: add dutch lang * fix: linting issues * fix: string * fix: update GHA * cleanup trpc * fix linting Co-authored-by: Peer Richelsen <peeroke@gmail.com> Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> Co-authored-by: Crowdin Bot <support+bot@crowdin.com> Co-authored-by: Bailey Pumfleet <pumfleet@hey.com>
118 lines
2.8 KiB
TypeScript
118 lines
2.8 KiB
TypeScript
import dayjs from "dayjs";
|
|
import timezone from "dayjs/plugin/timezone";
|
|
import utc from "dayjs/plugin/utc";
|
|
import { GetServerSidePropsContext } from "next";
|
|
import { serverSideTranslations } from "next-i18next/serverSideTranslations";
|
|
|
|
import { asStringOrThrow } from "@lib/asStringOrNull";
|
|
import { getOrSetUserLocaleFromHeaders } from "@lib/core/i18n/i18n.utils";
|
|
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 locale = await getOrSetUserLocaleFromHeaders(context.req);
|
|
|
|
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: {
|
|
localeProp: locale,
|
|
profile: {
|
|
slug: user.username,
|
|
name: user.name,
|
|
image: user.avatar,
|
|
theme: user.theme,
|
|
},
|
|
eventType: eventTypeObject,
|
|
booking,
|
|
...(await serverSideTranslations(locale, ["common"])),
|
|
},
|
|
};
|
|
}
|