Skip to content

Commit b7b631f

Browse files
fix: Persist filters across tabs to improve user experience (calcom#21706)
* fix: Persist filters across tabs to improve user experience * fixes unnecessary renders --------- Co-authored-by: Kartik Saini <41051387+kart1ka@users.noreply.github.com>
1 parent c10f15e commit b7b631f

1 file changed

Lines changed: 41 additions & 28 deletions

File tree

apps/web/modules/bookings/views/bookings-listing-view.tsx

Lines changed: 41 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
"use client";
22

33
import { useReactTable, getCoreRowModel, getSortedRowModel, createColumnHelper } from "@tanstack/react-table";
4+
import { useSearchParams } from "next/navigation";
45
import { useMemo, useRef } from "react";
56

67
import { WipeMyCalActionButton } from "@calcom/app-store/wipemycalother/components";
@@ -44,34 +45,6 @@ type RecurringInfo = {
4445
bookings: { [key: string]: Date[] };
4546
};
4647

47-
const tabs: (VerticalTabItemProps | HorizontalTabItemProps)[] = [
48-
{
49-
name: "upcoming",
50-
href: "/bookings/upcoming",
51-
"data-testid": "upcoming",
52-
},
53-
{
54-
name: "unconfirmed",
55-
href: "/bookings/unconfirmed",
56-
"data-testid": "unconfirmed",
57-
},
58-
{
59-
name: "recurring",
60-
href: "/bookings/recurring",
61-
"data-testid": "recurring",
62-
},
63-
{
64-
name: "past",
65-
href: "/bookings/past",
66-
"data-testid": "past",
67-
},
68-
{
69-
name: "cancelled",
70-
href: "/bookings/cancelled",
71-
"data-testid": "cancelled",
72-
},
73-
];
74-
7548
const descriptionByStatus: Record<BookingListingStatus, string> = {
7649
upcoming: "upcoming_bookings",
7750
recurring: "recurring_bookings",
@@ -107,6 +80,46 @@ function BookingsContent({ status }: BookingsProps) {
10780
const { t } = useLocale();
10881
const user = useMeQuery().data;
10982
const tableContainerRef = useRef<HTMLDivElement>(null);
83+
const searchParams = useSearchParams();
84+
85+
// Generate dynamic tabs that preserve query parameters
86+
const tabs: (VerticalTabItemProps | HorizontalTabItemProps)[] = useMemo(() => {
87+
const queryString = searchParams?.toString() || "";
88+
89+
const baseTabConfigs = [
90+
{
91+
name: "upcoming",
92+
path: "/bookings/upcoming",
93+
"data-testid": "upcoming",
94+
},
95+
{
96+
name: "unconfirmed",
97+
path: "/bookings/unconfirmed",
98+
"data-testid": "unconfirmed",
99+
},
100+
{
101+
name: "recurring",
102+
path: "/bookings/recurring",
103+
"data-testid": "recurring",
104+
},
105+
{
106+
name: "past",
107+
path: "/bookings/past",
108+
"data-testid": "past",
109+
},
110+
{
111+
name: "cancelled",
112+
path: "/bookings/cancelled",
113+
"data-testid": "cancelled",
114+
},
115+
];
116+
117+
return baseTabConfigs.map((tabConfig) => ({
118+
name: tabConfig.name,
119+
href: queryString ? `${tabConfig.path}?${queryString}` : tabConfig.path,
120+
"data-testid": tabConfig["data-testid"],
121+
}));
122+
}, [searchParams?.toString()]);
110123

111124
const eventTypeIds = useFilterValue("eventTypeId", ZMultiSelectFilterValue)?.data as number[] | undefined;
112125
const teamIds = useFilterValue("teamId", ZMultiSelectFilterValue)?.data as number[] | undefined;

0 commit comments

Comments
 (0)