2021-08-19 12:27:01 +00:00
|
|
|
import { GetServerSidePropsContext } from "next";
|
2021-09-22 19:52:38 +00:00
|
|
|
|
2021-09-29 21:33:18 +00:00
|
|
|
import { asStringOrUndefined } from "@lib/asStringOrNull";
|
2021-09-22 19:52:38 +00:00
|
|
|
import prisma from "@lib/prisma";
|
2021-06-09 18:28:39 +00:00
|
|
|
|
2021-08-19 12:27:01 +00:00
|
|
|
export default function Type() {
|
|
|
|
// Just redirect to the schedule page to reschedule it.
|
|
|
|
return null;
|
2021-06-09 18:28:39 +00:00
|
|
|
}
|
|
|
|
|
2021-08-19 12:27:01 +00:00
|
|
|
export async function getServerSideProps(context: GetServerSidePropsContext) {
|
2021-09-14 08:45:28 +00:00
|
|
|
const booking = await prisma.booking.findUnique({
|
2021-08-19 12:27:01 +00:00
|
|
|
where: {
|
2021-09-29 21:33:18 +00:00
|
|
|
uid: asStringOrUndefined(context.query.uid),
|
2021-08-19 12:27:01 +00:00
|
|
|
},
|
|
|
|
select: {
|
|
|
|
id: true,
|
2021-09-14 08:45:28 +00:00
|
|
|
eventType: {
|
|
|
|
select: {
|
|
|
|
users: {
|
|
|
|
select: {
|
|
|
|
username: true,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
slug: true,
|
|
|
|
team: {
|
|
|
|
select: {
|
|
|
|
slug: true,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
user: true,
|
2021-08-19 12:27:01 +00:00
|
|
|
title: true,
|
|
|
|
description: true,
|
|
|
|
startTime: true,
|
|
|
|
endTime: true,
|
|
|
|
attendees: true,
|
|
|
|
},
|
|
|
|
});
|
2021-09-14 08:45:28 +00:00
|
|
|
|
2021-09-29 21:33:18 +00:00
|
|
|
if (!booking?.eventType) throw Error("This booking doesn't exists");
|
2021-08-19 12:27:01 +00:00
|
|
|
|
2021-09-14 08:45:28 +00:00
|
|
|
const eventType = booking.eventType;
|
|
|
|
|
|
|
|
const eventPage =
|
|
|
|
(eventType.team ? "team/" + eventType.team.slug : booking.user.username) + "/" + booking.eventType.slug;
|
|
|
|
|
2021-08-19 12:27:01 +00:00
|
|
|
return {
|
|
|
|
redirect: {
|
2021-09-14 08:45:28 +00:00
|
|
|
destination: "/" + eventPage + "?rescheduleUid=" + context.query.uid,
|
2021-08-19 12:27:01 +00:00
|
|
|
permanent: false,
|
|
|
|
},
|
|
|
|
};
|
2021-06-09 18:28:39 +00:00
|
|
|
}
|