2023-02-16 22:39:57 +00:00
|
|
|
import type { GetServerSidePropsContext } from "next";
|
2021-09-22 19:52:38 +00:00
|
|
|
|
2022-04-06 17:20:30 +00:00
|
|
|
import { getDefaultEvent } from "@calcom/lib/defaultEvents";
|
2022-05-18 21:05:49 +00:00
|
|
|
import prisma, { bookingMinimalSelect } from "@calcom/prisma";
|
2022-04-06 17:20:30 +00:00
|
|
|
|
2021-09-29 21:33:18 +00:00
|
|
|
import { asStringOrUndefined } from "@lib/asStringOrNull";
|
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: {
|
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,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
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,
|
2022-12-07 20:08:34 +00:00
|
|
|
} as {
|
|
|
|
notFound: true;
|
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;
|
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
|
|
|
}
|