Skip to content

Commit

Permalink
Replacing bookingAttendees for bookingUid (#8997)
Browse files Browse the repository at this point in the history
  • Loading branch information
alannnc committed May 22, 2023
1 parent c8db177 commit ff6c6cc
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 6 deletions.
2 changes: 1 addition & 1 deletion apps/web/components/booking/AvailableTimes.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ const AvailableTimes: FC<AvailableTimesProps> = ({
slotUtcStartDate: slot.time,
eventTypeId,
slotUtcEndDate: dayjs(slot.time).utc().add(duration, "minutes").format(),
bookingAttendees: bookingAttendees || undefined,
bookingUid: slot.bookingUid,
});
};

Expand Down
2 changes: 1 addition & 1 deletion apps/web/components/booking/pages/BookingPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,7 @@ const BookingPage = ({
eventTypeId: eventType.id,
slotUtcStartDate: dayjs(queryDate).utc().format(),
slotUtcEndDate: dayjs(queryDate).utc().add(parseInt(queryDuration), "minutes").format(),
bookingAttendees: currentSlotBooking ? currentSlotBooking.attendees.length : undefined,
bookingUid: currentSlotBooking?.uid,
});
}
};
Expand Down
11 changes: 8 additions & 3 deletions packages/trpc/server/routers/viewer/slots/reserveSlot.handler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ interface ReserveSlotOptions {
export const reserveSlotHandler = async ({ ctx, input }: ReserveSlotOptions) => {
const { prisma, req, res } = ctx;
const uid = req?.cookies?.uid || uuid();
const { slotUtcStartDate, slotUtcEndDate, eventTypeId, bookingAttendees } = input;
const { slotUtcStartDate, slotUtcEndDate, eventTypeId, bookingUid } = input;
const releaseAt = dayjs.utc().add(parseInt(MINUTES_TO_BOOK), "minutes").format();
const eventType = await prisma.eventType.findUnique({
where: { id: eventTypeId },
Expand All @@ -40,8 +40,13 @@ export const reserveSlotHandler = async ({ ctx, input }: ReserveSlotOptions) =>
// If this is a seated event then don't reserve a slot
if (eventType.seatsPerTimeSlot) {
// Check to see if this is the last attendee
if (bookingAttendees) {
const seatsLeft = eventType.seatsPerTimeSlot - bookingAttendees;
const bookingWithAttendees = await prisma.booking.findFirst({
where: { uid: bookingUid },
select: { attendees: true },
});
const bookingAttendeesLength = bookingWithAttendees?.attendees?.length;
if (bookingAttendeesLength) {
const seatsLeft = eventType.seatsPerTimeSlot - bookingAttendeesLength;
if (seatsLeft < 1) shouldReserveSlot = false;
} else {
// If there is no booking yet then don't reserve the slot
Expand Down
2 changes: 1 addition & 1 deletion packages/trpc/server/routers/viewer/slots/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ export const reserveSlotSchema = z
slotUtcStartDate: z.string(),
// endTime ISOString
slotUtcEndDate: z.string(),
bookingAttendees: z.number().optional(),
bookingUid: z.string().optional(),
})
.refine(
(data) => !!data.eventTypeId || !!data.slotUtcStartDate || !!data.slotUtcEndDate,
Expand Down

1 comment on commit ff6c6cc

@vercel
Copy link

@vercel vercel bot commented on ff6c6cc May 22, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

ui – ./apps/storybook

ui-git-main-cal.vercel.app
timelessui.com
ui-cal.vercel.app
www.timelessui.com
cal-com-storybook.vercel.app
ui.cal.com

Please sign in to comment.