* fix: skip when browsing month has no available slots * Fix zustand error + add wip tests * Fix issue with using brows ingDate too early * Use slots instead of schedule return types to remove hard coupling to tRPC * Some await fixes + use type definition from extended core feature * Move useNextMonth to custom hook * Add unit tests to cover the next month scenario * Use changed interface, schedule -> slots,isLoading * Return no-op until ready
24 lines
590 B
TypeScript
24 lines
590 B
TypeScript
import { useMemo } from "react";
|
|
|
|
import type { Slots } from "../use-schedule/types";
|
|
|
|
export 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) && slots[date].length > 0)) {
|
|
nonEmptyDays.push(date);
|
|
}
|
|
});
|
|
|
|
return nonEmptyDays;
|
|
};
|
|
|
|
export const useNonEmptyScheduleDays = (slots?: Slots) => {
|
|
const days = useMemo(() => getNonEmptyScheduleDays(slots), [slots]);
|
|
|
|
return days;
|
|
};
|