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.

fix partner customer activity

Steven Tey68c092480875
diff --git a/apps/web/app/(ee)/api/partner-profile/programs/[programId]/customers/[customerId]/route.ts b/apps/web/app/(ee)/api/partner-profile/programs/[programId]/customers/[customerId]/route.ts
index cc46abc5d5..b688026986 100644
--- a/apps/web/app/(ee)/api/partner-profile/programs/[programId]/customers/[customerId]/route.ts
+++ b/apps/web/app/(ee)/api/partner-profile/programs/[programId]/customers/[customerId]/route.ts
@@ -41,18 +41,6 @@ export const GET = withPartnerProfile(async ({ partner, params }) => {
where: {
id: customerId,
},
- include: {
- // find the first commission for this customer and partner
- commissions: {
- where: {
- partnerId: partner.id,
- },
- take: 1,
- orderBy: {
- createdAt: "asc",
- },
- },
- },
});
if (!customer || customer?.projectId !== program.workspaceId) {
@@ -78,29 +66,14 @@ export const GET = withPartnerProfile(async ({ partner, params }) => {
const firstLinkId = events[events.length - 1].link_id;
const link = links.find((link) => link.id === firstLinkId);
- // Find the LTV of the customer
- // TODO: Calculate this from all events, not limited
- const ltv = events.reduce((acc, event) => {
- if (event.event === "sale" && event.saleAmount) {
- acc += Number(event.saleAmount);
- }
-
- return acc;
- }, 0);
-
- // Find the time to lead of the customer
const timeToLead =
customer.clickedAt && customer.createdAt
? customer.createdAt.getTime() - customer.clickedAt.getTime()
: null;
- // Find the time to first sale of the customer
- // TODO: Calculate this from all events, not limited
- const firstSale = events.filter(({ event }) => event === "sale").pop();
-
const timeToSale =
- firstSale && customer.createdAt
- ? new Date(firstSale.timestamp).getTime() - customer.createdAt.getTime()
+ customer.firstSaleAt && customer.createdAt
+ ? customer.firstSaleAt.getTime() - customer.createdAt.getTime()
: null;
return NextResponse.json(
@@ -116,10 +89,9 @@ export const GET = withPartnerProfile(async ({ partner, params }) => {
: customer.name || generateRandomName(),
}),
activity: {
- ltv,
+ ...customer,
timeToLead,
timeToSale,
- firstSaleDate: customer.commissions[0]?.createdAt ?? null,
events,
link,
},
diff --git a/apps/web/app/(ee)/api/partner-profile/programs/[programId]/customers/route.ts b/apps/web/app/(ee)/api/partner-profile/programs/[programId]/customers/route.ts
index 152e185067..7a97df3311 100644
--- a/apps/web/app/(ee)/api/partner-profile/programs/[programId]/customers/route.ts
+++ b/apps/web/app/(ee)/api/partner-profile/programs/[programId]/customers/route.ts
@@ -61,18 +61,6 @@ export const GET = withPartnerProfile(
},
include: {
link: true,
- commissions: {
- where: {
- partnerId: partner.id,
- },
- take: 1,
- orderBy: {
- createdAt: "asc",
- },
- select: {
- createdAt: true,
- },
- },
},
orderBy: {
[sortBy]: sortOrder,
@@ -100,10 +88,9 @@ export const GET = withPartnerProfile(
: customer.name || generateRandomName(),
}),
activity: {
- ltv: customer.saleAmount,
+ ...customer,
timeToLead,
timeToSale: null,
- firstSaleDate: customer.commissions[0]?.createdAt ?? null,
events: [],
link: customer.link,
},
diff --git a/apps/web/app/(ee)/partners.dub.co/(dashboard)/programs/[programSlug]/(enrolled)/customers/(index)/page-client.tsx b/apps/web/app/(ee)/partners.dub.co/(dashboard)/programs/[programSlug]/(enrolled)/customers/(index)/page-client.tsx
index 852ee3c8b0..d1e7ac950f 100644
--- a/apps/web/app/(ee)/partners.dub.co/(dashboard)/programs/[programSlug]/(enrolled)/customers/(index)/page-client.tsx
+++ b/apps/web/app/(ee)/partners.dub.co/(dashboard)/programs/[programSlug]/(enrolled)/customers/(index)/page-client.tsx
@@ -161,7 +161,7 @@ export function ProgramCustomersPageClient() {
headerTooltip:
"The total amount of revenue the customer has generated over time (lifetime value).",
},
- accessorKey: "activity.ltv",
+ accessorKey: "activity.saleAmount",
cell: ({ getValue }) => (
<div className="flex items-center gap-2">
<span>