fix: sort the availabilities based on start time for each day (#21656)
* sort the availabilities based on start time for each day * move the sorting outside the reduce * add guard variable for safe access --------- Co-authored-by: Kartik Saini <41051387+kart1ka@users.noreply.github.com>
This commit is contained in:
co-authored by
Kartik Saini
parent
108f95723b
commit
cd6293d220
@@ -31,7 +31,7 @@ export function transformDateOverridesForAtom(
|
||||
schedule: { availability: ScheduleOverride },
|
||||
timeZone: string
|
||||
) {
|
||||
return schedule.availability.reduce((acc, override) => {
|
||||
const acc = schedule.availability.reduce((acc, override) => {
|
||||
// only if future date override
|
||||
const currentUtcOffset = dayjs().tz(timeZone).utcOffset();
|
||||
const currentTimeInTz = dayjs().utc().add(currentUtcOffset, "minute");
|
||||
@@ -63,10 +63,17 @@ export function transformDateOverridesForAtom(
|
||||
acc[dayRangeIndex].ranges.push(newValue);
|
||||
return acc;
|
||||
}, [] as { ranges: TimeRange[] }[]);
|
||||
|
||||
acc.sort((a, b) => {
|
||||
const aTime = a.ranges?.[0]?.start?.getTime?.() ?? 0;
|
||||
const bTime = b.ranges?.[0]?.start?.getTime?.() ?? 0;
|
||||
return aTime - bTime;
|
||||
});
|
||||
return acc;
|
||||
}
|
||||
|
||||
export const transformScheduleToAvailabilityForAtom = (schedule: { availability: ScheduleAvailability }) => {
|
||||
return schedule.availability.reduce(
|
||||
const result = schedule.availability.reduce(
|
||||
(schedule: Schedule, availability) => {
|
||||
availability.days.forEach((day) => {
|
||||
schedule[day].push({
|
||||
@@ -94,4 +101,14 @@ export const transformScheduleToAvailabilityForAtom = (schedule: { availability:
|
||||
},
|
||||
Array.from([...Array(7)]).map(() => [])
|
||||
);
|
||||
|
||||
result.forEach((daySlots) => {
|
||||
daySlots.sort((a, b) => {
|
||||
const aTime = a?.start?.getTime?.() ?? 0;
|
||||
const bTime = b?.start?.getTime?.() ?? 0;
|
||||
return aTime - bTime;
|
||||
});
|
||||
});
|
||||
|
||||
return result;
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user