* feat: implement booking calendar view with weekly layout - Create reusable WeekCalendarView component that displays bookings in a weekly calendar format - Replace EmptyScreen in BookingsCalendar with the new calendar view - Calendar view includes: - Week navigation with Today, Previous, and Next buttons - 7-day week view with time slots from 12 AM to 11 PM - Bookings displayed as colored blocks positioned by time - Support for event type colors and status-based colors - Responsive design that fills the viewport - Hover tooltips showing booking details - Filters remain functional at the top of the view Co-Authored-By: [email protected] <[email protected]> * refactor: use existing Calendar component from weeklyview - Replace custom calendar implementation with the existing Calendar component - Use parseEventTypeColor to properly handle event type colors - Simplify implementation by leveraging existing calendar infrastructure - Maintain week navigation and filtering functionality Co-Authored-By: [email protected] <[email protected]> * fix imports * fix: replace isSameOrAfter with isAfter || isSame - isSameOrAfter method does not exist in dayjs - Use combination of isAfter and isSame instead Co-Authored-By: [email protected] <[email protected]> * remove useBookerTime dependency from weekly calendar view * modify date range filters * initial callback * sort events * clean up FilterBar * add showBackgroundPattern * update styles * update style * update styles * fix type error * fix error * update styles * update styles * update event colors * rename component * persist weekStart on the url * use FilterBar * apply feedback * extract BorderColor type * use client * clean up * adjust styles * color-code events * rename borderColor to color * restore class name * add feature flag * update class name --------- Co-authored-by: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
85 lines
2.8 KiB
TypeScript
85 lines
2.8 KiB
TypeScript
import { create } from "zustand";
|
|
|
|
import dayjs from "@calcom/dayjs";
|
|
import { CURRENT_TIMEZONE } from "@calcom/lib/timezoneConstants";
|
|
|
|
import type {
|
|
CalendarComponentProps,
|
|
CalendarPublicActions,
|
|
CalendarState,
|
|
CalendarStoreProps,
|
|
} from "../types/state";
|
|
import { mergeOverlappingDateRanges, weekdayDates } from "../utils";
|
|
|
|
const defaultState: CalendarComponentProps = {
|
|
view: "week",
|
|
startDate: weekdayDates(0, new Date()).startDate,
|
|
endDate: weekdayDates(0, new Date()).endDate,
|
|
events: [],
|
|
startHour: 0,
|
|
endHour: 23,
|
|
gridCellsPerHour: 4,
|
|
timezone: CURRENT_TIMEZONE,
|
|
showBackgroundPattern: true,
|
|
showBorder: true,
|
|
borderColor: "default",
|
|
};
|
|
|
|
export const useCalendarStore = create<CalendarStoreProps>((set) => ({
|
|
...defaultState,
|
|
setView: (view: CalendarComponentProps["view"]) => set({ view }),
|
|
setStartDate: (startDate: CalendarComponentProps["startDate"]) => set({ startDate }),
|
|
setEndDate: (endDate: CalendarComponentProps["endDate"]) => set({ endDate }),
|
|
setEvents: (events: CalendarComponentProps["events"]) => set({ events }),
|
|
// This looks a bit odd but init state only overrides the public props + actions as we don't want to override our internal state
|
|
initState: (state: CalendarState & CalendarPublicActions) => {
|
|
// Handle sorting of events if required
|
|
let events = state.events;
|
|
|
|
if (state.sortEvents) {
|
|
events = state.events.sort((a, b) => dayjs(a.start).valueOf() - dayjs(b.start).valueOf());
|
|
}
|
|
const blockingDates = mergeOverlappingDateRanges(state.blockingDates || []); // We merge overlapping dates so we don't get duplicate blocking "Cells" in the UI
|
|
|
|
set({
|
|
...state,
|
|
blockingDates,
|
|
events,
|
|
});
|
|
},
|
|
setSelectedEvent: (event) => set({ selectedEvent: event }),
|
|
handleDateChange: (payload) =>
|
|
set((state) => {
|
|
const { startDate, endDate } = state;
|
|
if (payload === "INCREMENT") {
|
|
const newStartDate = dayjs(startDate).add(1, state.view).toDate();
|
|
const newEndDate = dayjs(endDate).add(1, state.view).toDate();
|
|
|
|
// Do nothing if
|
|
if (
|
|
(state.minDate && newStartDate < state.minDate) ||
|
|
(state.maxDate && newEndDate > state.maxDate)
|
|
) {
|
|
return {
|
|
startDate,
|
|
endDate,
|
|
};
|
|
}
|
|
|
|
// We call this callback if we have it -> Allows you to change your state outside of the component
|
|
state.onDateChange?.(newStartDate, newEndDate);
|
|
return {
|
|
startDate: newStartDate,
|
|
endDate: newEndDate,
|
|
};
|
|
}
|
|
const newStartDate = dayjs(startDate).subtract(1, state.view).toDate();
|
|
const newEndDate = dayjs(endDate).subtract(1, state.view).toDate();
|
|
state.onDateChange?.(newStartDate, newEndDate);
|
|
return {
|
|
startDate: newStartDate,
|
|
endDate: newEndDate,
|
|
};
|
|
}),
|
|
}));
|