From 830f42bf9a692a705808c4f0971094f6c634b000 Mon Sep 17 00:00:00 2001 From: Joe Au-Yeung <65426560+joeauyeung@users.noreply.github.com> Date: Wed, 21 Sep 2022 12:30:44 -0400 Subject: [PATCH] Run available user check if event type does not have checks (#4646) * Move available users if there are no seats * Fix adding default seat to event type Co-authored-by: Alex van Andel --- .../v2/eventtype/EventAdvancedTab.tsx | 3 ++- apps/web/pages/api/book/event.ts | 26 +++++++++---------- 2 files changed, 15 insertions(+), 14 deletions(-) diff --git a/apps/web/components/v2/eventtype/EventAdvancedTab.tsx b/apps/web/components/v2/eventtype/EventAdvancedTab.tsx index f0d3a8c004..7e3aa37ece 100644 --- a/apps/web/components/v2/eventtype/EventAdvancedTab.tsx +++ b/apps/web/components/v2/eventtype/EventAdvancedTab.tsx @@ -42,7 +42,7 @@ export const EventAdvancedTab = ({ eventType, team }: Pick( eventType.customInputs.sort((a, b) => a.id - b.id) || [] ); @@ -324,6 +324,7 @@ export const EventAdvancedTab = ({ eventType, team }: Pick { setSeatsInputVisible(e); + formMethods.setValue("seatsPerTimeSlot", seatsPerTimeSlot); onChange(e ? seatsPerTimeSlot : null); }} fitToHeight={true} diff --git a/apps/web/pages/api/book/event.ts b/apps/web/pages/api/book/event.ts index f5fc833cff..6f133db7d9 100644 --- a/apps/web/pages/api/book/event.ts +++ b/apps/web/pages/api/book/event.ts @@ -327,20 +327,20 @@ async function handler(req: NextApiRequest) { if (!users) throw new HttpError({ statusCode: 404, message: "eventTypeUser.notFound" }); - const availableUsers = await ensureAvailableUsers( - { - ...eventType, - users, - }, - { - dateFrom: reqBody.start, - dateTo: reqBody.end, - } - ); - - // Add an if conditional if there are no seats on the event type - // Assign to only one user when ROUND_ROBIN if (!eventType.seatsPerTimeSlot) { + const availableUsers = await ensureAvailableUsers( + { + ...eventType, + users, + }, + { + dateFrom: reqBody.start, + dateTo: reqBody.end, + } + ); + + // Add an if conditional if there are no seats on the event type + // Assign to only one user when ROUND_ROBIN if (eventType.schedulingType === SchedulingType.ROUND_ROBIN) { users = [await getLuckyUser("MAXIMIZE_AVAILABILITY", { availableUsers, eventTypeId: eventType.id })]; } else {