import { useMemo } from "react"; import { shallow } from "zustand/shallow"; import type { Dayjs } from "@calcom/dayjs"; import dayjs from "@calcom/dayjs"; import { useTimePreferences } from "@calcom/features/bookings/lib"; import { classNames } from "@calcom/lib"; import { useCalendarStore } from "../../state/store"; import type { CalendarAvailableTimeslots } from "../../types/state"; import type { GridCellToDateProps } from "../../utils"; import { gridCellToDateTime } from "../../utils"; type EmptyCellProps = GridCellToDateProps & { isDisabled?: boolean; topOffsetMinutes?: number; }; export function EmptyCell(props: EmptyCellProps) { const cellToDate = gridCellToDateTime({ day: props.day, gridCellIdx: props.gridCellIdx, totalGridCells: props.totalGridCells, selectionLength: props.selectionLength, startHour: props.startHour, }); const minuesFromStart = (cellToDate.toDate().getHours() - props.startHour) * 60 + cellToDate.toDate().getMinutes(); return ; } type AvailableCellProps = { availableSlots: CalendarAvailableTimeslots; day: GridCellToDateProps["day"]; startHour: GridCellToDateProps["startHour"]; }; export function AvailableCellsForDay({ availableSlots, day, startHour }: AvailableCellProps) { const slotsForToday = availableSlots && availableSlots[dayjs(day).format("YYYY-MM-DD")]; const slots = useMemo( () => slotsForToday?.map((slot) => ({ slot, topOffsetMinutes: (slot.start.getHours() - startHour) * 60 + slot.start.getMinutes(), })), [slotsForToday, startHour] ); if (!availableSlots) return null; return ( <> {slots?.map((slot) => { return ( ); })} ); } type CellProps = { isDisabled?: boolean; topOffsetMinutes?: number; timeSlot: Dayjs; }; function Cell({ isDisabled, topOffsetMinutes, timeSlot }: CellProps) { const timeFormat = useTimePreferences((state) => state.timeFormat); const { onEmptyCellClick, hoverEventDuration } = useCalendarStore( (state) => ({ onEmptyCellClick: state.onEmptyCellClick, hoverEventDuration: state.hoverEventDuration, }), shallow ); return (
onEmptyCellClick && onEmptyCellClick(timeSlot.toDate())}> {!isDisabled && hoverEventDuration !== 0 && ( )}
); }