-
Notifications
You must be signed in to change notification settings - Fork 12k
feat: upcoming bookings atom #24010
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
feat: upcoming bookings atom #24010
Changes from all commits
b96460c
873d79d
b5da583
4d51bbb
a386547
21a94d1
2ae295c
e53b366
c718096
fc70e03
0c7e098
f79d943
87d0a53
a07a0f9
3eb7551
1b65fa6
d5420e2
c262d3c
bbef2a1
3ff1eec
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| --- | ||
| "@calcom/atoms": minor | ||
| --- | ||
|
|
||
| This PR adds ability to display bookings of a user event for calendar view atom |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,14 +1,14 @@ | ||
| import { useMemo, useEffect } from "react"; | ||
| import { useEffect, useMemo } 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 type { BookingStatus } from "@calcom/prisma/enums"; | ||
|
|
||
| import { useOverlayCalendarStore } from "../bookings/Booker/components/OverlayCalendar/store"; | ||
| import { useBookings } from "../../platform/atoms/hooks/bookings/useBookings"; | ||
| import type { useScheduleForEventReturnType } from "../bookings/Booker/utils/event"; | ||
| import { getQueryParam } from "../bookings/Booker/utils/query-param"; | ||
|
|
||
|
|
@@ -22,12 +22,11 @@ export const LargeCalendar = ({ | |
| schedule?: useScheduleForEventReturnType["data"]; | ||
| isLoading: boolean; | ||
| event: { | ||
| data?: Pick<BookerEvent, "length"> | null; | ||
| data?: Pick<BookerEvent, "length" | "id"> | 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"); | ||
|
|
||
|
|
@@ -40,25 +39,38 @@ export const LargeCalendar = ({ | |
| .add(extraDays - 1, "day") | ||
| .toDate(); | ||
|
|
||
| const { data: upcomingBookings } = useBookings({ | ||
| take: 150, | ||
| skip: 0, | ||
| status: ["upcoming", "past", "recurring"], | ||
| eventTypeId: event?.data?.id, | ||
| afterStart: startDate.toISOString(), | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Question - the start and end dates here refer to 1 week or we would fetch for whole month?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
for 1 week because, that way we reduce the load to the server and only fetch data that's needed, which the user clicks the next week button that's when we fetch bookings for that particular the user is on
hmm not sure here, should we increase the number of bookings then to 150? I think ideally its really hard to have 150 bookings for just for one week, what do you think about this?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. updated bookings fetch count to 150 |
||
| beforeEnd: endDate.toISOString(), | ||
| }); | ||
|
|
||
| // 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) => { | ||
| if (!upcomingBookings) return []; | ||
|
|
||
| return upcomingBookings?.map((booking) => { | ||
| return { | ||
| id, | ||
| start: dayjs(event.start).toDate(), | ||
| end: dayjs(event.end).toDate(), | ||
| title: "Busy", | ||
| id: booking.id, | ||
| title: booking.title ?? `Busy`, | ||
| start: new Date(booking.start), | ||
|
Comment on lines
+62
to
+63
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🛠️ Refactor suggestion | 🟠 Major Localize the “Busy” label. Frontend strings should be wrapped with As per coding guidelines |
||
| end: new Date(booking.end), | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why are we switching to
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. no real reason tbh, just for consistency with trouble shooter component here for consistency |
||
| options: { | ||
| status: "ACCEPTED", | ||
| borderColor: "black", | ||
| status: booking.status.toUpperCase() as BookingStatus, | ||
| "data-test-id": "troubleshooter-busy-event", | ||
| className: "border-[1.5px]", | ||
| }, | ||
| } as CalendarEvent; | ||
| }; | ||
| }); | ||
| }, [overlayEvents, displayOverlay]); | ||
| }, [upcomingBookings]); | ||
|
|
||
| return ( | ||
| <div className="h-full [--calendar-dates-sticky-offset:66px]"> | ||
|
|
||
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.
Fix table column delimiters.
The
usernamerow now has two extra|delimiters, which breaks the three-column layout when rendered. Please drop the trailing separators so the table stays well-formed.📝 Committable suggestion
🤖 Prompt for AI Agents