fix: deep link reschedule audit log to booking drawer history tab (#27709)
* fix: deep link reschedule audit log to booking drawer history tab Co-Authored-By: [email protected] <[email protected]> * fix: make booking drawer tab-agnostic for cross-tab deep links Co-Authored-By: [email protected] <[email protected]> * fix: use status-agnostic /bookings URL for audit log deep links - Update audit service URLs from /bookings/upcoming?uid=... to /bookings?uid=... - Add /bookings/page.tsx redirect that routes to /bookings/upcoming preserving query params - Update tests to expect new URL format Co-Authored-By: [email protected] <[email protected]> * fixes * refactor: use client-side replaceState instead of server redirect for booking deep links Co-Authored-By: [email protected] <[email protected]> * fix: use router.replace instead of replaceState to update tab and booking list Co-Authored-By: [email protected] <[email protected]> * improvements * refactor: extract deep link logic from BookingListContainer into usePreSelectedBooking hook Co-Authored-By: [email protected] <[email protected]> * fix: use proper BookingOutput status type in test helper Co-Authored-By: [email protected] <[email protected]> * fix: decouple getTabForBooking from BookingOutput type for simpler testing Co-Authored-By: [email protected] <[email protected]> * fix: accept Date | string for endTime in BookingForTabResolution interface Co-Authored-By: [email protected] <[email protected]> * refactor: eliminate initialBookingUid prop drilling and revert formatting-only changes Co-Authored-By: [email protected] <[email protected]> * fix: use AuditDeepLink wrapper to preserve target=_blank through ServerTrans cloneElement Co-Authored-By: [email protected] <[email protected]> * Improve code organization * refactor: rename usePreSelectedBooking to useSwitchToCorrectStatusTab Co-Authored-By: [email protected] <[email protected]> * fix: push preSelectedBooking into store so drawer opens on direct navigation Co-Authored-By: [email protected] <[email protected]> * fixes * fixes * fixes * fix --------- Co-authored-by: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com> Co-authored-by: Udit Takkar <[email protected]>
This commit is contained in:
9 files changed
+455
-96
No files matched your search
@@ -139,7 +139,13 @@ function ActionTitle({ actionDisplayTitle }: { actionDisplayTitle: TranslationWi
|
||||
values={actionDisplayTitle.params}
|
||||
components={actionDisplayTitle.components.map((comp) =>
|
||||
comp.type === "link" ? (
|
||||
<Link key={comp.href} href={comp.href} className="text-emphasis underline hover:no-underline" />
|
||||
<Link
|
||||
key={comp.href}
|
||||
href={comp.href}
|
||||
target="_blank"
|
||||
rel="noopener noreferrer"
|
||||
className="text-emphasis underline hover:no-underline"
|
||||
/>
|
||||
) : (
|
||||
<span key={comp.href} />
|
||||
)
|
||||
@@ -304,15 +310,15 @@ function BookingLogsTimeline({ logs }: BookingLogsTimelineProps) {
|
||||
{/* Render displayFields if available, otherwise show type */}
|
||||
{log.displayFields && log.displayFields.length > 0
|
||||
? log.displayFields.map((field, idx) => (
|
||||
<div
|
||||
key={idx}
|
||||
className="flex items-start gap-2 py-2 border-b px-3 border-subtle">
|
||||
<span className="font-medium text-emphasis w-[140px]">{t(field.labelKey)}</span>
|
||||
<span className="font-medium">
|
||||
<DisplayFieldValue field={field} />
|
||||
</span>
|
||||
</div>
|
||||
))
|
||||
<div
|
||||
key={idx}
|
||||
className="flex items-start gap-2 py-2 border-b px-3 border-subtle">
|
||||
<span className="font-medium text-emphasis w-[140px]">{t(field.labelKey)}</span>
|
||||
<span className="font-medium">
|
||||
<DisplayFieldValue field={field} />
|
||||
</span>
|
||||
</div>
|
||||
))
|
||||
: null}
|
||||
<div className="flex items-start gap-2 py-2 border-b px-3 border-subtle">
|
||||
<span className="font-medium text-emphasis w-[140px]">{t("actor")}</span>
|
||||
|
||||
@@ -13,13 +13,14 @@ import { ToggleGroup } from "@calcom/ui/components/form";
|
||||
import { WipeMyCalActionButton } from "@calcom/web/components/apps/wipemycalother/wipeMyCalActionButton";
|
||||
import { getCoreRowModel, getSortedRowModel, useReactTable } from "@tanstack/react-table";
|
||||
import { useRouter } from "next/navigation";
|
||||
import React, { useCallback, useEffect, useMemo, useState } from "react";
|
||||
import { useCallback, useEffect, useMemo, useState } from "react";
|
||||
import { useBookingFilters } from "~/bookings/hooks/useBookingFilters";
|
||||
import { useBookingListColumns } from "~/bookings/hooks/useBookingListColumns";
|
||||
import { useBookingListData } from "~/bookings/hooks/useBookingListData";
|
||||
import { useBookingStatusTab } from "~/bookings/hooks/useBookingStatusTab";
|
||||
import { useFacetedUniqueValues } from "~/bookings/hooks/useFacetedUniqueValues";
|
||||
import { useListAutoSelector } from "~/bookings/hooks/useListAutoSelector";
|
||||
import { useSwitchToCorrectStatusTab } from "~/bookings/hooks/useSwitchToCorrectStatusTab";
|
||||
import { DataTableFilters, DataTableSegment } from "~/data-table/components";
|
||||
import {
|
||||
BookingDetailsSheetStoreProvider,
|
||||
@@ -231,17 +232,21 @@ function BookingListInner({
|
||||
}
|
||||
|
||||
export function BookingListContainer(props: BookingListContainerProps) {
|
||||
const { limit, offset, setPageIndex, isValidatorPending } = useDataTable();
|
||||
const { limit, offset, isValidatorPending } = useDataTable();
|
||||
const { eventTypeIds, teamIds, userIds, dateRange, attendeeName, attendeeEmail, bookingUid } =
|
||||
useBookingFilters();
|
||||
|
||||
const { resolvedTabStatus, isResolvingTabStatus, preSelectedBooking } = useSwitchToCorrectStatusTab({
|
||||
defaultStatus: props.status,
|
||||
});
|
||||
|
||||
// Build query input once - shared between query and prefetching
|
||||
const queryInput = useMemo(
|
||||
() => ({
|
||||
limit,
|
||||
offset,
|
||||
filters: {
|
||||
statuses: [props.status],
|
||||
statuses: [resolvedTabStatus],
|
||||
eventTypeIds,
|
||||
teamIds,
|
||||
userIds,
|
||||
@@ -257,7 +262,7 @@ export function BookingListContainer(props: BookingListContainerProps) {
|
||||
[
|
||||
limit,
|
||||
offset,
|
||||
props.status,
|
||||
resolvedTabStatus,
|
||||
eventTypeIds,
|
||||
teamIds,
|
||||
userIds,
|
||||
@@ -271,10 +276,19 @@ export function BookingListContainer(props: BookingListContainerProps) {
|
||||
const query = trpc.viewer.bookings.get.useQuery(queryInput, {
|
||||
staleTime: 5 * 60 * 1000, // 5 minutes - data is considered fresh
|
||||
gcTime: 30 * 60 * 1000, // 30 minutes - cache retention time
|
||||
enabled: !isValidatorPending, // Wait for validator to be ready before fetching
|
||||
// We wait for tab status to be resolved before fetching, so that we can fetch the correct bookings as per resolved tab status
|
||||
enabled: !isValidatorPending && !isResolvingTabStatus, // Wait for validator to be ready before fetching
|
||||
});
|
||||
|
||||
const bookings = useMemo(() => query.data?.bookings ?? [], [query.data?.bookings]);
|
||||
const bookings = useMemo(() => {
|
||||
const queryBookings = query.data?.bookings ?? [];
|
||||
if (!preSelectedBooking) return queryBookings;
|
||||
if (queryBookings.some((b) => b.uid === preSelectedBooking.uid)) return queryBookings;
|
||||
// It ensures that the drawer opens for a booking that isn't even in the bookings list
|
||||
// Note that, bookings list doesn't use this so, it won't be visible in the list view but drawer will open for it
|
||||
// We don't want to show this booking in the list view, as it might not match the filters/pagination applied
|
||||
return [...queryBookings, preSelectedBooking];
|
||||
}, [query.data?.bookings, preSelectedBooking]);
|
||||
|
||||
// Always call the hook and provide navigation capabilities
|
||||
// The BookingDetailsSheet is only rendered when bookingsV3Enabled is true (see line 212)
|
||||
@@ -290,6 +304,7 @@ export function BookingListContainer(props: BookingListContainerProps) {
|
||||
<BookingDetailsSheetStoreProvider bookings={bookings}>
|
||||
<BookingListInner
|
||||
{...props}
|
||||
status={resolvedTabStatus}
|
||||
data={query.data}
|
||||
isPending={query.isPending}
|
||||
hasError={!!query.error}
|
||||
|
||||
@@ -0,0 +1,60 @@
|
||||
import { describe, it, expect } from "vitest";
|
||||
|
||||
import { getTabForBooking } from "./useSwitchToCorrectStatusTab";
|
||||
|
||||
function makeBooking(overrides: {
|
||||
status: string;
|
||||
endTime: Date;
|
||||
recurringEventId?: string | null;
|
||||
}){
|
||||
return {
|
||||
status: overrides.status,
|
||||
endTime: overrides.endTime,
|
||||
recurringEventId: overrides.recurringEventId ?? null,
|
||||
};
|
||||
}
|
||||
|
||||
const future = new Date(Date.now() + 24 * 60 * 60 * 1000);
|
||||
const past = new Date(Date.now() - 24 * 60 * 60 * 1000);
|
||||
|
||||
describe("getTabForBooking", () => {
|
||||
it("returns 'cancelled' for CANCELLED bookings", () => {
|
||||
expect(getTabForBooking(makeBooking({ status: "CANCELLED", endTime: future }))).toBe("cancelled");
|
||||
});
|
||||
|
||||
it("returns 'cancelled' for REJECTED bookings", () => {
|
||||
expect(getTabForBooking(makeBooking({ status: "REJECTED", endTime: future }))).toBe("cancelled");
|
||||
});
|
||||
|
||||
it("returns 'cancelled' for CANCELLED bookings even if past", () => {
|
||||
expect(getTabForBooking(makeBooking({ status: "CANCELLED", endTime: past }))).toBe("cancelled");
|
||||
});
|
||||
|
||||
it("returns 'unconfirmed' for PENDING bookings in the future", () => {
|
||||
expect(getTabForBooking(makeBooking({ status: "PENDING", endTime: future }))).toBe("unconfirmed");
|
||||
});
|
||||
|
||||
it("returns 'past' for PENDING bookings that have ended", () => {
|
||||
expect(getTabForBooking(makeBooking({ status: "PENDING", endTime: past }))).toBe("past");
|
||||
});
|
||||
|
||||
it("returns 'past' for ACCEPTED bookings that have ended", () => {
|
||||
expect(getTabForBooking(makeBooking({ status: "ACCEPTED", endTime: past }))).toBe("past");
|
||||
});
|
||||
|
||||
it("returns 'recurring' for future ACCEPTED bookings with recurringEventId", () => {
|
||||
expect(
|
||||
getTabForBooking(makeBooking({ status: "ACCEPTED", endTime: future, recurringEventId: "rec-123" }))
|
||||
).toBe("recurring");
|
||||
});
|
||||
|
||||
it("returns 'upcoming' for future ACCEPTED bookings without recurringEventId", () => {
|
||||
expect(getTabForBooking(makeBooking({ status: "ACCEPTED", endTime: future }))).toBe("upcoming");
|
||||
});
|
||||
|
||||
it("returns 'past' for recurring bookings that have ended", () => {
|
||||
expect(
|
||||
getTabForBooking(makeBooking({ status: "ACCEPTED", endTime: past, recurringEventId: "rec-123" }))
|
||||
).toBe("past");
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,103 @@
|
||||
import { trpc } from "@calcom/trpc/react";
|
||||
import { usePathname, useRouter, useSearchParams } from "next/navigation";
|
||||
import { useEffect, useState, useTransition } from "react";
|
||||
import { validStatuses } from "../lib/validStatuses";
|
||||
import type { BookingListingStatus, BookingOutput } from "../types";
|
||||
|
||||
interface BookingForTabResolution {
|
||||
status: string;
|
||||
endTime: Date | string;
|
||||
recurringEventId: string | null;
|
||||
}
|
||||
|
||||
interface UseSwitchToCorrectTabResult {
|
||||
resolvedTabStatus: BookingListingStatus;
|
||||
isResolvingTabStatus: boolean;
|
||||
preSelectedBooking: BookingOutput | null;
|
||||
}
|
||||
|
||||
export function getTabForBooking(booking: BookingForTabResolution): BookingListingStatus {
|
||||
const isPast = new Date(booking.endTime) <= new Date();
|
||||
|
||||
if (booking.status === "CANCELLED" || booking.status === "REJECTED") {
|
||||
return "cancelled";
|
||||
}
|
||||
if (booking.status === "PENDING" && !isPast) {
|
||||
return "unconfirmed";
|
||||
}
|
||||
if (isPast) {
|
||||
return "past";
|
||||
}
|
||||
if (booking.recurringEventId) {
|
||||
return "recurring";
|
||||
}
|
||||
return "upcoming";
|
||||
}
|
||||
|
||||
/**
|
||||
* Ensures that the correct status tab is selected based on the pre-selected booking through query params
|
||||
*/
|
||||
export function useSwitchToCorrectStatusTab({
|
||||
defaultStatus,
|
||||
}: {
|
||||
defaultStatus: BookingListingStatus;
|
||||
}): UseSwitchToCorrectTabResult {
|
||||
const {
|
||||
preSelectedBookingUid,
|
||||
preSelectedBooking,
|
||||
preSelectedBookingFull,
|
||||
isPending: isFetchingPreSelectedBooking,
|
||||
} = usePreSelectedBooking();
|
||||
const pathname = usePathname();
|
||||
const router = useRouter();
|
||||
const [resolvedTabStatus, setResolvedTab] = useState<BookingListingStatus>(defaultStatus);
|
||||
const [isNavigatingToCorrectTab, startNavigationToCorrectTab] = useTransition();
|
||||
|
||||
useEffect(() => {
|
||||
if (!preSelectedBooking) return;
|
||||
const correctTab = getTabForBooking(preSelectedBooking);
|
||||
const currentTab = pathname?.match(/\/bookings\/(\w+)/)?.[1];
|
||||
const shouldNavigate = correctTab && currentTab && correctTab !== currentTab;
|
||||
if (!shouldNavigate) return;
|
||||
startNavigationToCorrectTab(() => {
|
||||
const newPath = pathname.replace(`/bookings/${currentTab}`, `/bookings/${correctTab}`);
|
||||
router.replace(`${newPath}${window.location.search}`);
|
||||
});
|
||||
setResolvedTab(correctTab);
|
||||
}, [preSelectedBooking, pathname, router]);
|
||||
|
||||
const isResolvingTabStatus = preSelectedBookingUid
|
||||
? isFetchingPreSelectedBooking || isNavigatingToCorrectTab
|
||||
: false;
|
||||
|
||||
return { resolvedTabStatus, isResolvingTabStatus, preSelectedBooking: preSelectedBookingFull };
|
||||
}
|
||||
|
||||
export function usePreSelectedBooking(): {
|
||||
preSelectedBookingUid: string | undefined;
|
||||
preSelectedBooking: BookingForTabResolution | null;
|
||||
preSelectedBookingFull: BookingOutput | null;
|
||||
isPending: boolean;
|
||||
}{
|
||||
const searchParams = useSearchParams();
|
||||
const preSelectedBookingUid = searchParams?.get("uid") ?? undefined;
|
||||
|
||||
const { data: preSelectedBookingData, isPending } = trpc.viewer.bookings.get.useQuery(
|
||||
{
|
||||
limit: 1,
|
||||
offset: 0,
|
||||
filters: {
|
||||
bookingUid: preSelectedBookingUid,
|
||||
statuses: [...validStatuses],
|
||||
},
|
||||
},
|
||||
{
|
||||
enabled: !!preSelectedBookingUid,
|
||||
staleTime: 5 * 60 * 1000,
|
||||
}
|
||||
);
|
||||
|
||||
const preSelectedBookingFull = preSelectedBookingData?.bookings?.[0] ?? null;
|
||||
const preSelectedBooking: BookingForTabResolution | null = preSelectedBookingFull;
|
||||
return { preSelectedBookingUid, preSelectedBooking, preSelectedBookingFull, isPending };
|
||||
}
|
||||
Reference in new issue
Block a user