Skip to content

Commit 16a6668

Browse files
committed
Display referral and group moves changelog
1 parent 9c51777 commit 16a6668

40 files changed

+851
-54
lines changed

apps/web/app/(ee)/api/stripe/integration/webhook/checkout-session-completed.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -479,6 +479,7 @@ export async function checkoutSessionCompleted(
479479
trigger: "partnerMetricsUpdated",
480480
reason: "sale",
481481
identity: {
482+
workspaceId: workspace.id,
482483
programId: link.programId,
483484
partnerId: link.partnerId,
484485
},
@@ -664,6 +665,7 @@ async function attributeViaPromoCode({
664665
trigger: "partnerMetricsUpdated",
665666
reason: "lead",
666667
identity: {
668+
workspaceId: workspace.id,
667669
programId: link.programId,
668670
partnerId: link.partnerId,
669671
},

apps/web/app/(ee)/api/stripe/integration/webhook/invoice-paid.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -248,6 +248,7 @@ export async function invoicePaid(event: Stripe.Event, mode: StripeMode) {
248248
trigger: "partnerMetricsUpdated",
249249
reason: "sale",
250250
identity: {
251+
workspaceId: workspace.id,
251252
programId: link.programId,
252253
partnerId: link.partnerId,
253254
},

apps/web/app/(ee)/api/stripe/integration/webhook/utils/create-new-customer.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,7 @@ export async function createNewCustomer(event: Stripe.Event) {
109109
trigger: "partnerMetricsUpdated",
110110
reason: "lead",
111111
identity: {
112+
workspaceId: workspace.id,
112113
programId: link.programId,
113114
partnerId: link.partnerId,
114115
},

apps/web/app/(ee)/api/workflows/partner-approved/route.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -390,6 +390,7 @@ export const { POST } = serve<Payload>(
390390
await executeWorkflows({
391391
trigger: "partnerEnrolled",
392392
identity: {
393+
workspaceId: program.workspaceId,
393394
programId,
394395
partnerId,
395396
},

apps/web/app/api/activity-logs/route.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { getDefaultProgramIdOrThrow } from "@/lib/api/programs/get-default-program-id-or-throw";
12
import { withWorkspace } from "@/lib/auth";
23
import {
34
activityLogSchema,
@@ -7,16 +8,19 @@ import { prisma } from "@dub/prisma";
78
import { NextResponse } from "next/server";
89
import * as z from "zod/v4";
910

10-
// GET /api/activity-logs - get activity logs for a resource
11+
// GET /api/activity-logs get activity logs for a resource
1112
export const GET = withWorkspace(async ({ workspace, searchParams }) => {
12-
const { resourceType, resourceId } =
13+
const { resourceType, resourceId, action } =
1314
getActivityLogsQuerySchema.parse(searchParams);
1415

16+
const programId = getDefaultProgramIdOrThrow(workspace);
1517
const activityLogs = await prisma.activityLog.findMany({
1618
where: {
1719
workspaceId: workspace.id,
20+
programId,
1821
resourceType,
1922
resourceId,
23+
...(action && { action }),
2024
},
2125
orderBy: {
2226
createdAt: "desc",

apps/web/lib/actions/partners/create-manual-commission.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -575,6 +575,7 @@ export const createManualCommissionAction = authActionClient
575575
trigger: "partnerMetricsUpdated",
576576
reason: "commission",
577577
identity: {
578+
workspaceId: workspace.id,
578579
programId,
579580
partnerId,
580581
},

apps/web/lib/actions/referrals/update-referral-status.ts

Lines changed: 5 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,10 @@ import { getReferralOrThrow } from "@/lib/api/referrals/get-referral-or-throw";
77
import { markReferralClosedWon } from "@/lib/api/referrals/mark-referral-closed-won";
88
import { markReferralQualified } from "@/lib/api/referrals/mark-referral-qualified";
99
import { notifyReferralStatusUpdate } from "@/lib/api/referrals/notify-referral-status-update";
10-
import { REFERRAL_STATUS_TRANSITIONS } from "@/lib/referrals/constants";
10+
import {
11+
REFERRAL_STATUS_TO_ACTIVITY_ACTION,
12+
REFERRAL_STATUS_TRANSITIONS,
13+
} from "@/lib/referrals/constants";
1114
import { ReferralWithCustomer } from "@/lib/types";
1215
import { updateReferralStatusSchema } from "@/lib/zod/schemas/referrals";
1316
import { prisma } from "@dub/prisma";
@@ -16,16 +19,6 @@ import { waitUntil } from "@vercel/functions";
1619
import { authActionClient } from "../safe-action";
1720
import { throwIfNoPermission } from "../throw-if-no-permission";
1821

19-
const REFERRAL_EVENT_TYPES = {
20-
[ReferralStatus.pending]: "referral.created",
21-
[ReferralStatus.qualified]: "referral.qualified",
22-
[ReferralStatus.meeting]: "referral.meeting",
23-
[ReferralStatus.negotiation]: "referral.negotiation",
24-
[ReferralStatus.unqualified]: "referral.unqualified",
25-
[ReferralStatus.closedWon]: "referral.closedWon",
26-
[ReferralStatus.closedLost]: "referral.closedLost",
27-
} as const;
28-
2922
export const updateReferralStatusAction = authActionClient
3023
.inputSchema(updateReferralStatusSchema)
3124
.action(async ({ parsedInput, ctx }) => {
@@ -92,7 +85,7 @@ export const updateReferralStatusAction = authActionClient
9285
resourceType: "referral",
9386
resourceId: referral.id,
9487
userId: user.id,
95-
action: REFERRAL_EVENT_TYPES[status],
88+
action: REFERRAL_STATUS_TO_ACTIVITY_ACTION[status],
9689
description: notes,
9790
changeSet: {
9891
status: {

apps/web/lib/api/activity-log/build-change-set.ts

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,6 @@
1+
import type { ChangeSet } from "@/lib/types";
12
import { PartnerGroup } from "@dub/prisma/client";
23

3-
export type FieldDiff<T = unknown> = {
4-
old: T | null;
5-
new: T | null;
6-
};
7-
8-
export type ChangeSet = Record<string, FieldDiff>;
9-
104
interface BuildProgramEnrollmentChangeSetInput {
115
oldEnrollment:
126
| { partnerGroup: Pick<PartnerGroup, "id" | "name"> | null | undefined }

apps/web/lib/api/activity-log/track-activity-log.ts

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,21 @@
11
import { logger } from "@/lib/axiom/server";
2+
import type { ChangeSet } from "@/lib/types";
23
import {
34
ActivityLogAction,
45
ActivityLogResourceType,
56
} from "@/lib/zod/schemas/activity-log";
67
import { prisma } from "@dub/prisma";
78
import { Prisma } from "@dub/prisma/client";
89
import { prettyPrint } from "@dub/utils";
9-
import { ChangeSet } from "./build-change-set";
1010

1111
export interface TrackActivityLogInput
1212
extends Pick<
1313
Prisma.ActivityLogUncheckedCreateInput,
14-
"workspaceId" | "programId" | "resourceId" | "userId" | "description"
14+
"workspaceId" | "programId" | "resourceId" | "description"
1515
> {
1616
resourceType: ActivityLogResourceType;
1717
action: ActivityLogAction;
18+
userId?: string | null;
1819
changeSet?: ChangeSet;
1920
}
2021

@@ -24,7 +25,9 @@ export const trackActivityLog = async (
2425
let inputs = Array.isArray(input) ? input : [input];
2526

2627
inputs = inputs.filter(
27-
(i) => i.changeSet && Object.keys(i.changeSet).length > 0,
28+
(i) =>
29+
i.action === "referral.created" ||
30+
(i.changeSet && Object.keys(i.changeSet).length > 0),
2831
);
2932

3033
if (inputs.length === 0) {

apps/web/lib/api/conversions/track-lead.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -327,6 +327,7 @@ export const trackLead = async ({
327327
trigger: "partnerMetricsUpdated",
328328
reason: "lead",
329329
identity: {
330+
workspaceId: workspace.id,
330331
programId: link.programId,
331332
partnerId: link.partnerId,
332333
},

0 commit comments

Comments
 (0)