Skip to content

feat(bookings): add sort by booking creation date#29651

Open
karimqpn wants to merge 2 commits into
calcom:mainfrom
karimqpn:feat/bookings-sort-by-created-date
Open

feat(bookings): add sort by booking creation date#29651
karimqpn wants to merge 2 commits into
calcom:mainfrom
karimqpn:feat/bookings-sort-by-created-date

Conversation

@karimqpn

@karimqpn karimqpn commented Jun 26, 2026

Copy link
Copy Markdown

What

Adds a tab-independent Sort control (Newest first / Oldest first / Default) to the bookings list, ordering bookings by when they were created (createdAt).

Why

Users want to review bookings in the order they came in ("new bookings in created order"), independent of the upcoming/past/cancelled tab they're on.

How

  • Exposes sortCreated on the bookings query input (get.schema.ts). The handler's getOrderBy already maps sortCreated.orderBy("createdAt", …), so no handler change was needed.
  • BookingListContainer.tsx: a SortButton dropdown plus lifted sortCreated state wired into the query. When unset (Default), the existing per-status default ordering is preserved.
  • i18n keys sort, newest_first, oldest_first.

Testing

  • Verified getOrderBy returns { key: "createdAt", order } for sortCreated, and the input schema now accepts it. No new type errors introduced (confirmed by diffing the web type-check against a clean baseline).

Verified locally

  • Ran the full app against a local database and confirmed the Sort control appears on the Bookings page with Newest first / Oldest first / Default options, applying regardless of the active tab.

Notes / why this is low-risk

  • Opt-in: default ordering is unchanged unless the user picks a sort.
  • Backend already supported sortCreated; this is primarily input-schema + UI wiring.
  • Small surface: 3 files.

🤖 Generated with Claude Code

Adds a tab-independent Sort control (Newest first / Oldest first / Default)
to the bookings list, ordering by createdAt. Exposes sortCreated on the
bookings query input; the handler's getOrderBy already maps it to
createdAt ordering.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
@github-actions

Copy link
Copy Markdown
Contributor

Welcome to Cal.diy, @karimqpn! Thanks for opening this pull request.

A few things to keep in mind:

  • This is Cal.diy, not Cal.com. Cal.diy is a community-driven, fully open-source fork of Cal.com licensed under MIT. Your changes here will be part of Cal.diy — they will not be deployed to the Cal.com production app.
  • Please review our Contributing Guidelines if you haven't already.
  • Make sure your PR title follows the Conventional Commits format.

A maintainer will review your PR soon. Thanks for contributing!

@karimqpn karimqpn marked this pull request as ready for review June 26, 2026 09:37
@coderabbitai

coderabbitai Bot commented Jun 26, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 597b86f5-466b-4dfb-82ab-f9c3ece8dada

📥 Commits

Reviewing files that changed from the base of the PR and between 347a889 and cfba8ba.

📒 Files selected for processing (1)
  • apps/web/modules/bookings/components/BookingListContainer.tsx

📝 Walkthrough

Walkthrough

The booking list now supports sorting by booking creation date. The bookings input schema accepts an optional sortCreated value, the list header renders a localized sort dropdown with newest-first, oldest-first, and default options, and the container keeps sortCreated state, passes it to BookingListInner, and includes it in the tRPC query input when set.

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly summarizes the main change: adding booking creation-date sorting.
Description check ✅ Passed The description is directly related to the bookings sort feature and its UI, schema, and i18n changes.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
apps/web/modules/bookings/components/BookingListContainer.tsx (1)

310-345: 🎯 Functional Correctness | 🟡 Minor

Sorting changes do not reset pagination offset

When a user changes the sort order while on a paginated page, the offset remains stale. This can result in an empty or misaligned page until the user manually navigates. The onSortCreatedChange handler (line 377) only updates the sort state without resetting the page index.

Wrap the setSortCreated handler to reset the page index when sort changes:

Code Location
  export function BookingListContainer(props: BookingListContainerProps) {
    const { limit, offset, setPageIndex, isValidatorPending } = useDataTable();
    const { eventTypeIds, teamIds, userIds, dateRange, attendeeName, attendeeEmail, bookingUid } =
      useBookingFilters();

    const [sortCreated, setSortCreated] = useState<SortCreatedOrder>(undefined);

+   const handleSortChange = useCallback((value: SortCreatedOrder) => {
+     setPageIndex(0);
+     setSortCreated(value);
+   }, [setPageIndex, setSortCreated]);
+
    const queryInput = useMemo(
      () => ({
        limit,
        offset,
        filters: {
          statuses: [props.status],
          eventTypeIds,
          teamIds,
          userIds,
          attendeeName,
          attendeeEmail,
          bookingUid,
          afterStartDate: dateRange?.startDate
            ? dayjs(dateRange?.startDate).startOf("day").toISOString()
            : undefined,
          beforeEndDate: dateRange?.endDate ? dayjs(dateRange?.endDate).endOf("day").toISOString() : undefined,
        },
        sort: sortCreated ? { sortCreated } : undefined,
      }),
      [
        limit,
        offset,
        props.status,
        eventTypeIds,
        teamIds,
        userIds,
        attendeeName,
        attendeeEmail,
        bookingUid,
        dateRange,
        sortCreated,
      ]
    );

    // ... inside return ...
-       onSortCreatedChange={setSortCreated}
+       onSortCreatedChange={handleSortChange}
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@apps/web/modules/bookings/components/BookingListContainer.tsx` around lines
310 - 345, The sort change flow in BookingListContainer keeps the current
pagination offset, which can leave the user on a stale page after changing
order. Update the sort handler used by onSortCreatedChange to also reset the
page index/offset whenever setSortCreated is called, so queryInput is rebuilt
from the first page after a sort change and pagination stays aligned.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Outside diff comments:
In `@apps/web/modules/bookings/components/BookingListContainer.tsx`:
- Around line 310-345: The sort change flow in BookingListContainer keeps the
current pagination offset, which can leave the user on a stale page after
changing order. Update the sort handler used by onSortCreatedChange to also
reset the page index/offset whenever setSortCreated is called, so queryInput is
rebuilt from the first page after a sort change and pagination stays aligned.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 9cedabce-4329-4a29-9faf-1b9c25848395

📥 Commits

Reviewing files that changed from the base of the PR and between 62317bd and 347a889.

📒 Files selected for processing (3)
  • apps/web/modules/bookings/components/BookingListContainer.tsx
  • packages/i18n/locales/en/common.json
  • packages/trpc/server/routers/viewer/bookings/get.schema.ts

Addresses CodeRabbit review on calcom#29651: changing the sort while on a
paginated page kept a stale offset, which could land on an empty page.
The sort handler now resets the page index before updating sort state.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
@karimqpn

Copy link
Copy Markdown
Author

Thanks @coderabbitai — good catch. Fixed in cfba8ba: onSortCreatedChange now resets the page index (setPageIndex(0)) before updating sort state, so the query rebuilds from the first page and pagination stays aligned.

@coderabbitai

coderabbitai Bot commented Jun 26, 2026

Copy link
Copy Markdown
Contributor

Tip

For best results, initiate chat on the files or code changes.

@karimqpn Nice — thanks for addressing that. Resetting the page index before changing the sort should keep pagination and query state aligned.


If you found this review helpful, would you consider giving us a shout-out on X?

Thank you for using CodeRabbit!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants