-
Notifications
You must be signed in to change notification settings - Fork 12k
fix: Platform Prefetch for slots due to NaN != NaN issue #23913
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
Changes from all commits
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,56 @@ | ||
| import dayjs from "@calcom/dayjs"; | ||
| import type { BookerState } from "@calcom/features/bookings/Booker/types"; | ||
| import { BookerLayouts } from "@calcom/prisma/zod-utils"; | ||
|
|
||
| interface UsePrefetchParams { | ||
| date: string; | ||
| month: string | null; | ||
| bookerLayout: { | ||
| layout: string; | ||
| extraDays: number; | ||
| columnViewExtraDays: { current: number }; | ||
| }; | ||
| bookerState: BookerState; | ||
| } | ||
|
|
||
| export const usePrefetch = ({ date, month, bookerLayout, bookerState }: UsePrefetchParams) => { | ||
| const dateMonth = dayjs(date).month(); | ||
| const monthAfterAdding1Month = dayjs(date).add(1, "month").month(); | ||
| const monthAfterAddingExtraDays = dayjs(date).add(bookerLayout.extraDays, "day").month(); | ||
| const monthAfterAddingExtraDaysColumnView = dayjs(date) | ||
| .add(bookerLayout.columnViewExtraDays.current, "day") | ||
| .month(); | ||
|
|
||
coderabbitai[bot] marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| const isValidDate = dayjs(date).isValid(); | ||
| const twoWeeksAfter = dayjs(month).startOf("month").add(2, "week"); | ||
| const isSameMonth = dayjs().isSame(dayjs(month), "month"); | ||
| const isAfter2Weeks = dayjs().isAfter(twoWeeksAfter); | ||
|
|
||
| const prefetchNextMonth = | ||
| (bookerLayout.layout === BookerLayouts.WEEK_VIEW && | ||
| !!bookerLayout.extraDays && | ||
| !isNaN(dateMonth) && | ||
| !isNaN(monthAfterAddingExtraDays) && | ||
| dateMonth !== monthAfterAddingExtraDays) || | ||
| (bookerLayout.layout === BookerLayouts.COLUMN_VIEW && | ||
| !isNaN(dateMonth) && | ||
| !isNaN(monthAfterAddingExtraDaysColumnView) && | ||
| dateMonth !== monthAfterAddingExtraDaysColumnView) || | ||
|
Comment on lines
+32
to
+38
Member
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. Added these NaN checks as well because the root cause is that date string itself could be invalid causing the issue with all other derived variables from it. I will be adding unit tests for it in a followup and then this could be simplified when needed, ideally we return early when such a situation arise instead of having NaN checks everywhere
Member
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. |
||
| ((bookerLayout.layout === BookerLayouts.MONTH_VIEW || bookerLayout.layout === "mobile") && | ||
| (!isValidDate || isSameMonth) && | ||
| isAfter2Weeks); | ||
|
|
||
| const monthCount = | ||
| ((bookerLayout.layout !== BookerLayouts.WEEK_VIEW && bookerState === "selecting_time") || | ||
| bookerLayout.layout === BookerLayouts.COLUMN_VIEW) && | ||
| !isNaN(monthAfterAdding1Month) && | ||
| !isNaN(monthAfterAddingExtraDaysColumnView) && | ||
| monthAfterAdding1Month !== monthAfterAddingExtraDaysColumnView | ||
| ? 2 | ||
| : undefined; | ||
hariombalhara marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| return { | ||
| prefetchNextMonth, | ||
| monthCount, | ||
| }; | ||
| }; | ||
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.
we should use useMemo here, so that the references to prefetchNextMonth,
monthCount change only when date, month, bookerLayout, bookerState change