* migrate booker layout selector * move schedule hooks and types * migrate feature opt in components * migrate feedback dialog * update * migrate schedule hooks * migrate useSegments * update * update import paths * fix import paths * mv useTimesForSchedule back to features * fix
24 lines
600 B
TypeScript
24 lines
600 B
TypeScript
import { useMemo } from "react";
|
|
|
|
import type { Slots } from "../lib/types";
|
|
|
|
const getNonEmptyScheduleDays = (slots?: Slots) => {
|
|
if (typeof slots === "undefined") return [];
|
|
|
|
const nonEmptyDays: string[] = [];
|
|
|
|
Object.keys(slots).forEach((date) => {
|
|
if (slots[date].some((slot) => !(slot?.away && !slot.toUser && !slot.showNotePublicly) && slots[date].length > 0)) {
|
|
nonEmptyDays.push(date);
|
|
}
|
|
});
|
|
|
|
return nonEmptyDays;
|
|
};
|
|
|
|
export const useNonEmptyScheduleDays = (slots?: Slots) => {
|
|
const days = useMemo(() => getNonEmptyScheduleDays(slots), [slots]);
|
|
|
|
return days;
|
|
};
|