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.

Enhance activity logs for partner referrals

Kiran Kc2d062f10a73
diff --git a/apps/web/app/(ee)/api/partner-profile/programs/[programId]/activity-logs/route.ts b/apps/web/app/(ee)/api/partner-profile/programs/[programId]/activity-logs/route.ts
index db22ad271d..763140260d 100644
--- a/apps/web/app/(ee)/api/partner-profile/programs/[programId]/activity-logs/route.ts
+++ b/apps/web/app/(ee)/api/partner-profile/programs/[programId]/activity-logs/route.ts
@@ -14,6 +14,14 @@ export const GET = withPartnerProfile(
const { resourceType, resourceId, action } =
getActivityLogsQuerySchema.parse(searchParams);
+ // Limit to referral for now
+ if (resourceType !== "referral") {
+ throw new DubApiError({
+ code: "bad_request",
+ message: "Resource type must be referral.",
+ });
+ }
+
const programEnrollment = await getProgramEnrollmentOrThrow({
partnerId: partner.id,
programId: params.programId,
diff --git a/apps/web/lib/zod/schemas/activity-log.ts b/apps/web/lib/zod/schemas/activity-log.ts
index 18d0897aa6..526c306a5e 100644
--- a/apps/web/lib/zod/schemas/activity-log.ts
+++ b/apps/web/lib/zod/schemas/activity-log.ts
@@ -39,5 +39,5 @@ export const activityLogSchema = z.object({
description: z.string().nullable(),
changeSet: z.record(z.string(), fieldDiffSchema).nullable(),
createdAt: z.date(),
- user: UserSchema.nullable(),
+ user: UserSchema.nullable().default(null),
});
diff --git a/apps/web/ui/activity-logs/action-renderers/referral-created-renderer.tsx b/apps/web/ui/activity-logs/action-renderers/referral-created-renderer.tsx
index a0590cb44c..80d299de70 100644
--- a/apps/web/ui/activity-logs/action-renderers/referral-created-renderer.tsx
+++ b/apps/web/ui/activity-logs/action-renderers/referral-created-renderer.tsx
@@ -4,6 +4,7 @@ import { ActivityLog } from "@/lib/types";
import { FilePen } from "@dub/ui";
import { ReactNode } from "react";
import { ActorChip, SourcePill } from "../activity-entry-chips";
+import { useActivityLogContext } from "../activity-log-context";
function Label({ children }: { children: ReactNode }) {
return (
@@ -11,8 +12,22 @@ function Label({ children }: { children: ReactNode }) {
);
}
-export function ReferralCreatedRenderer({ log }: { log: ActivityLog }) {
- return (
+interface ReferralCreatedRendererProps {
+ log: ActivityLog;
+}
+
+export function ReferralCreatedRenderer({ log }: ReferralCreatedRendererProps) {
+ const { view } = useActivityLogContext();
+
+ return view === "partner" ? (
+ <>
+ <Label>Submitted via</Label>
+ <SourcePill
+ icon={<FilePen className="size-4 text-black" />}
+ label="Submission form"
+ />
+ </>
+ ) : (
<>
<Label>Submitted by</Label>
<ActorChip log={log} />
diff --git a/apps/web/ui/activity-logs/action-renderers/referral-status-changed-renderer.tsx b/apps/web/ui/activity-logs/action-renderers/referral-status-changed-renderer.tsx
index ae21fd3591..58ba2cc936 100644
--- a/apps/web/ui/activity-logs/action-renderers/referral-status-changed-renderer.tsx
+++ b/apps/web/ui/activity-logs/action-renderers/referral-status-changed-renderer.tsx
@@ -16,7 +16,13 @@ function Label({ children }: { children: ReactNode }) {
);
}
-export function ReferralStatusChangedRenderer({ log }: { log: ActivityLog }) {
+interface ReferralStatusChangedRendererProps {
+ log: ActivityLog;
+}
+
+export function ReferralStatusChangedRenderer({
+ log,
+}: ReferralStatusChangedRendererProps) {
const statusChange = log.changeSet?.status as StatusChangeSet | undefined;
const status = statusChange?.new ?? null;
diff --git a/apps/web/ui/activity-logs/activity-entry-chips.tsx b/apps/web/ui/activity-logs/activity-entry-chips.tsx
index a2aa2f66c6..ef694f43ee 100644
--- a/apps/web/ui/activity-logs/activity-entry-chips.tsx
+++ b/apps/web/ui/activity-logs/activity-entry-chips.tsx
@@ -1,10 +1,11 @@
-import { ActivityLog, GroupProps } from "@/lib/types";
+import { ActivityLog, GroupProps, ProgramProps } from "@/lib/types";
import { getResourceColorData, RAINBOW_CONIC_GRADIENT } from "@/ui/colors";
import { ReferralStatusBadges } from "@/ui/referrals/referral-status-badges";
import { ReferralStatus } from "@dub/prisma/client";
import { Bolt } from "@dub/ui";
import { cn, OG_AVATAR_URL } from "@dub/utils";
import { ReactNode } from "react";
+import { useActivityLogContext } from "./activity-log-context";
import { getActorType } from "./activity-log-registry";
interface ActivityChipProps {
children: ReactNode;
@@ -22,6 +23,10 @@ interface UserChipProps {
user: NonNullable<ActivityLog["user"]>;
}
+interface ProgramChipProps {
+ program: Pick<ProgramProps, "name" | "logo">;
+}
+
interface ActorChipProps {
log: ActivityLog;
}
@@ -81,6 +86,19 @@ export function UserChip({ user }: UserChipProps) {
);
}
+export function ProgramChip({ program }: ProgramChipProps) {
+ return (
+ <ActivityChip>
+ <img
+ src={program.logo || `${OG_AVATAR_URL}${program.name}`}
+ alt={program.name}
+ className="size-4 shrink-0 rounded-full"
+ />
+ {program.name}
+ </ActivityChip>
+ );
+}
+
export function SystemChip() {
return (
<ActivityChip>
@@ -92,6 +110,11 @@ export function SystemChip() {
export function ActorChip({ log }: ActorChipProps) {
const actorType = getActorType(log);
+ const { program } = useActivityLogContext();
+
+ if (program) {
+ return <ProgramChip program={program} />;
+ }
if (actorType === "USER" && log.user) {
return <UserChip user={log.user} />;
diff --git a/apps/web/ui/activity-logs/activity-log-context.tsx b/apps/web/ui/activity-logs/activity-log-context.tsx
new file mode 100644
index 0000000000..26f811d11f
--- /dev/null
+++ b/apps/web/ui/activity-logs/activity-log-context.tsx
@@ -0,0 +1,41 @@
+"use client";
+
+import { ProgramProps } from "@/lib/types";
+import { createContext, ReactNode, useContext } from "react";
+
+export type ActivityLogView = "program" | "partner";
+
+export interface ActivityLogContextValue {
+ program: Pick<ProgramProps, "id" | "name" | "logo"> | null;
+ view: ActivityLogView;
+}
+
+const ActivityLogContext = createContext<ActivityLogContextValue>({
+ program: null,
+ view: "program",
+});
+
+export function ActivityLogProvider({
+ program,
+ view = "program",
+ children,
+}: {
+ program?: Pick<ProgramProps, "id" | "name" | "logo"> | null;
+ view?: ActivityLogView;
+ children: ReactNode;
+}) {
+ const value: ActivityLogContextValue = {
+ program: program ?? null,
+ view,
+ };
+
+ return (
+ <ActivityLogContext.Provider value={value}>
+ {children}
+ </ActivityLogContext.Provider>
+ );
+}
+
+export function useActivityLogContext(): ActivityLogContextValue {
+ return useContext(ActivityLogContext);
+}
diff --git a/apps/web/ui/activity-logs/activity-log-description.tsx b/apps/web/ui/activity-logs/activity-log-description.tsx
index 1d1e301b9d..cf3eb1927f 100644
--- a/apps/web/ui/activity-logs/activity-log-description.tsx
+++ b/apps/web/ui/activity-logs/activity-log-description.tsx
@@ -1,33 +1,60 @@
import { ActivityLog } from "@/lib/types";
import { OG_AVATAR_URL, timeAgo } from "@dub/utils";
+import { useActivityLogContext } from "./activity-log-context";
interface ActivityLogDescriptionProps {
log: ActivityLog;
}
-export function ActivityLogDescription({ log }: ActivityLogDescriptionProps) {
- const { user, description, createdAt } = log;
+interface Actor {
+ id: string;
+ name: string;
+ image: string;
+}
+
+export function ActivityLogDescription({
+ log: { user, description, createdAt },
+}: ActivityLogDescriptionProps) {
+ const { program } = useActivityLogContext();
+
+ let actor: Actor | null = null;
+
+ if (program) {
+ actor = {
+ id: program.id,
+ name: program.name,
+ image: program.logo || `${OG_AVATAR_URL}${program.id}`,
+ };
+ } else if (user) {
+ actor = {
+ id: user.id,
+ name: user.name || user.email || "Unknown user",
+ image: user.image || `${OG_AVATAR_URL}${user.id}`,
+ };
+ }
return (
<div className="mt-2 rounded-xl border border-neutral-200 px-4 py-3">
<div className="flex items-center gap-1.5 text-xs">
- {user && (
+ {actor && (
<>
<img
- src={user.image || `${OG_AVATAR_URL}${user.id}`}
- alt={user.name || ""}
+ src={actor.image}
+ alt={actor.name}
className="size-4 shrink-0 rounded-full"
/>
<span className="text-content-default font-semibold">
- {user.name || user.email || "Unknown user"}
+ {actor.name}
</span>
<span className="text-content-muted">·</span>
</>
)}
+
<span className="text-content-subtle font-normal">
{timeAgo(createdAt, { withAgo: true })}
</span>
</div>
+
{description && (
<p className="text-content-subtle mt-2 text-sm">{description}</p>
)}
diff --git a/apps/web/ui/activity-logs/partner-referral-activity-section.tsx b/apps/web/ui/activity-logs/partner-referral-activity-section.tsx
index c10c15be04..e5cfd9d107 100644
--- a/apps/web/ui/activity-logs/partner-referral-activity-section.tsx
+++ b/apps/web/ui/activity-logs/partner-referral-activity-section.tsx
@@ -6,6 +6,7 @@ import {
ActivityFeed,
ActivityFeedSkeleton,
} from "@/ui/activity-logs/activity-feed";
+import { ActivityLogProvider } from "@/ui/activity-logs/activity-log-context";
export function PartnerReferralActivitySection({
referralId,
@@ -44,11 +45,9 @@ export function PartnerReferralActivitySection({
Failed to load activity. Please try again.
</p>
) : (
- <ActivityFeed
- logs={logs}
- resourceType="referral"
- programChip={program}
- />
+ <ActivityLogProvider program={program} view="partner">
+ <ActivityFeed logs={logs} resourceType="referral" />
+ </ActivityLogProvider>
)}
</section>
);
diff --git a/apps/web/ui/referrals/partner-profile-referral-sheet.tsx b/apps/web/ui/referrals/partner-profile-referral-sheet.tsx
index 022caa7580..523157f701 100644
--- a/apps/web/ui/referrals/partner-profile-referral-sheet.tsx
+++ b/apps/web/ui/referrals/partner-profile-referral-sheet.tsx
@@ -1,4 +1,5 @@
import { PartnerProfileReferral } from "@/lib/zod/schemas/partner-profile";
+import { PartnerReferralActivitySection } from "@/ui/activity-logs/partner-referral-activity-section";
import { X } from "@/ui/shared/icons";
import {
Button,
@@ -9,7 +10,6 @@ import {
useRouterStuff,
} from "@dub/ui";
import { Dispatch, SetStateAction } from "react";
-import { PartnerReferralActivitySection } from "@/ui/activity-logs/partner-referral-activity-section";
import { ReferralDetails } from "./referral-details";
import { ReferralLeadDetails } from "./referral-lead-details";