Skip to content

armgit / dub

Public Imported from GitHub
0

The modern link attribution platform. Loved by world-class engineering teams at Twilio, Zillow, Jobber, Vercel, Raycast, and more.

add TimestampTooltip

Steven Tey4d1b519207d2
diff --git a/apps/web/scripts/migrations/backfill-reward-activity-log.ts b/apps/web/scripts/migrations/backfill-reward-activity-log.ts
new file mode 100644
index 0000000000..6ddac84a15
--- /dev/null
+++ b/apps/web/scripts/migrations/backfill-reward-activity-log.ts
@@ -0,0 +1,66 @@
+import { trackActivityLog } from "@/lib/api/activity-log/track-activity-log";
+import { serializeReward } from "@/lib/api/partners/serialize-reward";
+import { RewardProps } from "@/lib/types";
+import { REWARD_EVENT_TO_RESOURCE_TYPE } from "@/lib/zod/schemas/activity-log";
+import { prisma } from "@dub/prisma";
+import { Reward } from "@dub/prisma/client";
+import { ACME_PROGRAM_ID } from "@dub/utils";
+import "dotenv-flow/config";
+
+function toRewardActivitySnapshot(reward: RewardProps) {
+ return {
+ event: reward.event,
+ type: reward.type,
+ amountInCents: reward.amountInCents ?? null,
+ amountInPercentage: reward.amountInPercentage ?? null,
+ maxDuration: reward.maxDuration ?? null,
+ description: reward.description ?? null,
+ tooltipDescription: reward.tooltipDescription ?? null,
+ modifiers: reward.modifiers ?? null,
+ };
+}
+
+// REMOVE the following before running this script:
+// - "server-only" from serialize-reward.ts
+// - import { logger } from "@/lib/axiom/server" from track-activity-log.ts
+async function main() {
+ const rewards = await prisma.reward.findMany({
+ where: {
+ programId: ACME_PROGRAM_ID,
+ },
+ include: {
+ program: true,
+ clickPartnerGroup: true,
+ leadPartnerGroup: true,
+ salePartnerGroup: true,
+ },
+ });
+
+ if (rewards.length === 0) {
+ return;
+ }
+
+ await trackActivityLog(
+ rewards.map((reward) => ({
+ workspaceId: reward.program.workspaceId,
+ programId: reward.program.id,
+ resourceId: reward.id,
+ parentResourceType: "reward",
+ parentResourceId:
+ reward.clickPartnerGroup?.id ??
+ reward.leadPartnerGroup?.id ??
+ reward.salePartnerGroup?.id,
+ resourceType: REWARD_EVENT_TO_RESOURCE_TYPE[reward.event],
+ action: "reward.created",
+ createdAt: reward.createdAt,
+ changeSet: {
+ reward: {
+ old: null,
+ new: toRewardActivitySnapshot(serializeReward(reward as Reward)),
+ },
+ },
+ })),
+ );
+}
+
+main();
diff --git a/apps/web/ui/activity-logs/action-renderers/reward-activity-renderer.tsx b/apps/web/ui/activity-logs/action-renderers/reward-activity-renderer.tsx
index b225ecd4cc..f20beeec89 100644
--- a/apps/web/ui/activity-logs/action-renderers/reward-activity-renderer.tsx
+++ b/apps/web/ui/activity-logs/action-renderers/reward-activity-renderer.tsx
@@ -3,6 +3,7 @@
import { ActivityLog, ActivityLogAction, RewardProps } from "@/lib/types";
import { ProgramRewardDescription } from "@/ui/partners/program-reward-description";
import { ProgramRewardModifiersTooltipContent } from "@/ui/partners/program-reward-modifiers-tooltip";
+import { TimestampTooltip } from "@dub/ui";
import { formatDate } from "@dub/utils";
import { UserAvatar } from "../activity-entry-chips";
@@ -88,14 +89,20 @@ export function RewardActivityRenderer({ log }: RewardActivityRendererProps) {
</span>
</div>
- <time className="shrink-0 text-sm font-normal text-neutral-500">
- {formatDate(log.createdAt, {
- month: "short",
- year: "numeric",
- hour: "numeric",
- minute: "2-digit",
- })}
- </time>
+ <TimestampTooltip
+ timestamp={log.createdAt}
+ side="left"
+ rows={["local", "utc", "unix"]}
+ >
+ <time className="shrink-0 text-xs font-normal text-neutral-500">
+ {formatDate(log.createdAt, {
+ month: "short",
+ year: "numeric",
+ hour: "numeric",
+ minute: "2-digit",
+ })}
+ </time>
+ </TimestampTooltip>
</div>
<div className="rounded-lg border border-neutral-200 bg-white px-3 py-2.5 text-xs font-medium leading-4 text-neutral-800">
diff --git a/apps/web/ui/activity-logs/partner-group-activity-item.tsx b/apps/web/ui/activity-logs/partner-group-activity-item.tsx
index d27300be71..4353936e8c 100644
--- a/apps/web/ui/activity-logs/partner-group-activity-item.tsx
+++ b/apps/web/ui/activity-logs/partner-group-activity-item.tsx
@@ -1,4 +1,5 @@
import { ActivityLog } from "@/lib/types";
+import { TimestampTooltip } from "@dub/ui";
import { formatDate } from "@dub/utils";
import {
getActivityLogIcon,
@@ -41,14 +42,20 @@ export function PartnerGroupActivityItem({
<div className="flex min-w-0 flex-wrap items-center gap-1.5 text-sm text-neutral-700">
<Renderer log={log} />
</div>
- <time className="text-xs text-neutral-500">
- {formatDate(log.createdAt, {
- month: "short",
- year: "numeric",
- hour: "numeric",
- minute: "2-digit",
- })}
- </time>
+ <TimestampTooltip
+ timestamp={log.createdAt}
+ side="left"
+ rows={["local", "utc", "unix"]}
+ >
+ <time className="text-xs text-neutral-500">
+ {formatDate(log.createdAt, {
+ month: "short",
+ year: "numeric",
+ hour: "numeric",
+ minute: "2-digit",
+ })}
+ </time>
+ </TimestampTooltip>
</div>
</li>
);
diff --git a/apps/web/ui/activity-logs/referral-activity-item.tsx b/apps/web/ui/activity-logs/referral-activity-item.tsx
index a0b4340696..edfc763395 100644
--- a/apps/web/ui/activity-logs/referral-activity-item.tsx
+++ b/apps/web/ui/activity-logs/referral-activity-item.tsx
@@ -1,4 +1,5 @@
import { ActivityLog } from "@/lib/types";
+import { TimestampTooltip } from "@dub/ui";
import { formatDate } from "@dub/utils";
import { ActivityLogDescription } from "./activity-log-description";
import {
@@ -43,14 +44,20 @@ export function ReferralActivityItem({
<span className="flex min-w-0 flex-1 flex-wrap items-center gap-2 overflow-hidden">
<Renderer log={log} />
</span>
- <time className="hidden shrink-0 text-xs text-neutral-500 sm:block">
- {formatDate(log.createdAt, {
- month: "short",
- year: "numeric",
- hour: "numeric",
- minute: "2-digit",
- })}
- </time>
+ <TimestampTooltip
+ timestamp={log.createdAt}
+ side="right"
+ rows={["local", "utc", "unix"]}
+ >
+ <time className="hidden shrink-0 text-xs text-neutral-500 sm:block">
+ {formatDate(log.createdAt, {
+ month: "short",
+ year: "numeric",
+ hour: "numeric",
+ minute: "2-digit",
+ })}
+ </time>
+ </TimestampTooltip>
</div>
{log.description && <ActivityLogDescription log={log} />}
</div>
diff --git a/apps/web/ui/activity-logs/reward-history-sheet.tsx b/apps/web/ui/activity-logs/reward-history-sheet.tsx
index ea0160ef5b..70d672391b 100644
--- a/apps/web/ui/activity-logs/reward-history-sheet.tsx
+++ b/apps/web/ui/activity-logs/reward-history-sheet.tsx
@@ -6,15 +6,10 @@ import { RewardProps } from "@/lib/types";
import { REWARD_EVENT_TO_RESOURCE_TYPE } from "@/lib/zod/schemas/activity-log";
import { X } from "@/ui/shared/icons";
import { Button, Sheet } from "@dub/ui";
+import { capitalize } from "@dub/utils";
import { Dispatch, SetStateAction, useState } from "react";
import { RewardActivitySection } from "./reward-activity-section";
-const REWARD_EVENT_TITLES: Record<RewardProps["event"], string> = {
- sale: "Sale reward history",
- lead: "Lead reward history",
- click: "Click reward history",
-};
-
interface RewardHistorySheetProps {
reward: Pick<RewardProps, "id" | "event"> | null;
isOpen: boolean;
@@ -32,7 +27,7 @@ function RewardHistorySheetContent({
<div className="flex size-full flex-col">
<div className="flex h-16 shrink-0 items-center justify-between border-b border-neutral-200 px-6 py-4">
<Sheet.Title className="text-lg font-semibold">
- {REWARD_EVENT_TITLES[reward.event]}
+ {capitalize(reward.event)} reward history
</Sheet.Title>
<Sheet.Close asChild>
<Button