The modern link attribution platform. Loved by world-class engineering teams at Twilio, Zillow, Jobber, Vercel, Raycast, and more.
TypeScript clickhousemysqlnextjsopen-sourceplanetscaleprismatailwindcsstinybirdtypescriptupstashvercel
Add timestamp tooltips throughout apps
Tim Wilson156841656cf2
diff --git a/apps/web/app/(ee)/partners.dub.co/(dashboard)/programs/[programSlug]/(enrolled)/earnings/earnings-table.tsx b/apps/web/app/(ee)/partners.dub.co/(dashboard)/programs/[programSlug]/(enrolled)/earnings/earnings-table.tsxindex 9f385a9ef0..f9281a7525 100644--- a/apps/web/app/(ee)/partners.dub.co/(dashboard)/programs/[programSlug]/(enrolled)/earnings/earnings-table.tsx+++ b/apps/web/app/(ee)/partners.dub.co/(dashboard)/programs/[programSlug]/(enrolled)/earnings/earnings-table.tsx@@ -14,6 +14,7 @@ import {LinkLogo,StatusBadge,Table,+ TimestampTooltip,Tooltip,usePagination,useRouterStuff,@@ -24,7 +25,6 @@ import {cn,currencyFormatter,fetcher,- formatDateTime,formatDateTimeSmart,getApexDomain,getPrettyUrl,@@ -79,9 +79,14 @@ export function EarningsTablePartner({ limit }: { limit?: number }) {accessorKey: "timestamp",minSize: 140,cell: ({ row }) => (- <p title={formatDateTime(row.original.createdAt)}>- {formatDateTimeSmart(row.original.createdAt)}- </p>+ <TimestampTooltip+ timestamp={row.original.createdAt}+ side="right"+ rows={["local"]}+ interactive+ >+ <span>{formatDateTimeSmart(row.original.createdAt)}</span>+ </TimestampTooltip>),},{diff --git a/apps/web/app/app.dub.co/(dashboard)/[slug]/(ee)/program/bounties/[bountyId]/bounty-submissions-table.tsx b/apps/web/app/app.dub.co/(dashboard)/[slug]/(ee)/program/bounties/[bountyId]/bounty-submissions-table.tsxindex ba1904fd98..8dc54827db 100644--- a/apps/web/app/app.dub.co/(dashboard)/[slug]/(ee)/program/bounties/[bountyId]/bounty-submissions-table.tsx+++ b/apps/web/app/app.dub.co/(dashboard)/[slug]/(ee)/program/bounties/[bountyId]/bounty-submissions-table.tsx@@ -16,6 +16,7 @@ import {ProgressCircle,StatusBadge,Table,+ TimestampTooltip,usePagination,useRouterStuff,useTable,@@ -185,12 +186,21 @@ export function BountySubmissionsTable() {{id: "createdAt",header: "Submitted",- accessorFn: (d: BountySubmissionProps) => {- if (!d.createdAt || d.status === "draft") {+ cell: ({ row }) => {+ if (!row.original.createdAt || row.original.status === "draft")return "-";- }- return formatDate(d.createdAt, { month: "short" });+ return (+ <TimestampTooltip+ timestamp={row.original.createdAt}+ side="left"+ delayDuration={150}+ >+ <span>+ {formatDate(row.original.createdAt, { month: "short" })}+ </span>+ </TimestampTooltip>+ );},},]diff --git a/apps/web/app/app.dub.co/(dashboard)/[slug]/(ee)/program/campaigns/[campaignId]/campaign-events-columns.tsx b/apps/web/app/app.dub.co/(dashboard)/[slug]/(ee)/program/campaigns/[campaignId]/campaign-events-columns.tsxindex 96d4a0a8ab..80f6aea2eb 100644--- a/apps/web/app/app.dub.co/(dashboard)/[slug]/(ee)/program/campaigns/[campaignId]/campaign-events-columns.tsx+++ b/apps/web/app/app.dub.co/(dashboard)/[slug]/(ee)/program/campaigns/[campaignId]/campaign-events-columns.tsx@@ -1,6 +1,6 @@import { GroupColorCircle } from "@/ui/partners/groups/group-color-circle";-import { Tooltip } from "@dub/ui";-import { formatDateTime, OG_AVATAR_URL, timeAgo } from "@dub/utils";+import { TimestampTooltip } from "@dub/ui";+import { OG_AVATAR_URL, timeAgo } from "@dub/utils";import { CampaignEvent } from "./campaign-events";export const campaignEventsColumns = [@@ -45,9 +45,11 @@ export const campaignEventsColumns = [const timestamp = getTimestamp(row.original);return (- <Tooltip- content={timestamp ? formatDateTime(timestamp) : "-"}+ <TimestampTooltip+ timestamp={timestamp}side="top"+ rows={["local", "utc", "unix"]}+ interactive><divclassName="text-content-subtle flex h-8 shrink-0 items-center justify-end text-xs font-medium"@@ -55,7 +57,7 @@ export const campaignEventsColumns = [>{timeAgo(timestamp)}</div>- </Tooltip>+ </TimestampTooltip>);},},diff --git a/apps/web/app/app.dub.co/(dashboard)/[slug]/(ee)/program/campaigns/campaigns-table.tsx b/apps/web/app/app.dub.co/(dashboard)/[slug]/(ee)/program/campaigns/campaigns-table.tsxindex 59b6846fc7..1faccec1be 100644--- a/apps/web/app/app.dub.co/(dashboard)/[slug]/(ee)/program/campaigns/campaigns-table.tsx+++ b/apps/web/app/app.dub.co/(dashboard)/[slug]/(ee)/program/campaigns/campaigns-table.tsx@@ -17,19 +17,14 @@ import {Popover,StatusBadge,Table,+ TimestampTooltip,Tooltip,usePagination,useRouterStuff,useTable,} from "@dub/ui";import { Dots, Duplicate, LoadingCircle, Trash } from "@dub/ui/icons";-import {- cn,- fetcher,- formatDateTime,- formatDateTimeSmart,- nFormatter,-} from "@dub/utils";+import { cn, fetcher, formatDateTimeSmart, nFormatter } from "@dub/utils";import { Row } from "@tanstack/react-table";import { Command } from "cmdk";import { Mail, Pause, Play } from "lucide-react";@@ -121,9 +116,14 @@ export function CampaignsTable() {header: "Created",accessorFn: (d) => d.createdAt,cell: ({ row }) => (- <p title={formatDateTime(row.original.createdAt)}>- {formatDateTimeSmart(row.original.createdAt)}- </p>+ <TimestampTooltip+ timestamp={row.original.createdAt}+ side="right"+ rows={["local"]}+ delayDuration={150}+ >+ <span>{formatDateTimeSmart(row.original.createdAt)}</span>+ </TimestampTooltip>),},{diff --git a/apps/web/app/app.dub.co/(dashboard)/[slug]/(ee)/program/commissions/commission-table.tsx b/apps/web/app/app.dub.co/(dashboard)/[slug]/(ee)/program/commissions/commission-table.tsxindex bb484c58d4..0822b98d12 100644--- a/apps/web/app/app.dub.co/(dashboard)/[slug]/(ee)/program/commissions/commission-table.tsx+++ b/apps/web/app/app.dub.co/(dashboard)/[slug]/(ee)/program/commissions/commission-table.tsx@@ -18,6 +18,7 @@ import {Filter,StatusBadge,Table,+ TimestampTooltip,Tooltip,usePagination,useRouterStuff,@@ -28,7 +29,6 @@ import {cn,currencyFormatter,fetcher,- formatDateTime,formatDateTimeSmart,nFormatter,} from "@dub/utils";@@ -90,9 +90,15 @@ const CommissionTableInner = memo(id: "createdAt",header: "Date",cell: ({ row }) => (- <p title={formatDateTime(row.original.createdAt)}>- {formatDateTimeSmart(row.original.createdAt)}- </p>+ <TimestampTooltip+ timestamp={row.original.createdAt}+ side="right"+ rows={["local", "utc", "unix"]}+ delayDuration={150}+ interactive+ >+ <p>{formatDateTimeSmart(row.original.createdAt)}</p>+ </TimestampTooltip>),},{diff --git a/apps/web/app/app.dub.co/(dashboard)/[slug]/(ee)/program/partners/partners-table.tsx b/apps/web/app/app.dub.co/(dashboard)/[slug]/(ee)/program/partners/partners-table.tsxindex 66bcbc1212..89b7a780db 100644--- a/apps/web/app/app.dub.co/(dashboard)/[slug]/(ee)/program/partners/partners-table.tsx+++ b/apps/web/app/app.dub.co/(dashboard)/[slug]/(ee)/program/partners/partners-table.tsx@@ -28,6 +28,7 @@ import {Popover,StatusBadge,Table,+ TimestampTooltip,useColumnVisibility,usePagination,useRouterStuff,@@ -191,7 +192,18 @@ export function PartnersTable() {{id: "createdAt",header: "Enrolled",- accessorFn: (d) => formatDate(d.createdAt, { month: "short" }),+ cell: ({ row }) => (+ <TimestampTooltip+ timestamp={row.original.createdAt}+ side="right"+ rows={["local"]}+ delayDuration={150}+ >+ <span>+ {formatDate(row.original.createdAt, { month: "short" })}+ </span>+ </TimestampTooltip>+ ),},{id: "status",diff --git a/apps/web/app/app.dub.co/(dashboard)/[slug]/links/utm/template-card.tsx b/apps/web/app/app.dub.co/(dashboard)/[slug]/links/utm/template-card.tsxindex 414899fc85..f23b90c447 100644--- a/apps/web/app/app.dub.co/(dashboard)/[slug]/links/utm/template-card.tsx+++ b/apps/web/app/app.dub.co/(dashboard)/[slug]/links/utm/template-card.tsx@@ -9,6 +9,7 @@ import {Button,CardList,Popover,+ TimestampTooltip,Tooltip,useKeyboardShortcut,UTM_PARAMETERS,@@ -108,7 +109,14 @@ export function TemplateCard({</Tooltip><div className="hidden text-sm text-neutral-500 sm:block">- {formatDate(template.updatedAt, { month: "short" })}+ <TimestampTooltip+ timestamp={template.updatedAt}+ rows={["local"]}+ side="left"+ delayDuration={150}+ >+ <span>{formatDate(template.updatedAt, { month: "short" })}</span>+ </TimestampTooltip></div><div className="flex items-center gap-5 sm:gap-8 md:gap-12">diff --git a/apps/web/ui/analytics/events/events-table.tsx b/apps/web/ui/analytics/events/events-table.tsxindex 291e58c3f7..86ec3091ce 100644--- a/apps/web/ui/analytics/events/events-table.tsx+++ b/apps/web/ui/analytics/events/events-table.tsx@@ -12,6 +12,7 @@ import {EditColumnsButton,LinkLogo,Table,+ TimestampTooltip,Tooltip,useColumnVisibility,usePagination,@@ -184,21 +185,16 @@ export default function EventsTable({enableHiding: false,size: 160,cell: ({ getValue }) => (- <Tooltip- content={getValue().toLocaleTimeString("en-US", {- year: "numeric",- month: "short",- day: "numeric",- hour: "numeric",- minute: "numeric",- second: "numeric",- hour12: true,- })}+ <TimestampTooltip+ timestamp={getValue()}+ side="right"+ rows={["local", "utc", "unix"]}+ interactive>- <div className="w-full truncate">+ <div className="w-full select-none truncate">{formatDateTimeSmart(getValue())}</div>- </Tooltip>+ </TimestampTooltip>),},// Sale amountdiff --git a/apps/web/ui/customers/customer-activity-list.tsx b/apps/web/ui/customers/customer-activity-list.tsxindex de7d52aecc..16d393ef6c 100644--- a/apps/web/ui/customers/customer-activity-list.tsx+++ b/apps/web/ui/customers/customer-activity-list.tsx@@ -1,5 +1,5 @@import { CustomerActivityResponse } from "@/lib/types";-import { DynamicTooltipWrapper, LinkLogo } from "@dub/ui";+import { DynamicTooltipWrapper, LinkLogo, TimestampTooltip } from "@dub/ui";import { CursorRays, MoneyBill2, UserCheck } from "@dub/ui/icons";import { formatDateTimeSmart, getApexDomain, getPrettyUrl } from "@dub/utils";import Link from "next/link";@@ -136,9 +136,16 @@ export function CustomerActivityList({</div><div className="flex min-w-0 flex-col gap-x-4 gap-y-1 whitespace-nowrap text-sm text-neutral-800 lg:grow lg:flex-row lg:justify-between"><div className="truncate">{content(event)}</div>- <span className="shrink-0 truncate text-sm text-neutral-500">- {formatDateTimeSmart(event.timestamp)}- </span>+ <TimestampTooltip+ timestamp={event.timestamp}+ side="right"+ rows={["local", "utc", "unix"]}+ interactive+ >+ <span className="shrink-0 truncate text-sm text-neutral-500">+ {formatDateTimeSmart(event.timestamp)}+ </span>+ </TimestampTooltip></div></li>);diff --git a/apps/web/ui/customers/customer-details-column.tsx b/apps/web/ui/customers/customer-details-column.tsxindex 2ab9a2fb3b..a5027cee12 100644--- a/apps/web/ui/customers/customer-details-column.tsx+++ b/apps/web/ui/customers/customer-details-column.tsx@@ -1,5 +1,5 @@import { CustomerActivityResponse, CustomerProps } from "@/lib/types";-import { CopyButton, UTM_PARAMETERS } from "@dub/ui";+import { CopyButton, TimestampTooltip, UTM_PARAMETERS } from "@dub/ui";import {capitalize,cn,@@ -123,13 +123,19 @@ export function CustomerDetailsColumn({<div className="flex flex-col gap-2"><DetailHeading>Customer since</DetailHeading>{customer ? (- <span>- {new Date(customer.createdAt).toLocaleDateString("en-US", {- month: "short",- day: "numeric",- year: "numeric",- })}- </span>+ <TimestampTooltip+ timestamp={customer.createdAt}+ rows={["local"]}+ side="left"+ >+ <span>+ {new Date(customer.createdAt).toLocaleDateString("en-US", {+ month: "short",+ day: "numeric",+ year: "numeric",+ })}+ </span>+ </TimestampTooltip>) : (<div className="h-5 w-12 animate-pulse rounded-md bg-neutral-100" />)}diff --git a/apps/web/ui/customers/customer-sales-table.tsx b/apps/web/ui/customers/customer-sales-table.tsxindex 9d5ee0f4f2..15ccb314e9 100644--- a/apps/web/ui/customers/customer-sales-table.tsx+++ b/apps/web/ui/customers/customer-sales-table.tsx@@ -1,5 +1,5 @@import { CommissionResponse, SaleEvent } from "@/lib/types";-import { StatusBadge } from "@dub/ui";+import { StatusBadge, TimestampTooltip } from "@dub/ui";import { currencyFormatter, formatDateTimeSmart, nFormatter } from "@dub/utils";import {flexRender,@@ -37,7 +37,16 @@ export function CustomerSalesTable({new Date("timestamp" in d ? d.timestamp : d.createdAt),enableHiding: false,minSize: 100,- cell: ({ getValue }) => <span>{formatDateTimeSmart(getValue())}</span>,+ cell: ({ getValue }) => (+ <TimestampTooltip+ timestamp={getValue()}+ side="right"+ rows={["local", "utc", "unix"]}+ interactive+ >+ <span>{formatDateTimeSmart(getValue())}</span>+ </TimestampTooltip>+ ),},...(sales?.length && "eventName" in sales?.[0]? [diff --git a/apps/web/ui/links/link-builder/link-creator-info.tsx b/apps/web/ui/links/link-builder/link-creator-info.tsxindex 6c6012bb4a..6f833760f0 100644--- a/apps/web/ui/links/link-builder/link-creator-info.tsx+++ b/apps/web/ui/links/link-builder/link-creator-info.tsx@@ -1,7 +1,7 @@import { ExpandedLinkProps } from "@/lib/types";import { UserAvatar } from "@/ui/links/link-title-column";-import { Tooltip } from "@dub/ui";-import { formatDateTime, timeAgo } from "@dub/utils";+import { TimestampTooltip } from "@dub/ui";+import { timeAgo } from "@dub/utils";import Link from "next/link";import { useParams } from "next/navigation";@@ -28,9 +28,14 @@ export function LinkCreatorInfo({ link }: { link: ExpandedLinkProps }) {</Link><span className="text-neutral-400">·{" "}- <Tooltip content={formatDateTime(link.createdAt)} delayDuration={150}>- <span>{timeAgo(link.createdAt)}</span>- </Tooltip>+ <TimestampTooltip+ timestamp={link.createdAt}+ rows={["local", "utc", "unix"]}+ delayDuration={150}+ interactive+ >+ <span className="select-none">{timeAgo(link.createdAt)}</span>+ </TimestampTooltip></span></div>);diff --git a/apps/web/ui/links/link-title-column.tsx b/apps/web/ui/links/link-title-column.tsxindex f6d52612d5..7d485739d4 100644--- a/apps/web/ui/links/link-title-column.tsx+++ b/apps/web/ui/links/link-title-column.tsx@@ -12,6 +12,7 @@ import {CopyButton,LinkLogo,Switch,+ TimestampTooltip,Tooltip,TooltipContent,useInViewport,@@ -32,7 +33,6 @@ import {} from "@dub/ui/icons";import {cn,- formatDateTime,getApexDomain,getPrettyUrl,isDubDomain,@@ -381,9 +381,9 @@ const Details = memo(displayProperties.includes("createdAt") && "sm:block",)}>- <Tooltip content={formatDateTime(createdAt)} delayDuration={150}>+ <TimestampTooltip timestamp={createdAt} delayDuration={150}><span className="text-neutral-400">{timeAgo(createdAt)}</span>- </Tooltip>+ </TimestampTooltip></div></div>);diff --git a/packages/ui/src/timestamp-tooltip.tsx b/packages/ui/src/timestamp-tooltip.tsxindex 77a6b52cd9..c2b6e4fca4 100644--- a/packages/ui/src/timestamp-tooltip.tsx+++ b/packages/ui/src/timestamp-tooltip.tsx@@ -1,60 +1,43 @@"use client";-import { cn, timeAgo } from "@dub/utils";-import { Tooltip } from "./tooltip";--type TimestampInput = Date | string | number;--export interface TimestampTooltipProps {- timestamp: TimestampInput;- /**- * If true, the inline display will only render the time (HH:mm:ss).- * Useful for compact layouts on mobile.- */- timeOnly?: boolean;- side?: "top" | "bottom" | "left" | "right";+import { cn } from "@dub/utils";+import { formatDuration, intervalToDuration } from "date-fns";+import { useMemo } from "react";+import { toast } from "sonner";+import { Tooltip, TooltipProps } from "./tooltip";++const DAY_MS = 24 * 60 * 60 * 1000;+const MONTH_MS = 30 * DAY_MS;++export type TimestampTooltipProps = {+ timestamp: Date | string | number | null | undefined;+ rows?: ("local" | "utc" | "unix")[];+ interactive?: boolean;className?: string;-}+} & Omit<TooltipProps, "content">;function getLocalTimeZone(): string {if (typeof Intl !== "undefined") {try {return Intl.DateTimeFormat().resolvedOptions().timeZone || "Local";- } catch (e) {- return "Local";- }+ } catch (e) {}}return "Local";}-function formatDisplay(date: Date, timeOnly?: boolean) {- const time = date.toLocaleTimeString("en-US", {- hour12: false,- hour: "2-digit",- minute: "2-digit",- second: "2-digit",- });- if (timeOnly) return time;-- // Month (short, uppercase) + 2-digit day- const datePart = date- .toLocaleDateString("en-US", { month: "short", day: "2-digit" })- .toUpperCase();- return `${datePart} ${time}`;-}-export function TimestampTooltip({timestamp,- timeOnly,+ children,+ rows = ["local", "utc"],+ interactive = false,className,- side = "top",...tooltipProps}: TimestampTooltipProps) {- const date = new Date(timestamp);+ if (!timestamp) return children;- const tz = getLocalTimeZone();+ const date = new Date(timestamp);- const inlineText = formatDisplay(date, timeOnly);+ if (date.toString() === "Invalid Date") return children;const commonFormat: Intl.DateTimeFormatOptions = {year: "numeric",@@ -66,48 +49,124 @@ export function TimestampTooltip({hour12: true,};- const localText = date.toLocaleString("en-US", commonFormat);-- const utcText = new Date(date.getTime()).toLocaleString("en-US", {- ...commonFormat,- timeZone: "UTC",+ const diff = new Date().getTime() - date.getTime();+ const relativeDuration = intervalToDuration({+ start: date,+ end: new Date(),});+ const relative =+ formatDuration(relativeDuration, {+ delimiter: ", ",+ format: [+ "years",+ "months",+ "days",+ ...(diff < MONTH_MS+ ? [+ "hours" as const,+ ...(diff < DAY_MS+ ? ["minutes" as const, "seconds" as const]+ : []),+ ]+ : []),+ ],+ }) + " ago";++ const items: {+ label: string;+ shortLabel?: string;+ value: string;+ valueMono?: boolean;+ }[] = useMemo(+ () =>+ rows.map(+ (key) =>+ ({+ local: {+ label: getLocalTimeZone(),+ shortLabel: new Date()+ .toLocaleTimeString("en-US", { timeZoneName: "short" })+ .split(" ")[2],+ value: date.toLocaleString("en-US", commonFormat),+ },++ utc: {+ label: "UTC",+ shortLabel: "UTC",+ value: new Date(date.getTime()).toLocaleString("en-US", {+ ...commonFormat,+ timeZone: "UTC",+ }),+ },++ unix: {+ label: "UNIX Timestamp",+ value: date.getTime().toString(),+ valueMono: true,+ },+ })[key]!,+ ),+ [rows, date],+ );- const unixMs = date.getTime().toString();- const relative = timeAgo(date, { withAgo: true });-- const rows: { label: string; value: string }[] = [- { label: tz, value: localText },- { label: "UTC", value: utcText },- { label: "UNIX Timestamp", value: unixMs },- { label: "Relative", value: relative },- ];+ const shortLabels = items.every(({ shortLabel }) => shortLabel);return (<Tooltip- side={side}content={- <div className="grid w-[360px] gap-2.5 px-4 py-3 text-left text-sm text-neutral-700">- {rows.map((row, idx) => (- <div- key={idx}- className="grid grid-cols-[auto,1fr] items-baseline gap-x-4"- >- <span className="max-w-[170px] truncate text-xs text-neutral-400">- {row.label}- </span>- <span className="whitespace-nowrap font-mono text-neutral-800">- {row.value}- </span>- </div>- ))}+ <div className="flex max-w-[360px] flex-col gap-2 px-2.5 py-2 text-left text-xs">+ <span className="text-content-subtle cursor-default">{relative}</span>+ <table>+ {items.map((row, idx) => (+ <tr+ key={idx}+ className={cn(+ interactive &&+ "before:bg-bg-emphasis relative select-none before:absolute before:-inset-x-1 before:inset-y-0 before:rounded before:opacity-0 before:content-[''] hover:cursor-pointer hover:before:opacity-60 active:before:opacity-100",+ )}+ onClick={+ interactive+ ? () => {+ try {+ navigator.clipboard.writeText(row.value);+ toast.success("Copied to clipboard");+ } catch (e) {+ toast.error("Failed to copy to clipboard");+ console.error("Failed to copy to clipboard", e);+ }+ }+ : undefined+ }+ >+ <td className="relative py-0.5">+ <span+ className={cn(+ "text-content-subtle truncate",+ shortLabels && "bg-bg-inverted/10 rounded px-1 font-mono",+ )}+ title={shortLabels ? row.label : undefined}+ >+ {shortLabels ? row.shortLabel : row.label}+ </span>+ </td>+ <td+ className={cn(+ "text-content-default relative whitespace-nowrap py-0.5 pl-3",+ shortLabels && "pl-2",+ row.valueMono && "font-mono",+ )}+ >+ {row.value}+ </td>+ </tr>+ ))}+ </table></div>}+ disableHoverableContent={!interactive}{...tooltipProps}>- <span className={cn("inline-block", className)} suppressHydrationWarning>- {inlineText}- </span>+ {children}</Tooltip>);}