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
parent
0830523b84
commit
830f42bf9a
|
@ -42,7 +42,7 @@ export const EventAdvancedTab = ({ eventType, team }: Pick<EventTypeSetupInfered
|
||||||
const [hashedLinkVisible, setHashedLinkVisible] = useState(!!eventType.hashedLink);
|
const [hashedLinkVisible, setHashedLinkVisible] = useState(!!eventType.hashedLink);
|
||||||
const [hashedUrl, setHashedUrl] = useState(eventType.hashedLink?.link);
|
const [hashedUrl, setHashedUrl] = useState(eventType.hashedLink?.link);
|
||||||
const [seatsInputVisible, setSeatsInputVisible] = useState(!!eventType.seatsPerTimeSlot);
|
const [seatsInputVisible, setSeatsInputVisible] = useState(!!eventType.seatsPerTimeSlot);
|
||||||
const [seatsPerTimeSlot, setSeatsPerTimeSlot] = useState(eventType.seatsPerTimeSlot);
|
const [seatsPerTimeSlot, setSeatsPerTimeSlot] = useState(eventType.seatsPerTimeSlot || 2);
|
||||||
const [customInputs, setCustomInputs] = useState<EventTypeCustomInput[]>(
|
const [customInputs, setCustomInputs] = useState<EventTypeCustomInput[]>(
|
||||||
eventType.customInputs.sort((a, b) => a.id - b.id) || []
|
eventType.customInputs.sort((a, b) => a.id - b.id) || []
|
||||||
);
|
);
|
||||||
|
@ -324,6 +324,7 @@ export const EventAdvancedTab = ({ eventType, team }: Pick<EventTypeSetupInfered
|
||||||
checked={seatsInputVisible}
|
checked={seatsInputVisible}
|
||||||
onCheckedChange={(e) => {
|
onCheckedChange={(e) => {
|
||||||
setSeatsInputVisible(e);
|
setSeatsInputVisible(e);
|
||||||
|
formMethods.setValue("seatsPerTimeSlot", seatsPerTimeSlot);
|
||||||
onChange(e ? seatsPerTimeSlot : null);
|
onChange(e ? seatsPerTimeSlot : null);
|
||||||
}}
|
}}
|
||||||
fitToHeight={true}
|
fitToHeight={true}
|
||||||
|
|
|
@ -327,20 +327,20 @@ async function handler(req: NextApiRequest) {
|
||||||
|
|
||||||
if (!users) throw new HttpError({ statusCode: 404, message: "eventTypeUser.notFound" });
|
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) {
|
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) {
|
if (eventType.schedulingType === SchedulingType.ROUND_ROBIN) {
|
||||||
users = [await getLuckyUser("MAXIMIZE_AVAILABILITY", { availableUsers, eventTypeId: eventType.id })];
|
users = [await getLuckyUser("MAXIMIZE_AVAILABILITY", { availableUsers, eventTypeId: eventType.id })];
|
||||||
} else {
|
} else {
|
||||||
|
|
Loading…
Reference in New Issue