Fix/Round Robin (#6121)
* Identify owner for a timeslot and check busyness against his schedule only * Fix TS errors * Fix flatmap * Fix xisting unit tests * Prevent duplicate slots by merging, userId -> userIds (multi) * Small fix to potential undefined * Moved duplicate prevention to buildSlots function * Apply date override on a per user basis * Prevent -1 being added to computedLocalAvailability * Removed console.log * Apply override properly on COLLECTIVE * Default timeZone to UTC when undefined * isSame doesn't work when the day shifts, isBetween instead * Iterate over all slot.userIds schedules to identify the first user schedule that matches * add round-robin test Co-authored-by: Alex van Andel <[email protected]> Co-authored-by: Peer Richelsen <[email protected]>
This commit is contained in:
10 files changed
+221
-87
No files matched your search
@@ -101,7 +101,8 @@ const AvailableTimes: FC<AvailableTimesProps> = ({
|
||||
}
|
||||
|
||||
return (
|
||||
<div key={dayjs(slot.time).format()}>
|
||||
<div data-slot-owner={(slot.userIds || []).join(",")} key={`${dayjs(slot.time).format()}`}>
|
||||
{/* ^ data-slot-owner is helpful in debugging and used to identify the owners of the slot. Owners are the users which have the timeslot in their schedule. It doesn't consider if a user has that timeslot booked */}
|
||||
{/* Current there is no way to disable Next.js Links */}
|
||||
{seatsPerTimeSlot && slot.attendees && slot.attendees >= seatsPerTimeSlot ? (
|
||||
<div
|
||||
|
||||
@@ -8,17 +8,17 @@ MockDate.set("2021-06-20T11:59:59Z");
|
||||
const HAWAII_AND_NEWYORK_TEAM = [
|
||||
{
|
||||
timeZone: "America/Detroit", // GMT -4 per 22th of Aug, 2022
|
||||
workingHours: [{ days: [1, 2, 3, 4, 5], startTime: 780, endTime: 1260 }],
|
||||
workingHours: [{ userId: 1, days: [1, 2, 3, 4, 5], startTime: 780, endTime: 1260 }],
|
||||
busy: [],
|
||||
dateOverrides: [],
|
||||
},
|
||||
{
|
||||
timeZone: "Pacific/Honolulu", // GMT -10 per 22th of Aug, 2022
|
||||
workingHours: [
|
||||
{ days: [3, 4, 5], startTime: 0, endTime: 360 },
|
||||
{ days: [6], startTime: 0, endTime: 180 },
|
||||
{ days: [2, 3, 4], startTime: 780, endTime: 1439 },
|
||||
{ days: [5], startTime: 780, endTime: 1439 },
|
||||
{ userId: 1, days: [3, 4, 5], startTime: 0, endTime: 360 },
|
||||
{ userId: 2, days: [6], startTime: 0, endTime: 180 },
|
||||
{ userId: 3, days: [2, 3, 4], startTime: 780, endTime: 1439 },
|
||||
{ userId: 4, days: [5], startTime: 780, endTime: 1439 },
|
||||
],
|
||||
busy: [],
|
||||
dateOverrides: [],
|
||||
@@ -44,6 +44,7 @@ it("Sydney and Shiraz can live in harmony 🙏", async () => {
|
||||
],
|
||||
"endTime": 180,
|
||||
"startTime": 0,
|
||||
"userId": 2,
|
||||
},
|
||||
Object {
|
||||
"days": Array [
|
||||
@@ -63,4 +64,57 @@ it("Sydney and Shiraz can live in harmony 🙏", async () => {
|
||||
},
|
||||
]
|
||||
`);
|
||||
|
||||
expect(getAggregateWorkingHours(HAWAII_AND_NEWYORK_TEAM, "ROUND_ROBIN")).toMatchInlineSnapshot(`
|
||||
Array [
|
||||
Object {
|
||||
"days": Array [
|
||||
1,
|
||||
2,
|
||||
3,
|
||||
4,
|
||||
5,
|
||||
],
|
||||
"endTime": 1260,
|
||||
"startTime": 780,
|
||||
"userId": 1,
|
||||
},
|
||||
Object {
|
||||
"days": Array [
|
||||
3,
|
||||
4,
|
||||
5,
|
||||
],
|
||||
"endTime": 360,
|
||||
"startTime": 0,
|
||||
"userId": 1,
|
||||
},
|
||||
Object {
|
||||
"days": Array [
|
||||
6,
|
||||
],
|
||||
"endTime": 180,
|
||||
"startTime": 0,
|
||||
"userId": 2,
|
||||
},
|
||||
Object {
|
||||
"days": Array [
|
||||
2,
|
||||
3,
|
||||
4,
|
||||
],
|
||||
"endTime": 1439,
|
||||
"startTime": 780,
|
||||
"userId": 3,
|
||||
},
|
||||
Object {
|
||||
"days": Array [
|
||||
5,
|
||||
],
|
||||
"endTime": 1439,
|
||||
"startTime": 780,
|
||||
"userId": 4,
|
||||
},
|
||||
]
|
||||
`);
|
||||
});
|
||||
@@ -18,6 +18,7 @@ describe("Tests the slot logic", () => {
|
||||
minimumBookingNotice: 0,
|
||||
workingHours: [
|
||||
{
|
||||
userId: 1,
|
||||
days: Array.from(Array(7).keys()),
|
||||
startTime: MINUTES_DAY_START,
|
||||
endTime: MINUTES_DAY_END,
|
||||
@@ -38,6 +39,7 @@ describe("Tests the slot logic", () => {
|
||||
minimumBookingNotice: 0,
|
||||
workingHours: [
|
||||
{
|
||||
userId: 1,
|
||||
days: Array.from(Array(7).keys()),
|
||||
startTime: MINUTES_DAY_START,
|
||||
endTime: MINUTES_DAY_END,
|
||||
@@ -56,6 +58,7 @@ describe("Tests the slot logic", () => {
|
||||
minimumBookingNotice: 0,
|
||||
workingHours: [
|
||||
{
|
||||
userId: 1,
|
||||
days: [0],
|
||||
startTime: 23 * 60, // 23h
|
||||
endTime: MINUTES_DAY_END,
|
||||
@@ -69,6 +72,7 @@ describe("Tests the slot logic", () => {
|
||||
it("can cut off dates that due to invitee timezone differences fall on the previous day", async () => {
|
||||
const workingHours = [
|
||||
{
|
||||
userId: 1,
|
||||
days: [0],
|
||||
startTime: MINUTES_DAY_START,
|
||||
endTime: 1 * 60, // 1h
|
||||
@@ -94,6 +98,7 @@ describe("Tests the slot logic", () => {
|
||||
minimumBookingNotice: 1500,
|
||||
workingHours: [
|
||||
{
|
||||
userId: 1,
|
||||
days: Array.from(Array(7).keys()),
|
||||
startTime: MINUTES_DAY_START,
|
||||
endTime: MINUTES_DAY_END,
|
||||
|
||||
Reference in new issue
Block a user