From 9603831def554e56924c89d34a5f91f31f0a57e1 Mon Sep 17 00:00:00 2001 From: Hariom Balhara <1780212+hariombalhara@users.noreply.github.com> Date: Tue, 17 Feb 2026 13:22:16 +0530 Subject: [PATCH] refactor: update BookingHistory component to use date-fns for timestamp formatting (#27851) Replaced dayjs with date-fns for better performance and consistency in date handling. Added Tooltip for displaying formatted timestamps and improved search functionality by translating field labels and values. Cleaned up code for better readability. --- .../components/BookingHistory.tsx | 36 ++++++++++++------- 1 file changed, 23 insertions(+), 13 deletions(-) diff --git a/apps/web/modules/booking-audit/components/BookingHistory.tsx b/apps/web/modules/booking-audit/components/BookingHistory.tsx index 2668f1af5c..0889689d64 100644 --- a/apps/web/modules/booking-audit/components/BookingHistory.tsx +++ b/apps/web/modules/booking-audit/components/BookingHistory.tsx @@ -1,6 +1,5 @@ "use client"; -import dayjs from "@calcom/dayjs"; import type { AuditActorType } from "@calcom/features/booking-audit/lib/repository/IAuditActorRepository"; import ServerTrans from "@calcom/lib/components/ServerTrans"; import { useLocale } from "@calcom/lib/hooks/useLocale"; @@ -10,6 +9,8 @@ import { Button } from "@calcom/ui/components/button"; import { FilterSearchField, Select } from "@calcom/ui/components/form"; import { Icon, type IconName } from "@calcom/ui/components/icon"; import { SkeletonText } from "@calcom/ui/components/skeleton"; +import { Tooltip } from "@calcom/ui/components/tooltip"; +import { format, formatDistanceToNow } from "date-fns"; import Link from "next/link"; import { useState } from "react"; @@ -286,7 +287,9 @@ function BookingLogsTimeline({ logs }: BookingLogsTimelineProps) { {actorRole && {` (${t(actorRole)})`}} • - {dayjs(log.timestamp).fromNow()} + + {formatDistanceToNow(new Date(log.timestamp), { addSuffix: true })} + @@ -343,7 +346,7 @@ function BookingLogsTimeline({ logs }: BookingLogsTimelineProps) {
{t("timestamp")} - {dayjs(log.timestamp).format("YYYY-MM-DD HH:mm:ss")} + {format(new Date(log.timestamp), "yyyy-MM-dd HH:mm:ss")}
{log.displayJson && Object.keys(log.displayJson).length > 0 && ( @@ -374,28 +377,35 @@ function BookingLogsTimeline({ logs }: BookingLogsTimelineProps) { } function useBookingLogsFilters(auditLogs: AuditLog[], searchTerm: string, actorFilter: string | null) { + const { t } = useLocale(); + const filteredLogs = auditLogs.filter((log) => { const doesMatchDisplayFields = (): boolean => { return ( log.displayFields?.some((field) => { const searchLower = searchTerm.toLowerCase(); + + const translatedLabel = field.labelKey ? t(field.labelKey) : ""; + const translatedValue = field.valueKey ? t(field.valueKey) : ""; + const displayValue = field.value ?? ""; + const displayValues = field.values ?? []; + return ( - field.valueKey?.toLowerCase().includes(searchLower) || - field.labelKey?.toLowerCase().includes(searchLower) || - field.value?.toLowerCase().includes(searchLower) || - field.values?.some((v) => v.toLowerCase().includes(searchLower)) + translatedLabel.toLowerCase().includes(searchLower) || + translatedValue.toLowerCase().includes(searchLower) || + displayValue.toLowerCase().includes(searchLower) || + displayValues.some((v) => v.toLowerCase().includes(searchLower)) ); }) ?? false ); }; const doesMatchActionDisplayTitle = (): boolean => { - return ( - log.actionDisplayTitle.key?.toLowerCase().includes(searchTerm.toLowerCase()) || - Object.values(log.actionDisplayTitle.params ?? {}).some((param) => - param?.toString().toLowerCase().includes(searchTerm.toLowerCase()) - ) - ); + const translatedTitle = log.actionDisplayTitle.key + ? t(log.actionDisplayTitle.key, log.actionDisplayTitle.params ?? {}) + : ""; + + return translatedTitle.toLowerCase().includes(searchTerm.toLowerCase()); }; const matchesSearch =