Skip to content

Commit e2de28b

Browse files
kart1kaPraashh
andauthored
feat: prevent rescheduling past bookings (#18003)
* feat: prevent rescheduling past bookings * hide reschedule option on frontend * fix * addd null check for booking.endTime --------- Co-authored-by: Prashant Varma <prashantvarma5083@gmail.com>
1 parent 5d88858 commit e2de28b

File tree

3 files changed

+44
-30
lines changed

3 files changed

+44
-30
lines changed

apps/web/components/booking/BookingListItem.tsx

+21-17
Original file line numberDiff line numberDiff line change
@@ -212,23 +212,27 @@ function BookingListItem(booking: BookingItemProps) {
212212
];
213213

214214
const editBookingActions: ActionType[] = [
215-
{
216-
id: "reschedule",
217-
icon: "clock" as const,
218-
label: t("reschedule_booking"),
219-
href: `/reschedule/${booking.uid}${
220-
booking.seatsReferences.length ? `?seatReferenceUid=${getSeatReferenceUid()}` : ""
221-
}`,
222-
},
223-
{
224-
id: "reschedule_request",
225-
icon: "send" as const,
226-
iconClassName: "rotate-45 w-[16px] -translate-x-0.5 ",
227-
label: t("send_reschedule_request"),
228-
onClick: () => {
229-
setIsOpenRescheduleDialog(true);
230-
},
231-
},
215+
...(isBookingInPast
216+
? []
217+
: [
218+
{
219+
id: "reschedule",
220+
icon: "clock" as const,
221+
label: t("reschedule_booking"),
222+
href: `/reschedule/${booking.uid}${
223+
booking.seatsReferences.length ? `?seatReferenceUid=${getSeatReferenceUid()}` : ""
224+
}`,
225+
},
226+
{
227+
id: "reschedule_request",
228+
icon: "send" as const,
229+
iconClassName: "rotate-45 w-[16px] -translate-x-0.5 ",
230+
label: t("send_reschedule_request"),
231+
onClick: () => {
232+
setIsOpenRescheduleDialog(true);
233+
},
234+
},
235+
]),
232236
...(isBookingReroutable(parsedBooking)
233237
? [
234238
{

apps/web/lib/reschedule/[uid]/getServerSideProps.ts

+22-12
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,28 @@ export async function getServerSideProps(context: GetServerSidePropsContext) {
115115
};
116116
}
117117

118+
const eventType = booking.eventType ? booking.eventType : getDefaultEvent(dynamicEventSlugRef);
119+
120+
const enrichedBookingUser = booking.user
121+
? await UserRepository.enrichUserWithItsProfile({ user: booking.user })
122+
: null;
123+
124+
const eventUrl = await buildEventUrlFromBooking({
125+
eventType,
126+
dynamicGroupSlugRef: booking.dynamicGroupSlugRef ?? null,
127+
profileEnrichedBookingUser: enrichedBookingUser,
128+
});
129+
130+
const isBookingInPast = booking.endTime && new Date(booking.endTime) < new Date();
131+
if (isBookingInPast) {
132+
return {
133+
redirect: {
134+
destination: eventUrl,
135+
permanent: false,
136+
},
137+
};
138+
}
139+
118140
// if booking event type is for a seated event and no seat reference uid is provided, throw not found
119141
if (booking?.eventType?.seatsPerTimeSlot && !maybeSeatReferenceUid) {
120142
const userId = session?.user?.id;
@@ -142,18 +164,6 @@ export async function getServerSideProps(context: GetServerSidePropsContext) {
142164
}
143165
}
144166

145-
const eventType = booking.eventType ? booking.eventType : getDefaultEvent(dynamicEventSlugRef);
146-
147-
const enrichedBookingUser = booking.user
148-
? await UserRepository.enrichUserWithItsProfile({ user: booking.user })
149-
: null;
150-
151-
const eventUrl = await buildEventUrlFromBooking({
152-
eventType,
153-
dynamicGroupSlugRef: booking.dynamicGroupSlugRef ?? null,
154-
profileEnrichedBookingUser: enrichedBookingUser,
155-
});
156-
157167
const destinationUrlSearchParams = new URLSearchParams();
158168

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

apps/web/modules/bookings/views/bookings-single-view.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -729,7 +729,7 @@ export default function Success(props: PageProps) {
729729
</span>
730730

731731
<>
732-
{!props.recurringBookings && (
732+
{!props.recurringBookings && !isBookingInPast && (
733733
<span className="text-default inline">
734734
<span className="underline" data-testid="reschedule-link">
735735
<Link

0 commit comments

Comments
 (0)