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.

Display commission source

Steven Tey1a1b4c72c077
diff --git a/apps/web/app/app.dub.co/(dashboard)/[slug]/(ee)/program/partners/partners-menu-popover.tsx b/apps/web/app/app.dub.co/(dashboard)/[slug]/(ee)/program/partners/partners-menu-popover.tsx
index 3d124ffc53..8a0c953fa8 100644
--- a/apps/web/app/app.dub.co/(dashboard)/[slug]/(ee)/program/partners/partners-menu-popover.tsx
+++ b/apps/web/app/app.dub.co/(dashboard)/[slug]/(ee)/program/partners/partners-menu-popover.tsx
@@ -46,7 +46,7 @@ export function PartnersMenuPopover() {
Import Partners
</p>
- {PROGRAM_IMPORT_SOURCES.map((source) => (
+ {Object.values(PROGRAM_IMPORT_SOURCES).map((source) => (
<ImportOption
key={source.id}
onClick={() => {
diff --git a/apps/web/lib/api-logs/constants.ts b/apps/web/lib/api-logs/constants.ts
index 9b30f94280..66208c6503 100644
--- a/apps/web/lib/api-logs/constants.ts
+++ b/apps/web/lib/api-logs/constants.ts
@@ -4,6 +4,7 @@ import {
HUBSPOT_INTEGRATION_ID,
INTERCOM_INTEGRATION_ID,
SHOPIFY_INTEGRATION_ID,
+ SINGULAR_INTEGRATION_ID,
STRIPE_INTEGRATION_ID,
} from "@dub/utils";
@@ -224,6 +225,12 @@ export const WEBHOOK_REQUEST_ACTORS_BY_PATH = {
image:
"https://dubassets.com/integrations/int_1KV6R1E61E0044C0VFQKV2Q6K_PfbSFTk",
},
+ "/singular/webhook": {
+ id: SINGULAR_INTEGRATION_ID,
+ name: "Singular",
+ image:
+ "https://dubassets.com/integrations/int_1K0F60E21R1F43ZBNES3RG81P_JjFaAI8",
+ },
} as const;
export const PUBLISHABLE_KEY_ACTOR = {
diff --git a/apps/web/lib/commissions/display-commission-source.ts b/apps/web/lib/commissions/display-commission-source.ts
new file mode 100644
index 0000000000..95a12b6c2f
--- /dev/null
+++ b/apps/web/lib/commissions/display-commission-source.ts
@@ -0,0 +1,131 @@
+import { WEBHOOK_REQUEST_ACTORS_BY_PATH } from "@/lib/api-logs/constants";
+import { PROGRAM_IMPORT_SOURCES } from "@/lib/constants/program";
+import { DUB_LOGO_SQUARE } from "@dub/utils";
+import { CommissionSource, CommissionStatus } from "@prisma/client";
+
+const COMMISSION_SOURCE_DISPLAY = {
+ api: { action: "tracked by", name: "API", image: DUB_LOGO_SQUARE },
+ user: {
+ action: "created by",
+ name: "user",
+ image: "https://api.dub.co/og/avatar",
+ },
+ stripe: {
+ action: "tracked by",
+ name: "Stripe",
+ image: WEBHOOK_REQUEST_ACTORS_BY_PATH["/stripe/integration/webhook"].image,
+ },
+ shopify: {
+ action: "tracked by",
+ name: "Shopify",
+ image: WEBHOOK_REQUEST_ACTORS_BY_PATH["/shopify/integration/webhook"].image,
+ },
+ hubspot: {
+ action: "tracked by",
+ name: "HubSpot",
+ image: WEBHOOK_REQUEST_ACTORS_BY_PATH["/hubspot/webhook"].image,
+ },
+ appsflyer: {
+ action: "tracked by",
+ name: "AppsFlyer",
+ image: WEBHOOK_REQUEST_ACTORS_BY_PATH["/appsflyer/webhook"].image,
+ },
+ singular: {
+ action: "tracked by",
+ name: "Singular",
+ image: WEBHOOK_REQUEST_ACTORS_BY_PATH["/singular/webhook"].image,
+ },
+ rewardful: {
+ action: "imported from",
+ name: PROGRAM_IMPORT_SOURCES.rewardful.value,
+ image: PROGRAM_IMPORT_SOURCES.rewardful.image,
+ },
+ partnerstack: {
+ action: "imported from",
+ name: "PartnerStack",
+ image: PROGRAM_IMPORT_SOURCES.partnerstack.image,
+ },
+ firstpromoter: {
+ action: "imported from",
+ name: "FirstPromoter",
+ image: PROGRAM_IMPORT_SOURCES.firstpromoter.image,
+ },
+ tolt: {
+ action: "imported from",
+ name: "Tolt",
+ image: PROGRAM_IMPORT_SOURCES.tolt.image,
+ },
+ tapfiliate: {
+ action: "imported from",
+ name: "Tapfiliate",
+ image: PROGRAM_IMPORT_SOURCES.tapfiliate.image,
+ },
+ lemonsqueezy: {
+ action: "imported from",
+ name: "Lemon Squeezy",
+ image: PROGRAM_IMPORT_SOURCES.lemonsqueezy.image,
+ },
+ affiliatewp: {
+ action: "imported from",
+ name: "AffiliateWP",
+ image: "https://assets.dub.co/misc/icons/affiliatewp.svg",
+ },
+} as const satisfies Record<
+ CommissionSource,
+ {
+ action: "tracked by" | "imported from" | "created by";
+ name: string;
+ image: string;
+ }
+>;
+
+export function getCommissionSourceDisplay(
+ source: CommissionSource | null | undefined,
+) {
+ if (!source) return null;
+
+ const { action, name, image } = COMMISSION_SOURCE_DISPLAY[source];
+
+ return {
+ source,
+ action,
+ name,
+ image,
+ phrase: `${action} ${name}`,
+ };
+}
+
+export function getCommissionCreatedActivity({
+ source,
+ status,
+ hasActivityLogs,
+ hasUser = false,
+}: {
+ source: CommissionSource | null | undefined;
+ status: CommissionStatus;
+ hasActivityLogs: boolean;
+ hasUser?: boolean;
+}): {
+ lead: string;
+ status: CommissionStatus;
+ showUser: boolean;
+} {
+ const createdStatus =
+ status !== "pending" && !hasActivityLogs ? status : "pending";
+
+ const display = getCommissionSourceDisplay(source);
+
+ if (display) {
+ return {
+ lead: `Commission ${display.action}`,
+ status: createdStatus,
+ showUser: display.source === "user" && hasUser,
+ };
+ }
+
+ return {
+ lead: createdStatus === "pending" ? "Commission" : "Commission imported as",
+ status: createdStatus,
+ showUser: false,
+ };
+}
diff --git a/apps/web/lib/constants/program.ts b/apps/web/lib/constants/program.ts
index f5f8ea1937..d8aa2f4366 100644
--- a/apps/web/lib/constants/program.ts
+++ b/apps/web/lib/constants/program.ts
@@ -6,44 +6,44 @@ export const MAX_PARTNERS_INVITES_PER_REQUEST = 50;
export const MAX_PROGRAM_CATEGORIES = 3;
export const PROGRAM_SIMILARITY_SCORE_THRESHOLD = 0.3;
-export const PROGRAM_IMPORT_SOURCES = [
- {
+export const PROGRAM_IMPORT_SOURCES = {
+ rewardful: {
id: "rewardful",
value: "Rewardful",
image: "https://assets.dub.co/misc/icons/rewardful.svg",
helpUrl: "https://dub.co/help/article/migrating-from-rewardful",
},
- {
+ tolt: {
id: "tolt",
value: "Tolt",
image: "https://assets.dub.co/misc/icons/tolt.svg",
helpUrl: "https://dub.co/help/article/migrating-from-tolt",
},
- {
+ partnerstack: {
id: "partnerstack",
value: "PartnerStack",
image: "https://assets.dub.co/misc/icons/partnerstack.svg",
helpUrl: "https://dub.co/help/article/migrating-from-partnerstack",
},
- {
+ firstpromoter: {
id: "firstpromoter",
value: "FirstPromoter",
image: "https://assets.dub.co/misc/icons/firstpromoter.svg",
helpUrl: "https://dub.co/help/article/migrating-from-firstpromoter",
},
- {
+ tapfiliate: {
id: "tapfiliate",
value: "Tapfiliate",
image: "https://assets.dub.co/misc/icons/tapfiliate.svg",
helpUrl: "https://dub.co/help/article/migrating-from-tapfiliate",
},
- {
+ lemonsqueezy: {
id: "lemonsqueezy",
value: "Lemon Squeezy",
image: "https://assets.dub.co/misc/icons/lemonsqueezy.svg",
helpUrl: "https://dub.co/help/article/migrating-from-lemonsqueezy",
},
-] as const;
+};
export const PROGRAM_APPLICATION_IMAGE_MAX_FILE_SIZE_MB = 5;
diff --git a/apps/web/lib/zod/schemas/commissions.ts b/apps/web/lib/zod/schemas/commissions.ts
index 699ba6ed15..252350ab9b 100644
--- a/apps/web/lib/zod/schemas/commissions.ts
+++ b/apps/web/lib/zod/schemas/commissions.ts
@@ -94,6 +94,10 @@ export const CommissionEnrichedSchema = CommissionSchema.extend({
// Schema for the commission detail page (GET /api/commissions/:commissionId)
// TODO: Simplify this for OpenAPI and limit extra fields to in-app only – similar to getLinkInfoQuerySchemaExtended logic
export const CommissionDetailSchema = CommissionEnrichedSchema.extend({
+ source: z
+ .enum(CommissionSource)
+ .nullable()
+ .describe("Where the commission originated."),
user: UserSchema.nullish().describe("The user who created the commission."),
reward: RewardSchema.pick({
event: true,
diff --git a/apps/web/tests/commissions/display-commission-source.test.ts b/apps/web/tests/commissions/display-commission-source.test.ts
new file mode 100644
index 0000000000..98b35a80a5
--- /dev/null
+++ b/apps/web/tests/commissions/display-commission-source.test.ts
@@ -0,0 +1,126 @@
+import {
+ getCommissionCreatedActivity,
+ getCommissionSourceDisplay,
+} from "@/lib/commissions/display-commission-source";
+import { PROGRAM_IMPORT_SOURCES } from "@/lib/constants/program";
+import { CommissionSource } from "@prisma/client";
+import { describe, expect, test } from "vitest";
+
+describe("getCommissionSourceDisplay", () => {
+ test("returns null when the commission has no source", () => {
+ expect(getCommissionSourceDisplay(null)).toBeNull();
+ expect(getCommissionSourceDisplay(undefined)).toBeNull();
+ });
+
+ test.each([
+ ["rewardful", "imported from Rewardful"],
+ ["partnerstack", "imported from PartnerStack"],
+ ["firstpromoter", "imported from FirstPromoter"],
+ ["tolt", "imported from Tolt"],
+ ["tapfiliate", "imported from Tapfiliate"],
+ ["lemonsqueezy", "imported from Lemon Squeezy"],
+ ["affiliatewp", "imported from AffiliateWP"],
+ ] as const)("describes %s as %s", (source, phrase) => {
+ expect(getCommissionSourceDisplay(source)?.phrase).toBe(phrase);
+ });
+
+ test.each([
+ ["api", "tracked by API"],
+ ["user", "created by user"],
+ ["stripe", "tracked by Stripe"],
+ ["shopify", "tracked by Shopify"],
+ ["hubspot", "tracked by HubSpot"],
+ ["appsflyer", "tracked by AppsFlyer"],
+ ["singular", "tracked by Singular"],
+ ] as const)("describes %s as %s", (source, phrase) => {
+ expect(getCommissionSourceDisplay(source)?.phrase).toBe(phrase);
+ });
+
+ test("covers every commission source", () => {
+ for (const source of Object.values(CommissionSource)) {
+ const display = getCommissionSourceDisplay(source);
+
+ expect(display?.phrase).toBeTruthy();
+ expect(display?.image || source === "user").toBeTruthy();
+ }
+ });
+
+ test("reuses import source artwork", () => {
+ for (const source of Object.values(PROGRAM_IMPORT_SOURCES)) {
+ expect(
+ getCommissionSourceDisplay(source.id as CommissionSource)?.image,
+ ).toBe(source.image);
+ }
+ });
+});
+
+describe("getCommissionCreatedActivity", () => {
+ test("uses the source phrase and pending when later activity exists", () => {
+ expect(
+ getCommissionCreatedActivity({
+ source: "stripe",
+ status: "paid",
+ hasActivityLogs: true,
+ }),
+ ).toEqual({
+ lead: "Commission tracked by",
+ status: "pending",
+ showUser: false,
+ });
+ });
+
+ test("keeps the imported status when there is no activity history", () => {
+ expect(
+ getCommissionCreatedActivity({
+ source: "rewardful",
+ status: "paid",
+ hasActivityLogs: false,
+ }),
+ ).toEqual({
+ lead: "Commission imported from",
+ status: "paid",
+ showUser: false,
+ });
+ });
+
+ test("points a manual commission at the creating user", () => {
+ expect(
+ getCommissionCreatedActivity({
+ source: "user",
+ status: "pending",
+ hasActivityLogs: false,
+ hasUser: true,
+ }),
+ ).toEqual({
+ lead: "Commission created by",
+ status: "pending",
+ showUser: true,
+ });
+ });
+
+ test("falls back to the previous copy when source is missing", () => {
+ expect(
+ getCommissionCreatedActivity({
+ source: null,
+ status: "processed",
+ hasActivityLogs: false,
+ }),
+ ).toEqual({
+ lead: "Commission imported as",
+ status: "processed",
+ showUser: false,
+ });
+
+ expect(
+ getCommissionCreatedActivity({
+ source: null,
+ status: "pending",
+ hasActivityLogs: false,
+ }),
+ ).toEqual({
+ lead: "Commission",
+ status: "pending",
+ showUser: false,
+ });
+ });
+});
diff --git a/apps/web/ui/activity-logs/commission-activity.tsx b/apps/web/ui/activity-logs/commission-activity.tsx
index 4697034c79..447fc244b2 100644
--- a/apps/web/ui/activity-logs/commission-activity.tsx
+++ b/apps/web/ui/activity-logs/commission-activity.tsx
@@ -1,5 +1,9 @@
"use client";
+import {
+ getCommissionCreatedActivity,
+ getCommissionSourceDisplay,
+} from "@/lib/commissions/display-commission-source";
import { useActivityLogs } from "@/lib/swr/use-activity-logs";
import {
ActivityLog,
@@ -61,6 +65,60 @@ function parseChangeSet(log: ActivityLog) {
};
}
+function ActivityPill({
+ icon,
+ label,
+}: {
+ icon: React.ReactNode;
+ label: string;
+}) {
+ return (
+ <div className="flex h-6 items-center gap-2 rounded-lg bg-neutral-100 px-2 py-1">
+ {icon}
+ <span className="text-[13px] text-neutral-700">{label}</span>
+ </div>
+ );
+}
+
+function ActivityUserPill({
+ user,
+}: {
+ user: {
+ id?: string | null;
+ name?: string | null;
+ email?: string | null;
+ image?: string | null;
+ };
+}) {
+ return (
+ <ActivityPill
+ icon={<UserAvatar user={user} className="size-4" />}
+ label={user.name || user.email || "Deleted user"}
+ />
+ );
+}
+
+function ActivitySourcePill({
+ image,
+ label,
+}: {
+ image: string;
+ label: string;
+}) {
+ return (
+ <ActivityPill
+ icon={
+ <img
+ src={image}
+ alt=""
+ className="size-4 shrink-0 rounded-full border border-neutral-200"
+ />
+ }
+ label={label}
+ />
+ );
+}
+
function getCommissionNote({
description,
reward,
@@ -122,44 +180,42 @@ export function CommissionActivity({
);
}
- const createdEvent =
- commission.status !== "pending" && activityLogs?.length === 0
- ? {
- key: "created",
- icon: CommissionStatusBadges[commission.status].icon,
- timestamp: commission.createdAt,
- note: getCommissionNote(commission),
- children: (
- <>
- <span className="text-sm text-neutral-700">
- Commission imported as
- </span>
- <StatusBadge
- icon={null}
- variant={CommissionStatusBadges[commission.status].variant}
- >
- {CommissionStatusBadges[commission.status].label}
- </StatusBadge>
- </>
- ),
- }
- : {
- key: "created",
- icon: CommissionStatusBadges["pending"].icon,
- timestamp: commission.createdAt,
- note: getCommissionNote(commission),
- children: (
- <>
- <span className="text-sm text-neutral-700">Commission</span>
- <StatusBadge
- icon={null}
- variant={CommissionStatusBadges["pending"].variant}
- >
- {CommissionStatusBadges["pending"].label}
- </StatusBadge>
- </>
- ),
- };
+ const sourceDisplay = getCommissionSourceDisplay(commission.source);
+ const created = getCommissionCreatedActivity({
+ source: commission.source,
+ status: commission.status,
+ hasActivityLogs: (activityLogs?.length ?? 0) > 0,
+ hasUser: !!commission.user,
+ });
+ const createdBadge = CommissionStatusBadges[created.status];
+
+ const createdEvent = {
+ key: "created",
+ icon: createdBadge.icon,
+ timestamp: commission.createdAt,
+ note: getCommissionNote(commission),
+ children: (
+ <>
+ <span className="text-sm text-neutral-700">{created.lead}</span>
+ {created.showUser && commission.user ? (
+ <ActivityUserPill user={commission.user} />
+ ) : sourceDisplay ? (
+ <ActivitySourcePill
+ image={
+ sourceDisplay.image ?? "https://assets.dub.co/logo-square.png"
+ }
+ label={sourceDisplay.name}
+ />
+ ) : null}
+ {created.lead === "Commission imported as" ? null : (
+ <span className="text-sm text-neutral-700">as</span>
+ )}
+ <StatusBadge icon={null} variant={createdBadge.variant}>
+ {createdBadge.label}
+ </StatusBadge>
+ </>
+ ),
+ };
const fmt = (v: number) =>
currencyFormatter(v, { trailingZeroDisplay: "stripIfInteger" });
@@ -192,12 +248,7 @@ export function CommissionActivity({
const userByline = log.user ? (
<>
<span className="text-sm text-neutral-500">by</span>
- <div className="flex h-6 items-center gap-2 rounded-lg bg-neutral-100 px-2 py-1">
- <UserAvatar user={log.user} className="size-4" />
- <span className="text-[13px] text-neutral-700">
- {log.user.name || log.user.email || "Deleted user"}
- </span>
- </div>
+ <ActivityUserPill user={log.user} />
</>
) : null;
diff --git a/packages/utils/src/constants/integrations.ts b/packages/utils/src/constants/integrations.ts
index b8b7dc08bf..c714f5dc7d 100644
--- a/packages/utils/src/constants/integrations.ts
+++ b/packages/utils/src/constants/integrations.ts
@@ -7,3 +7,4 @@ export const HUBSPOT_INTEGRATION_ID = "int_ffw3qgrFAahY6qs1hXaH3wHS";
export const APPSFLYER_INTEGRATION_ID = "int_1KN8JP7ET3VQQRF7ZQEVNFPJ5";
export const INTERCOM_INTEGRATION_ID = "int_1KV6R1E61E0044C0VFQKV2Q6K";
export const GOOGLE_ADS_INTEGRATION_ID = "int_1M096GK5Q66FJ78WQAH82SD7V";
+export const SINGULAR_INTEGRATION_ID = "int_1K0F60E21R1F43ZBNES3RG81P";