-
Notifications
You must be signed in to change notification settings - Fork 12k
feat: calendar view atom v1
#23840
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
feat: calendar view atom v1
#23840
Changes from all commits
Commits
Show all changes
23 commits
Select commit
Hold shift + click to select a range
b34864f
fix: refactor
Ryukemeister 962a984
add `isMonthViewProp` to header
Ryukemeister 31cfe82
feat: init v1 for calendar view atom
Ryukemeister 0029a58
Merge branch 'main' into calendar-view-atom-v1
Ryukemeister f522e3d
Merge branch 'main' into calendar-view-atom-v1
Ryukemeister fcec72f
Merge branch 'main' into calendar-view-atom-v1
Ryukemeister 5a8e0bf
Merge branch 'main' into calendar-view-atom-v1
Ryukemeister 6cd88ea
test breaking toggle buttons
Ryukemeister 1400eac
fix: make sure week start is always sunday for calendar view atom
Ryukemeister 6127bbe
fixup
Ryukemeister 7412a63
Merge branch 'main' into calendar-view-atom-v1
Ryukemeister cff8138
fix: remove extra comments
Ryukemeister 6552d1a
fix: add calendar view page in examples app
Ryukemeister 7550a4b
Merge branch 'main' into calendar-view-atom-v1
Ryukemeister df4b2d6
chore: add changesets
Ryukemeister 575f129
fix: coderabbit feedback
Ryukemeister f50d616
Merge branch 'main' into calendar-view-atom-v1
Ryukemeister c07a72b
fixup
Ryukemeister adfb52d
Merge branch 'main' into calendar-view-atom-v1
Ryukemeister 6dc26b4
Merge branch 'main' into calendar-view-atom-v1
Ryukemeister d65d2bb
Merge branch 'main' into calendar-view-atom-v1
Ryukemeister c940118
fix: import path
Ryukemeister 41d54d1
fix: `customReplyToEmail` breaking
Ryukemeister File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| --- | ||
| "@calcom/atoms": minor | ||
| --- | ||
|
|
||
| This PR adds a new atom called `CalendarView` which is a read only calendar view component for a user. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
30 changes: 30 additions & 0 deletions
30
packages/features/bookings/Booker/components/hooks/useAvailableTimeSlots.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,30 @@ | ||
| import { useMemo } from "react"; | ||
|
|
||
| import dayjs from "@calcom/dayjs"; | ||
| import type { CalendarAvailableTimeslots } from "@calcom/features/calendars/weeklyview/types/state"; | ||
| import type { IGetAvailableSlots } from "@calcom/trpc/server/routers/viewer/slots/util"; | ||
|
|
||
| interface UseAvailableTimeSlotsProps { | ||
| eventDuration: number; | ||
| schedule?: IGetAvailableSlots; | ||
| } | ||
|
|
||
| export const useAvailableTimeSlots = ({ schedule, eventDuration }: UseAvailableTimeSlotsProps) => { | ||
| return useMemo(() => { | ||
| const availableTimeslots: CalendarAvailableTimeslots = {}; | ||
| if (!schedule || !schedule.slots) return availableTimeslots; | ||
|
|
||
| for (const day in schedule.slots) { | ||
| availableTimeslots[day] = schedule.slots[day].map((slot) => { | ||
| const { time, ...rest } = slot; | ||
| return { | ||
| start: dayjs(time).toDate(), | ||
| end: dayjs(time).add(eventDuration, "minutes").toDate(), | ||
| ...rest, | ||
| }; | ||
| }); | ||
| } | ||
|
|
||
| return availableTimeslots; | ||
| }, [schedule, eventDuration]); | ||
| }; |
17 changes: 17 additions & 0 deletions
17
packages/features/bookings/Booker/components/hooks/useInitializeWeekStart.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,17 @@ | ||
| import { useEffect } from "react"; | ||
|
|
||
| import dayjs from "@calcom/dayjs"; | ||
| import { useBookerStoreContext } from "@calcom/features/bookings/Booker/BookerStoreProvider"; | ||
|
|
||
| export const useInitializeWeekStart = (isPlatform: boolean, isCalendarView: boolean) => { | ||
| const today = dayjs(); | ||
| const weekStart = today.startOf("week").format("YYYY-MM-DD"); | ||
| const setSelectedDate = useBookerStoreContext((state) => state.setSelectedDate); | ||
|
|
||
| useEffect(() => { | ||
| if (isPlatform && isCalendarView) { | ||
| setSelectedDate({ date: weekStart, omitUpdatingParams: true }); | ||
| } | ||
| // eslint-disable-next-line react-hooks/exhaustive-deps | ||
| }, []); | ||
| }; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,79 @@ | ||
| import { useMemo, useEffect } from "react"; | ||
|
|
||
| import dayjs from "@calcom/dayjs"; | ||
| import { useBookerStoreContext } from "@calcom/features/bookings/Booker/BookerStoreProvider"; | ||
| import { useAvailableTimeSlots } from "@calcom/features/bookings/Booker/components/hooks/useAvailableTimeSlots"; | ||
| import type { BookerEvent } from "@calcom/features/bookings/types"; | ||
| import { Calendar } from "@calcom/features/calendars/weeklyview"; | ||
| import type { CalendarEvent } from "@calcom/features/calendars/weeklyview/types/events"; | ||
| import { localStorage } from "@calcom/lib/webstorage"; | ||
|
|
||
| import { useOverlayCalendarStore } from "../bookings/Booker/components/OverlayCalendar/store"; | ||
| import type { useScheduleForEventReturnType } from "../bookings/Booker/utils/event"; | ||
| import { getQueryParam } from "../bookings/Booker/utils/query-param"; | ||
|
|
||
| export const LargeCalendar = ({ | ||
| extraDays, | ||
| schedule, | ||
| isLoading, | ||
| event, | ||
| }: { | ||
| extraDays: number; | ||
| schedule?: useScheduleForEventReturnType["data"]; | ||
| isLoading: boolean; | ||
| event: { | ||
| data?: Pick<BookerEvent, "length"> | null; | ||
| }; | ||
| }) => { | ||
| const selectedDate = useBookerStoreContext((state) => state.selectedDate); | ||
| const selectedEventDuration = useBookerStoreContext((state) => state.selectedDuration); | ||
| const overlayEvents = useOverlayCalendarStore((state) => state.overlayBusyDates); | ||
| const displayOverlay = | ||
| getQueryParam("overlayCalendar") === "true" || localStorage?.getItem("overlayCalendarSwitchDefault"); | ||
|
|
||
| const eventDuration = selectedEventDuration || event?.data?.length || 30; | ||
|
|
||
| const availableSlots = useAvailableTimeSlots({ schedule, eventDuration }); | ||
|
|
||
| const startDate = selectedDate ? dayjs(selectedDate).toDate() : dayjs().toDate(); | ||
| const endDate = dayjs(startDate) | ||
| .add(extraDays - 1, "day") | ||
| .toDate(); | ||
|
|
||
| // HACK: force rerender when overlay events change | ||
| // Sine we dont use react router here we need to force rerender (ATOM SUPPORT) | ||
| // eslint-disable-next-line @typescript-eslint/no-empty-function | ||
| useEffect(() => {}, [displayOverlay]); | ||
|
|
||
| const overlayEventsForDate = useMemo(() => { | ||
| if (!overlayEvents || !displayOverlay) return []; | ||
| return overlayEvents.map((event, id) => { | ||
| return { | ||
| id, | ||
| start: dayjs(event.start).toDate(), | ||
| end: dayjs(event.end).toDate(), | ||
| title: "Busy", | ||
| options: { | ||
| status: "ACCEPTED", | ||
| }, | ||
| } as CalendarEvent; | ||
| }); | ||
| }, [overlayEvents, displayOverlay]); | ||
|
|
||
| return ( | ||
| <div className="h-full [--calendar-dates-sticky-offset:66px]"> | ||
| <Calendar | ||
| isPending={isLoading} | ||
| availableTimeslots={availableSlots} | ||
| startHour={0} | ||
| endHour={23} | ||
| events={overlayEventsForDate} | ||
| startDate={startDate} | ||
| endDate={endDate} | ||
| gridCellsPerHour={60 / eventDuration} | ||
| hoverEventDuration={eventDuration} | ||
| hideHeader | ||
| /> | ||
| </div> | ||
| ); | ||
| }; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| export { CalendarViewPlatformWrapper } from "./wrappers/CalendarViewPlatformWrapper"; |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🛠️ Refactor suggestion
🧩 Analysis chain
Remove file‑wide exhaustive‑deps disable; scope it to specific hooks.
A blanket disable can hide stale-closure bugs across this hook-heavy file. Prefer fixing deps or narrowly disabling per‑hook (you already do this in a few places).
Apply:
-/* eslint-disable react-hooks/exhaustive-deps */Run to audit where we still rely on blanket vs scoped disables:
🏁 Script executed:
Length of output: 2023
Remove file-wide
eslint-disable react-hooks/exhaustive-deps. Scoped disables already cover the five specific hooks at lines 153, 158, 231, 468, and 490—drop the blanket disable at the top.-/* eslint-disable react-hooks/exhaustive-deps */📝 Committable suggestion
🤖 Prompt for AI Agents