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 <me@alexvanandel.com>
pull/4652/head^2
Joe Au-Yeung 2022-09-21 12:30:44 -04:00 committed by GitHub
parent 0830523b84
commit 830f42bf9a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 15 additions and 14 deletions

View File

@ -42,7 +42,7 @@ export const EventAdvancedTab = ({ eventType, team }: Pick<EventTypeSetupInfered
const [hashedLinkVisible, setHashedLinkVisible] = useState(!!eventType.hashedLink);
const [hashedUrl, setHashedUrl] = useState(eventType.hashedLink?.link);
const [seatsInputVisible, setSeatsInputVisible] = useState(!!eventType.seatsPerTimeSlot);
const [seatsPerTimeSlot, setSeatsPerTimeSlot] = useState(eventType.seatsPerTimeSlot);
const [seatsPerTimeSlot, setSeatsPerTimeSlot] = useState(eventType.seatsPerTimeSlot || 2);
const [customInputs, setCustomInputs] = useState<EventTypeCustomInput[]>(
eventType.customInputs.sort((a, b) => a.id - b.id) || []
);
@ -324,6 +324,7 @@ export const EventAdvancedTab = ({ eventType, team }: Pick<EventTypeSetupInfered
checked={seatsInputVisible}
onCheckedChange={(e) => {
setSeatsInputVisible(e);
formMethods.setValue("seatsPerTimeSlot", seatsPerTimeSlot);
onChange(e ? seatsPerTimeSlot : null);
}}
fitToHeight={true}

View File

@ -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 {