-
Notifications
You must be signed in to change notification settings - Fork 12k
refactor: improve most booked & least booked #23192
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
Changes from all commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
f94b29d
refactor: improve most booked & least booked
bandhan-majumder 4cec63e
add 2 new charts and trpc handlers
bandhan-majumder 09ab971
update arg
bandhan-majumder 5f0c3c4
update comment
bandhan-majumder fbaf2ed
completed booking filter
bandhan-majumder 3d52c49
update
bandhan-majumder 39c6ca4
Merge branch 'main' into fix-23176-chart
bandhan-majumder 1959603
add change in component level and remove unused translations
bandhan-majumder c5e21ac
current time and accepted status logic handler
bandhan-majumder b719cbe
resize some charts
eunjae-lee cd17408
Merge branch 'main' into fix-23176-chart
eunjae-lee 9bb5eda
restore some i18n
eunjae-lee 3ad481d
M/erge branch 'fix-23176-chart' of github.com:bandhan-majumder/cal.co…
eunjae-lee 66cde51
restore i18n
eunjae-lee bcf4b62
restore i18n
eunjae-lee 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
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
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
51 changes: 51 additions & 0 deletions
51
packages/features/insights/components/booking/LeastCompletedBookings.tsx
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,51 @@ | ||
| "use client"; | ||
|
|
||
| import { useMemo } from "react"; | ||
|
|
||
| import dayjs from "@calcom/dayjs"; | ||
| import { useChangeTimeZoneWithPreservedLocalTime } from "@calcom/features/data-table/hooks/useChangeTimeZoneWithPreservedLocalTime"; | ||
| import { useLocale } from "@calcom/lib/hooks/useLocale"; | ||
| import { trpc } from "@calcom/trpc"; | ||
|
|
||
| import { useInsightsBookingParameters } from "../../hooks/useInsightsBookingParameters"; | ||
| import { ChartCard } from "../ChartCard"; | ||
| import { LoadingInsight } from "../LoadingInsights"; | ||
| import { UserStatsTable } from "../UserStatsTable"; | ||
|
|
||
| export const LeastCompletedTeamMembersTable = () => { | ||
| const { t } = useLocale(); | ||
| let insightsBookingParams = useInsightsBookingParameters(); | ||
|
|
||
| const currentTime = useChangeTimeZoneWithPreservedLocalTime( | ||
| useMemo(() => { | ||
| return dayjs().toISOString(); | ||
| }, []) | ||
| ); | ||
|
|
||
| // booking with endDate < now is "accepted" booking | ||
| insightsBookingParams = { | ||
| ...insightsBookingParams, | ||
| endDate: currentTime, | ||
| }; | ||
|
|
||
| const { data, isSuccess, isPending } = trpc.viewer.insights.membersWithLeastCompletedBookings.useQuery( | ||
| insightsBookingParams, | ||
| { | ||
| staleTime: 180000, | ||
| refetchOnWindowFocus: false, | ||
| trpc: { | ||
| context: { skipBatch: true }, | ||
| }, | ||
| } | ||
| ); | ||
|
|
||
| if (isPending) return <LoadingInsight />; | ||
|
|
||
| if (!isSuccess || !data) return null; | ||
|
|
||
| return ( | ||
| <ChartCard title={t("least_bookings_completed")}> | ||
bandhan-majumder marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| <UserStatsTable data={data} /> | ||
| </ChartCard> | ||
| ); | ||
| }; | ||
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
51 changes: 51 additions & 0 deletions
51
packages/features/insights/components/booking/MostCompletedBookings.tsx
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,51 @@ | ||
| "use client"; | ||
|
|
||
| import { useMemo } from "react"; | ||
|
|
||
| import dayjs from "@calcom/dayjs"; | ||
| import { useChangeTimeZoneWithPreservedLocalTime } from "@calcom/features/data-table/hooks/useChangeTimeZoneWithPreservedLocalTime"; | ||
| import { useLocale } from "@calcom/lib/hooks/useLocale"; | ||
| import { trpc } from "@calcom/trpc"; | ||
|
|
||
| import { useInsightsBookingParameters } from "../../hooks/useInsightsBookingParameters"; | ||
| import { ChartCard } from "../ChartCard"; | ||
| import { LoadingInsight } from "../LoadingInsights"; | ||
| import { UserStatsTable } from "../UserStatsTable"; | ||
|
|
||
| export const MostCompletedTeamMembersTable = () => { | ||
| const { t } = useLocale(); | ||
| let insightsBookingParams = useInsightsBookingParameters(); | ||
|
|
||
| const currentTime = useChangeTimeZoneWithPreservedLocalTime( | ||
| useMemo(() => { | ||
| return dayjs().toISOString(); | ||
| }, []) | ||
| ); | ||
|
|
||
| // booking with endDate < now is "accepted" booking | ||
| insightsBookingParams = { | ||
| ...insightsBookingParams, | ||
| endDate: currentTime, | ||
| }; | ||
|
|
||
| const { data, isSuccess, isPending } = trpc.viewer.insights.membersWithMostCompletedBookings.useQuery( | ||
| insightsBookingParams, | ||
| { | ||
| staleTime: 180000, | ||
| refetchOnWindowFocus: false, | ||
| trpc: { | ||
| context: { skipBatch: true }, | ||
| }, | ||
| } | ||
| ); | ||
|
|
||
| if (isPending) return <LoadingInsight />; | ||
|
|
||
| if (!isSuccess || !data) return null; | ||
|
|
||
| return ( | ||
| <ChartCard title={t("most_bookings_completed")}> | ||
| <UserStatsTable data={data} /> | ||
| </ChartCard> | ||
| ); | ||
| }; |
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
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.
💡 Verification agent
🧩 Analysis chain
Completed-bookings components imported — looks good; verify wiring (exports, routes, locales).
The imports align with the PR goal to surface completed-bookings insights. Please run the quick checks below to ensure nothing’s dangling (public exports, TRPC routes, service filter, and locale keys).
🏁 Script executed:
Length of output: 2033
🏁 Script executed:
Length of output: 1556
Action Required: Address missing status filter & update locale usages
Verified that imports and TRPC endpoints are wired correctly. However, two critical issues need your attention:
• Service filter – In
packages/lib/server/service/InsightsBookingBaseService.ts, thegetMembersStatsWithCount()method currently does not filter bookings by status'accepted'. Please add or verify a line such as:within the query options passed to your data layer so only completed (accepted) bookings are counted.
• Stale locale keys – Although the new keys (
most_bookings_completed,least_bookings_completed, etc.) are present inapps/web/public/static/locales/en/common.json, the old keys are still referenced in:i18n.lock(lines 2170–2171):most_booked_members
least_booked_members
packages/emails/src/templates/MonthlyDigestEmail.tsx:160:Update these usages to the new keys (
most_bookings_completedandleast_bookings_completed), then regenerate your i18n lock file.Once these fixes are in place, rerun your locale and service tests to confirm everything surfaces correctly.
🤖 Prompt for AI Agents