Skip to content

Commit

Permalink
feat: redirect to original event link for rescheduling cancelled booking
Browse files Browse the repository at this point in the history
  • Loading branch information
kart1ka committed Jan 11, 2025
1 parent 62b753a commit 2f1cd94
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 9 deletions.
10 changes: 9 additions & 1 deletion apps/web/lib/team/[slug]/[type]/getServerSideProps.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import { getPlaceholderAvatar } from "@calcom/lib/defaultAvatarImage";
import { OrganizationRepository } from "@calcom/lib/server/repository/organization";
import slugify from "@calcom/lib/slugify";
import prisma from "@calcom/prisma";
import { RedirectType } from "@calcom/prisma/client";
import { BookingStatus, RedirectType } from "@calcom/prisma/client";
import { EventTypeMetaDataSchema } from "@calcom/prisma/zod-utils";

import { getTemporaryOrgRedirect } from "@lib/getTemporaryOrgRedirect";
Expand Down Expand Up @@ -162,6 +162,14 @@ export const getServerSideProps = async (context: GetServerSidePropsContext) =>
let booking: GetBookingType | null = null;
if (rescheduleUid) {
booking = await getBookingForReschedule(`${rescheduleUid}`, session?.user?.id);
if (booking?.status === BookingStatus.CANCELLED) {
return {
redirect: {
permanent: false,
destination: `/team/${teamSlug}/${meetingSlug}`,
},
};
}
}

const ssr = await ssrInit(context);
Expand Down
34 changes: 27 additions & 7 deletions apps/web/server/lib/[user]/[type]/getServerSideProps.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,15 @@ import type { Session } from "next-auth";
import { z } from "zod";

import { getServerSession } from "@calcom/features/auth/lib/getServerSession";
import { getBookingForReschedule, getBookingForSeatedEvent } from "@calcom/features/bookings/lib/get-booking";
import type { GetBookingType } from "@calcom/features/bookings/lib/get-booking";
import { getBookingForReschedule, getBookingForSeatedEvent } from "@calcom/features/bookings/lib/get-booking";
import { orgDomainConfig } from "@calcom/features/ee/organizations/lib/orgDomains";
import type { getPublicEvent } from "@calcom/features/eventtypes/lib/getPublicEvent";
import { getUsernameList } from "@calcom/lib/defaultEvents";
import { UserRepository } from "@calcom/lib/server/repository/user";
import slugify from "@calcom/lib/slugify";
import prisma from "@calcom/prisma";
import { RedirectType } from "@calcom/prisma/client";
import { BookingStatus, RedirectType } from "@calcom/prisma/client";

import { getTemporaryOrgRedirect } from "@lib/getTemporaryOrgRedirect";

Expand Down Expand Up @@ -59,7 +59,11 @@ async function processReschedule({
if (!rescheduleUid) return;
const booking = await getBookingForReschedule(`${rescheduleUid}`, session?.user?.id);
// if no booking found, no eventTypeId (dynamic) or it matches this eventData - return void (success).
if (booking === null || !booking.eventTypeId || booking?.eventTypeId === props.eventData?.id) {
if (
booking === null ||
!booking.eventTypeId ||
(booking?.eventTypeId === props.eventData?.id && booking.status !== BookingStatus.CANCELLED)
) {
props.booking = booking;
props.rescheduleUid = Array.isArray(rescheduleUid) ? rescheduleUid[0] : rescheduleUid;
return;
Expand Down Expand Up @@ -94,8 +98,18 @@ async function processSeatedEvent({
bookingUid: string | string[] | undefined;
}) {
if (!bookingUid) return;
props.booking = await getBookingForSeatedEvent(`${bookingUid}`);
props.bookingUid = Array.isArray(bookingUid) ? bookingUid[0] : bookingUid;
const booking = await getBookingForSeatedEvent(`${bookingUid}`);
if (booking?.status === BookingStatus.CANCELLED) {
return {
redirect: {
permanent: false,
destination: `${props.slug}`,
},
};
} else {
props.booking = booking;
props.bookingUid = Array.isArray(bookingUid) ? bookingUid[0] : bookingUid;
}
}

async function getDynamicGroupPageProps(context: GetServerSidePropsContext) {
Expand Down Expand Up @@ -183,7 +197,10 @@ async function getDynamicGroupPageProps(context: GetServerSidePropsContext) {
return processRescheduleResult;
}
} else if (bookingUid) {
await processSeatedEvent({ props, bookingUid });
const processSeatResult = await processSeatedEvent({ props, bookingUid });
if (processSeatResult) {
return processSeatResult;
}
}

return {
Expand Down Expand Up @@ -279,7 +296,10 @@ async function getUserPageProps(context: GetServerSidePropsContext) {
return processRescheduleResult;
}
} else if (bookingUid) {
await processSeatedEvent({ props, bookingUid });
const processSeatResult = await processSeatedEvent({ props, bookingUid });
if (processSeatResult) {
return processSeatResult;
}
}

return {
Expand Down
2 changes: 2 additions & 0 deletions packages/features/bookings/lib/get-booking.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ async function getBooking(prisma: PrismaClient, uid: string, isSeatedEvent?: boo
smsReminderNumber: true,
location: true,
eventTypeId: true,
status: true,
attendees: {
select: {
email: true,
Expand Down Expand Up @@ -226,6 +227,7 @@ export const getBookingForSeatedEvent = async (uid: string) => {
uid: true,
startTime: true,
endTime: true,
status: true,
attendees: {
select: {
id: true,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { BookingStatus } from "@calcom/prisma/enums";

import { type OriginalRescheduledBooking } from "./getOriginalRescheduledBooking";

export const validateOriginalRescheduledBooking = async (
export const validateOriginalRescheduledBooking = (
originalRescheduledBooking: OriginalRescheduledBooking
) => {
if (!originalRescheduledBooking) {
Expand Down

0 comments on commit 2f1cd94

Please sign in to comment.