Skip to content

Commit

Permalink
allow cancelled booking rescheduling when allowRescheduleForCancelled…
Browse files Browse the repository at this point in the history
…Booking is true
  • Loading branch information
kart1ka committed Jan 11, 2025
1 parent 2f1cd94 commit 96c71b8
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 22 deletions.
30 changes: 17 additions & 13 deletions apps/web/lib/reschedule/[uid]/getServerSideProps.ts
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,18 @@ export async function getServerSideProps(context: GetServerSidePropsContext) {
} as const;
}

const eventType = booking.eventType ? booking.eventType : getDefaultEvent(dynamicEventSlugRef);

const enrichedBookingUser = booking.user
? await UserRepository.enrichUserWithItsProfile({ user: booking.user })
: null;

const eventUrl = await buildEventUrlFromBooking({
eventType,
dynamicGroupSlugRef: booking.dynamicGroupSlugRef ?? null,
profileEnrichedBookingUser: enrichedBookingUser,
});

// If booking is already CANCELLED or REJECTED, we can't reschedule this booking. Take the user to the booking page which would show it's correct status and other details.
// A booking that has been rescheduled to a new booking will also have a status of CANCELLED
if (
Expand All @@ -103,7 +115,7 @@ export async function getServerSideProps(context: GetServerSidePropsContext) {
) {
return {
redirect: {
destination: `/booking/${uid}`,
destination: booking.status === BookingStatus.CANCELLED ? `${eventUrl}` : `/booking/${uid}`,
permanent: false,
},
};
Expand All @@ -118,18 +130,6 @@ export async function getServerSideProps(context: GetServerSidePropsContext) {
};
}

const eventType = booking.eventType ? booking.eventType : getDefaultEvent(dynamicEventSlugRef);

const enrichedBookingUser = booking.user
? await UserRepository.enrichUserWithItsProfile({ user: booking.user })
: null;

const eventUrl = await buildEventUrlFromBooking({
eventType,
dynamicGroupSlugRef: booking.dynamicGroupSlugRef ?? null,
profileEnrichedBookingUser: enrichedBookingUser,
});

const isBookingInPast = booking.endTime && new Date(booking.endTime) < new Date();
if (isBookingInPast) {
const destinationUrlSearchParams = new URLSearchParams();
Expand Down Expand Up @@ -180,6 +180,10 @@ export async function getServerSideProps(context: GetServerSidePropsContext) {

destinationUrlSearchParams.set("rescheduleUid", seatReferenceUid || bookingUid);

if (allowRescheduleForCancelledBooking) {
destinationUrlSearchParams.set("allowRescheduleForCancelledBooking", "true");
}

// TODO: I think we should just forward all the query params here including coep flag
if (coepFlag) {
destinationUrlSearchParams.set("flag.coep", coepFlag as string);
Expand Down
3 changes: 2 additions & 1 deletion apps/web/lib/team/[slug]/[type]/getServerSideProps.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ export const getServerSideProps = async (context: GetServerSidePropsContext) =>
const session = await getServerSession({ req });
const { slug: teamSlug, type: meetingSlug } = paramsSchema.parse(params);
const { rescheduleUid, isInstantMeeting: queryIsInstantMeeting, email } = query;
const allowRescheduleForCancelledBooking = query.allowRescheduleForCancelledBooking === "true";
const { currentOrgDomain, isValidOrgDomain } = orgDomainConfig(req, params?.orgSlug);
const isOrgContext = currentOrgDomain && isValidOrgDomain;

Expand Down Expand Up @@ -162,7 +163,7 @@ 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) {
if (booking?.status === BookingStatus.CANCELLED && !allowRescheduleForCancelledBooking) {
return {
redirect: {
permanent: false,
Expand Down
39 changes: 31 additions & 8 deletions apps/web/server/lib/[user]/[type]/getServerSideProps.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,18 +51,21 @@ async function processReschedule({
props,
rescheduleUid,
session,
allowRescheduleForCancelledBooking,
}: {
props: Props;
session: Session | null;
rescheduleUid: string | string[] | undefined;
allowRescheduleForCancelledBooking?: boolean;
}) {
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 && booking.status !== BookingStatus.CANCELLED)
(booking?.eventTypeId === props.eventData?.id &&
(booking.status !== BookingStatus.CANCELLED || allowRescheduleForCancelledBooking))
) {
props.booking = booking;
props.rescheduleUid = Array.isArray(rescheduleUid) ? rescheduleUid[0] : rescheduleUid;
Expand Down Expand Up @@ -93,13 +96,15 @@ async function processReschedule({
async function processSeatedEvent({
props,
bookingUid,
allowRescheduleForCancelledBooking,
}: {
props: Props;
bookingUid: string | string[] | undefined;
allowRescheduleForCancelledBooking?: boolean;
}) {
if (!bookingUid) return;
const booking = await getBookingForSeatedEvent(`${bookingUid}`);
if (booking?.status === BookingStatus.CANCELLED) {
if (booking?.status === BookingStatus.CANCELLED && !allowRescheduleForCancelledBooking) {
return {
redirect: {
permanent: false,
Expand All @@ -116,7 +121,7 @@ async function getDynamicGroupPageProps(context: GetServerSidePropsContext) {
const session = await getServerSession(context);
const { user: usernames, type: slug } = paramsSchema.parse(context.params);
const { rescheduleUid, bookingUid } = context.query;

const allowRescheduleForCancelledBooking = context.query.allowRescheduleForCancelledBooking === "true";
const { ssrInit } = await import("@server/lib/ssr");
const ssr = await ssrInit(context);
const { currentOrgDomain, isValidOrgDomain } = orgDomainConfig(context.req, context.params?.orgSlug);
Expand Down Expand Up @@ -192,12 +197,21 @@ async function getDynamicGroupPageProps(context: GetServerSidePropsContext) {
};

if (rescheduleUid) {
const processRescheduleResult = await processReschedule({ props, rescheduleUid, session });
const processRescheduleResult = await processReschedule({
props,
rescheduleUid,
session,
allowRescheduleForCancelledBooking,
});
if (processRescheduleResult) {
return processRescheduleResult;
}
} else if (bookingUid) {
const processSeatResult = await processSeatedEvent({ props, bookingUid });
const processSeatResult = await processSeatedEvent({
props,
bookingUid,
allowRescheduleForCancelledBooking,
});
if (processSeatResult) {
return processSeatResult;
}
Expand All @@ -213,6 +227,7 @@ async function getUserPageProps(context: GetServerSidePropsContext) {
const { user: usernames, type: slug } = paramsSchema.parse(context.params);
const username = usernames[0];
const { rescheduleUid, bookingUid } = context.query;
const allowRescheduleForCancelledBooking = context.query.allowRescheduleForCancelledBooking === "true";
const { currentOrgDomain, isValidOrgDomain } = orgDomainConfig(context.req, context.params?.orgSlug);

const isOrgContext = currentOrgDomain && isValidOrgDomain;
Expand Down Expand Up @@ -289,14 +304,22 @@ async function getUserPageProps(context: GetServerSidePropsContext) {
rescheduleUid: null,
orgBannerUrl: eventData?.owner?.profile?.organization?.bannerUrl ?? null,
};

if (rescheduleUid) {
const processRescheduleResult = await processReschedule({ props, rescheduleUid, session });
const processRescheduleResult = await processReschedule({
props,
rescheduleUid,
session,
allowRescheduleForCancelledBooking,
});
if (processRescheduleResult) {
return processRescheduleResult;
}
} else if (bookingUid) {
const processSeatResult = await processSeatedEvent({ props, bookingUid });
const processSeatResult = await processSeatedEvent({
props,
bookingUid,
allowRescheduleForCancelledBooking,
});
if (processSeatResult) {
return processSeatResult;
}
Expand Down

0 comments on commit 96c71b8

Please sign in to comment.