2023-06-09 09:38:18 +00:00
|
|
|
import { shallow } from "zustand/shallow";
|
|
|
|
|
|
|
|
import dayjs from "@calcom/dayjs";
|
2023-06-13 11:08:00 +00:00
|
|
|
import { useTimePreferences } from "@calcom/features/bookings/lib";
|
2023-06-09 09:38:18 +00:00
|
|
|
import { classNames } from "@calcom/lib";
|
2022-12-14 13:36:10 +00:00
|
|
|
|
|
|
|
import { useCalendarStore } from "../../state/store";
|
2023-06-09 09:38:18 +00:00
|
|
|
import type { CalendarAvailableTimeslots } from "../../types/state";
|
2023-04-05 18:14:46 +00:00
|
|
|
import type { GridCellToDateProps } from "../../utils";
|
|
|
|
import { gridCellToDateTime } from "../../utils";
|
2022-12-14 13:36:10 +00:00
|
|
|
|
2023-06-09 09:38:18 +00:00
|
|
|
type EmptyCellProps = GridCellToDateProps & {
|
|
|
|
availableSlots?: CalendarAvailableTimeslots;
|
|
|
|
};
|
|
|
|
|
|
|
|
export function EmptyCell(props: EmptyCellProps) {
|
2023-06-13 11:08:00 +00:00
|
|
|
const timeFormat = useTimePreferences((state) => state.timeFormat);
|
2022-12-14 13:36:10 +00:00
|
|
|
const { onEmptyCellClick, hoverEventDuration } = useCalendarStore(
|
|
|
|
(state) => ({
|
|
|
|
onEmptyCellClick: state.onEmptyCellClick,
|
|
|
|
hoverEventDuration: state.hoverEventDuration,
|
|
|
|
}),
|
|
|
|
shallow
|
|
|
|
);
|
|
|
|
|
|
|
|
const cellToDate = gridCellToDateTime({
|
|
|
|
day: props.day,
|
|
|
|
gridCellIdx: props.gridCellIdx,
|
|
|
|
totalGridCells: props.totalGridCells,
|
|
|
|
selectionLength: props.selectionLength,
|
|
|
|
startHour: props.startHour,
|
|
|
|
});
|
|
|
|
|
2023-06-09 09:38:18 +00:00
|
|
|
// Empty cell won't show it self (be disabled) when
|
|
|
|
// availableslots is passed in, and it's curren time is not part of the available slots
|
|
|
|
const isDisabled =
|
|
|
|
props.availableSlots &&
|
|
|
|
!props.availableSlots[dayjs(props.day).format("YYYY-MM-DD")]?.find(
|
|
|
|
(slot) => slot.start.getTime() === cellToDate.toDate().getTime()
|
|
|
|
);
|
|
|
|
|
2022-12-14 13:36:10 +00:00
|
|
|
return (
|
|
|
|
<div
|
2023-06-09 09:38:18 +00:00
|
|
|
className={classNames(
|
2023-06-13 11:08:00 +00:00
|
|
|
"group flex w-full items-center justify-center",
|
2023-06-09 09:38:18 +00:00
|
|
|
isDisabled && "pointer-events-none",
|
|
|
|
!isDisabled && "bg-default dark:bg-muted"
|
|
|
|
)}
|
|
|
|
data-disabled={isDisabled}
|
|
|
|
data-day={props.day.toISOString()}
|
|
|
|
style={{ height: `calc(${hoverEventDuration}*var(--one-minute-height))`, overflow: "visible" }}
|
2022-12-14 13:36:10 +00:00
|
|
|
onClick={() => onEmptyCellClick && onEmptyCellClick(cellToDate.toDate())}>
|
2023-06-09 09:38:18 +00:00
|
|
|
{!isDisabled && hoverEventDuration !== 0 && (
|
2022-12-14 13:36:10 +00:00
|
|
|
<div
|
2023-06-09 09:38:18 +00:00
|
|
|
className="opacity-4 bg-subtle hover:bg-emphasis text-emphasis dark:border-emphasis absolute hidden
|
|
|
|
rounded-[4px]
|
|
|
|
border-[1px] border-gray-900 py-1 px-[6px] text-xs font-semibold leading-5 group-hover:block group-hover:cursor-pointer"
|
2022-12-14 13:36:10 +00:00
|
|
|
style={{
|
2023-06-13 11:08:00 +00:00
|
|
|
height: `calc(${hoverEventDuration}*var(--one-minute-height) - 2px)`,
|
2022-12-14 13:36:10 +00:00
|
|
|
zIndex: 49,
|
2023-06-09 09:38:18 +00:00
|
|
|
// @TODO: This used to be 90% as per Sean's work. I think this was needed when
|
|
|
|
// multiple events are stacked next to each other. We might need to add this back later.
|
2023-06-13 11:08:00 +00:00
|
|
|
width: "calc(100% - 2px)",
|
2022-12-14 13:36:10 +00:00
|
|
|
}}>
|
2023-06-13 11:08:00 +00:00
|
|
|
<div className=" overflow-ellipsis leading-4">{cellToDate.format(timeFormat)}</div>
|
2022-12-14 13:36:10 +00:00
|
|
|
</div>
|
|
|
|
)}
|
|
|
|
</div>
|
|
|
|
);
|
|
|
|
}
|