calcom / cal.com

Scheduling infrastructure for absolutely everyone.
https://cal.com
Other
32.42k stars 8k forks source link

[CAL-3891] Availability overrides on current day do not show up in availability or slots #15250

Open joelweight opened 5 months ago

joelweight commented 5 months ago

Issue Summary

User is unable to add availability override on the current day. If you attempt to add availability it will appear to succeed. If you hit "save" on the override page it will also appear to succeed, and is actually saved, but if you then reload the availability page, it will be culled by a bug on line 41 of transformers.js which is looking at day granularity instead of looking at minute granularity.

Steps to Reproduce

  1. Go to user availability
  2. Add an override for TODAY at a time after current time
  3. Save override (close the popup and also hit "save" in the top right corner
  4. Note that at this point the override is save.
  5. Refresh the availability page and notice that the new availability override is gone.

Any other relevant information. For example, why do you consider this a bug and what did you expect to happen instead?

Actual Results

Expected Results

Technical details

Loom simple demo of the problem. Note: I am adding availability override for TODAY.

https://www.loom.com/share/3bbcbfe3d8c94159a52f96f7e2b5fc25?sid=3c4e2db6-b214-48fa-8b11-5fec10c0d4df

The problem is in transformers.js line 41. It is looking at the override from a "day" perspective instead of from a "minute" perspective.

Evidence

https://www.loom.com/share/3bbcbfe3d8c94159a52f96f7e2b5fc25?sid=3c4e2db6-b214-48fa-8b11-5fec10c0d4df

CAL-3891

dosubot[bot] commented 5 months ago

Hey there, @joelweight! I'm Dosu, a bot here to help you with bug fixes, questions, and becoming a contributor. I'm ready to assist you with the issue you've posted.

To fix the bug in transformers.js at line 41 that prevents same-day availability overrides from being saved and displayed correctly, you need to modify the transformDateOverridesForClient function. The issue likely stems from the condition that checks if the override date is in the future, which prevents same-day overrides from being processed.

Here's the corrected function:

export function transformDateOverridesForClient(schedule: ScheduleWithAvailabilities, timeZone: string) {
  return schedule.availability.reduce((acc, override) => {
    // Allow same-day overrides by changing the condition to include the current day
    if (!override.date || dayjs.tz(override.date, timeZone).isBefore(dayjs(), "day")) {
      return acc;
    }
    const newValue = {
      start: dayjs
        .utc(override.date)
        .hour(override.startTime.getUTCHours())
        .minute(override.startTime.getUTCMinutes())
        .toDate(),
      end: dayjs
        .utc(override.date)
        .hour(override.endTime.getUTCHours())
        .minute(override.endTime.getUTCMinutes())
        .toDate(),
    };
    const dayRangeIndex = acc.findIndex(
      // early return prevents override.date from ever being empty.
      // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
      (item) => yyyymmdd(item.ranges[0].start) === yyyymmdd(override.date!)
    );
    if (dayRangeIndex === -1) {
      acc.push({ ranges: [newValue] });
      return acc;
    }
    acc[dayRangeIndex].ranges.push(newValue);
    return acc;
  }, [] as { ranges: TimeRange[] }[]);
}

The key change is in the condition that checks if the override date is in the future. By modifying this condition to include the current day, same-day availability overrides will be processed correctly [1].

#### Details **About Dosu** This response is meant to be useful and save you time. It is **not meant to be a precise solution**, but rather a starting point for your own research. Help me be more useful! Please leave a 👍 if this is helpful and 👎 if it is irrelevant.

To continue the conversation, mention @dosu.

xcellentavi commented 15 hours ago

Also experiencing this issue with same-day overrides. Currently running v4.6.14. It works on booking calendars, but not showing up if you refresh Date overrides in the settings.