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, timezone: props.timezone, }); const minuesFromStart = (cellToDate.hour() - props.startHour) * 60 + cellToDate.minute(); return ; } type AvailableCellProps = { availableSlots: CalendarAvailableTimeslots; day: GridCellToDateProps["day"]; startHour: GridCellToDateProps["startHour"]; }; export function AvailableCellsForDay({ availableSlots, day, startHour }: AvailableCellProps) { const { timezone } = useTimePreferences(); const slotsForToday = availableSlots && availableSlots[dayjs(day).format("YYYY-MM-DD")]; const slots = useMemo( () => slotsForToday?.map((slot) => ({ slot, topOffsetMinutes: (dayjs(slot.start).tz(timezone).hour() - startHour) * 60 + dayjs(slot.start).tz(timezone).minute(), })), [slotsForToday, startHour, timezone] ); if (!availableSlots) return null; return ( <> {slots?.map((slot, index) => { return ( ); })} ); } type CellProps = { isDisabled?: boolean; topOffsetMinutes?: number; timeSlot: Dayjs; }; function Cell({ isDisabled, topOffsetMinutes, timeSlot }: CellProps) { const { timeFormat } = useTimePreferences(); const { onEmptyCellClick, hoverEventDuration } = useCalendarStore( (state) => ({ onEmptyCellClick: state.onEmptyCellClick, hoverEventDuration: state.hoverEventDuration, }), shallow ); return (
{ onEmptyCellClick && onEmptyCellClick(timeSlot.toDate()); }}> {!isDisabled && hoverEventDuration !== 0 && ( )}
); }