From b7b631f0b036c62deaeae071d4db1e3fde4aa0c2 Mon Sep 17 00:00:00 2001 From: Sarthak Kapila Date: Thu, 26 Jun 2025 15:34:53 +0530 Subject: [PATCH] fix: Persist filters across tabs to improve user experience (#21706) * fix: Persist filters across tabs to improve user experience * fixes unnecessary renders --------- Co-authored-by: Kartik Saini <41051387+kart1ka@users.noreply.github.com> --- .../bookings/views/bookings-listing-view.tsx | 69 +++++++++++-------- 1 file changed, 41 insertions(+), 28 deletions(-) diff --git a/apps/web/modules/bookings/views/bookings-listing-view.tsx b/apps/web/modules/bookings/views/bookings-listing-view.tsx index 55431e66c7..e3fac8d29a 100644 --- a/apps/web/modules/bookings/views/bookings-listing-view.tsx +++ b/apps/web/modules/bookings/views/bookings-listing-view.tsx @@ -1,6 +1,7 @@ "use client"; import { useReactTable, getCoreRowModel, getSortedRowModel, createColumnHelper } from "@tanstack/react-table"; +import { useSearchParams } from "next/navigation"; import { useMemo, useRef } from "react"; import { WipeMyCalActionButton } from "@calcom/app-store/wipemycalother/components"; @@ -44,34 +45,6 @@ type RecurringInfo = { bookings: { [key: string]: Date[] }; }; -const tabs: (VerticalTabItemProps | HorizontalTabItemProps)[] = [ - { - name: "upcoming", - href: "/bookings/upcoming", - "data-testid": "upcoming", - }, - { - name: "unconfirmed", - href: "/bookings/unconfirmed", - "data-testid": "unconfirmed", - }, - { - name: "recurring", - href: "/bookings/recurring", - "data-testid": "recurring", - }, - { - name: "past", - href: "/bookings/past", - "data-testid": "past", - }, - { - name: "cancelled", - href: "/bookings/cancelled", - "data-testid": "cancelled", - }, -]; - const descriptionByStatus: Record = { upcoming: "upcoming_bookings", recurring: "recurring_bookings", @@ -107,6 +80,46 @@ function BookingsContent({ status }: BookingsProps) { const { t } = useLocale(); const user = useMeQuery().data; const tableContainerRef = useRef(null); + const searchParams = useSearchParams(); + + // Generate dynamic tabs that preserve query parameters + const tabs: (VerticalTabItemProps | HorizontalTabItemProps)[] = useMemo(() => { + const queryString = searchParams?.toString() || ""; + + const baseTabConfigs = [ + { + name: "upcoming", + path: "/bookings/upcoming", + "data-testid": "upcoming", + }, + { + name: "unconfirmed", + path: "/bookings/unconfirmed", + "data-testid": "unconfirmed", + }, + { + name: "recurring", + path: "/bookings/recurring", + "data-testid": "recurring", + }, + { + name: "past", + path: "/bookings/past", + "data-testid": "past", + }, + { + name: "cancelled", + path: "/bookings/cancelled", + "data-testid": "cancelled", + }, + ]; + + return baseTabConfigs.map((tabConfig) => ({ + name: tabConfig.name, + href: queryString ? `${tabConfig.path}?${queryString}` : tabConfig.path, + "data-testid": tabConfig["data-testid"], + })); + }, [searchParams?.toString()]); const eventTypeIds = useFilterValue("eventTypeId", ZMultiSelectFilterValue)?.data as number[] | undefined; const teamIds = useFilterValue("teamId", ZMultiSelectFilterValue)?.data as number[] | undefined;