2023-02-16 22:39:57 +00:00
|
|
|
import type { GetServerSidePropsContext } from "next";
|
2023-03-14 04:19:05 +00:00
|
|
|
import { URLSearchParams } from "url";
|
|
|
|
import { z } from "zod";
|
2021-09-22 19:52:38 +00:00
|
|
|
|
2022-04-06 17:20:30 +00:00
|
|
|
import { getDefaultEvent } from "@calcom/lib/defaultEvents";
|
2023-03-14 04:19:05 +00:00
|
|
|
import { maybeGetBookingUidFromSeat } from "@calcom/lib/server/maybeGetBookingUidFromSeat";
|
2022-05-18 21:05:49 +00:00
|
|
|
import prisma, { bookingMinimalSelect } from "@calcom/prisma";
|
2022-04-06 17:20:30 +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) {
|
2023-07-11 15:11:08 +00:00
|
|
|
const { uid: bookingId, seatReferenceUid } = z
|
2023-03-14 04:19:05 +00:00
|
|
|
.object({ uid: z.string(), seatReferenceUid: z.string().optional() })
|
|
|
|
.parse(context.query);
|
2023-07-11 15:11:08 +00:00
|
|
|
|
2023-03-14 04:19:05 +00:00
|
|
|
const uid = await maybeGetBookingUidFromSeat(prisma, bookingId);
|
2021-09-14 08:45:28 +00:00
|
|
|
const booking = await prisma.booking.findUnique({
|
2021-08-19 12:27:01 +00:00
|
|
|
where: {
|
2023-03-14 04:19:05 +00:00
|
|
|
uid,
|
2021-08-19 12:27:01 +00:00
|
|
|
},
|
|
|
|
select: {
|
2022-05-18 21:05:49 +00:00
|
|
|
...bookingMinimalSelect,
|
2021-09-14 08:45:28 +00:00
|
|
|
eventType: {
|
|
|
|
select: {
|
|
|
|
users: {
|
|
|
|
select: {
|
|
|
|
username: true,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
slug: true,
|
|
|
|
team: {
|
|
|
|
select: {
|
|
|
|
slug: true,
|
|
|
|
},
|
|
|
|
},
|
2023-07-11 15:11:08 +00:00
|
|
|
seatsPerTimeSlot: true,
|
2021-09-14 08:45:28 +00:00
|
|
|
},
|
|
|
|
},
|
2022-04-06 17:20:30 +00:00
|
|
|
dynamicEventSlugRef: true,
|
|
|
|
dynamicGroupSlugRef: true,
|
2021-09-14 08:45:28 +00:00
|
|
|
user: true,
|
2021-08-19 12:27:01 +00:00
|
|
|
},
|
|
|
|
});
|
2022-04-06 17:20:30 +00:00
|
|
|
const dynamicEventSlugRef = booking?.dynamicEventSlugRef || "";
|
2022-06-30 15:09:15 +00:00
|
|
|
|
|
|
|
if (!booking) {
|
|
|
|
return {
|
|
|
|
notFound: true,
|
2023-03-14 04:19:05 +00:00
|
|
|
} as const;
|
2022-06-30 15:09:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (!booking?.eventType && !booking?.dynamicEventSlugRef) {
|
|
|
|
// TODO: Show something in UI to let user know that this booking is not rescheduleable.
|
|
|
|
return {
|
|
|
|
notFound: true,
|
2022-12-07 20:08:34 +00:00
|
|
|
} as {
|
|
|
|
notFound: true;
|
2022-06-30 15:09:15 +00:00
|
|
|
};
|
|
|
|
}
|
2021-09-14 08:45:28 +00:00
|
|
|
|
2022-04-06 17:20:30 +00:00
|
|
|
const eventType = booking.eventType ? booking.eventType : getDefaultEvent(dynamicEventSlugRef);
|
2021-09-14 08:45:28 +00:00
|
|
|
|
|
|
|
const eventPage =
|
2021-10-20 15:42:40 +00:00
|
|
|
(eventType.team
|
|
|
|
? "team/" + eventType.team.slug
|
2022-04-06 17:20:30 +00:00
|
|
|
: dynamicEventSlugRef
|
|
|
|
? booking.dynamicGroupSlugRef
|
2021-10-20 15:42:40 +00:00
|
|
|
: booking.user?.username || "rick") /* This shouldn't happen */ +
|
|
|
|
"/" +
|
2022-04-06 17:20:30 +00:00
|
|
|
eventType?.slug;
|
2023-03-14 04:19:05 +00:00
|
|
|
const destinationUrl = new URLSearchParams();
|
2023-07-11 15:11:08 +00:00
|
|
|
|
|
|
|
destinationUrl.set("rescheduleUid", seatReferenceUid || bookingId);
|
2023-03-14 04:19:05 +00:00
|
|
|
|
2021-08-19 12:27:01 +00:00
|
|
|
return {
|
|
|
|
redirect: {
|
2023-07-11 15:11:08 +00:00
|
|
|
destination: `/${eventPage}?${destinationUrl.toString()}${
|
|
|
|
eventType.seatsPerTimeSlot ? "&bookingUid=null" : ""
|
|
|
|
}`,
|
2021-08-19 12:27:01 +00:00
|
|
|
permanent: false,
|
|
|
|
},
|
|
|
|
};
|
2021-06-09 18:28:39 +00:00
|
|
|
}
|