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.

remove leadCreatedAt

Kiran Kbceae6f76d7b
diff --git a/apps/web/app/api/customers/[id]/activity/route.ts b/apps/web/app/api/customers/[id]/activity/route.ts
index db8dd940fc..0c65c0e1eb 100644
--- a/apps/web/app/api/customers/[id]/activity/route.ts
+++ b/apps/web/app/api/customers/[id]/activity/route.ts
@@ -53,7 +53,7 @@ export const GET = withWorkspace(async ({ workspace, params }) => {
// Add lead event to activities
activity.push({
- timestamp: customer.leadCreatedAt!,
+ timestamp: customer.createdAt,
event: "lead",
event_name: "Account created",
metadata: null,
@@ -63,7 +63,7 @@ export const GET = withWorkspace(async ({ workspace, params }) => {
activity.push({
timestamp: customer.clickedAt!,
event: "click",
- event_name: "Link clicked",
+ event_name: "Link click",
metadata: null,
});
@@ -78,18 +78,17 @@ export const GET = withWorkspace(async ({ workspace, params }) => {
// Find the time to lead of the customer
const timeToLead =
- customer.clickedAt && customer.leadCreatedAt
- ? customer.leadCreatedAt.getTime() - customer.clickedAt.getTime()
- : 0;
+ customer.clickedAt && customer.createdAt
+ ? customer.createdAt.getTime() - customer.clickedAt.getTime()
+ : null;
// Find the time to first sale of the customer
const firstSale = activity.filter(({ event }) => event === "sale").pop();
const timeToSale =
- firstSale && customer.leadCreatedAt
- ? new Date(firstSale.timestamp).getTime() -
- customer.leadCreatedAt.getTime()
- : 0;
+ firstSale && customer.createdAt
+ ? new Date(firstSale.timestamp).getTime() - customer.createdAt.getTime()
+ : null;
return NextResponse.json(
customerActivityResponseSchema.parse({
diff --git a/apps/web/lib/zod/schemas/customers.ts b/apps/web/lib/zod/schemas/customers.ts
index f81bdeeb2d..6c574e1497 100644
--- a/apps/web/lib/zod/schemas/customers.ts
+++ b/apps/web/lib/zod/schemas/customers.ts
@@ -115,7 +115,7 @@ export const customerActivitySchema = z.object({
export const customerActivityResponseSchema = z.object({
ltv: z.number(),
timeToLead: z.number(),
- timeToSale: z.number(),
+ timeToSale: z.number().nullable(),
activity: z.array(customerActivitySchema),
customer: CustomerSchema,
link: LinkSchema.pick({
diff --git a/apps/web/scripts/backfill-customers.ts b/apps/web/scripts/backfill-customers.ts
index a0f5bd2be3..300d1d8ac6 100644
--- a/apps/web/scripts/backfill-customers.ts
+++ b/apps/web/scripts/backfill-customers.ts
@@ -63,7 +63,6 @@ async function main() {
clickId: leadEvent.click_id,
country: leadEvent.country,
clickedAt: clickEvent.timestamp,
- leadCreatedAt: null,
},
select: {
id: true,
@@ -71,7 +70,6 @@ async function main() {
clickId: true,
country: true,
clickedAt: true,
- leadCreatedAt: true,
},
});
}),
diff --git a/apps/web/ui/partners/customer-details-sheet.tsx b/apps/web/ui/partners/customer-details-sheet.tsx
index 6d101dcb2d..c093e22ea1 100644
--- a/apps/web/ui/partners/customer-details-sheet.tsx
+++ b/apps/web/ui/partners/customer-details-sheet.tsx
@@ -206,12 +206,23 @@ function CustomerDetailsSheetContent({
maximumFractionDigits: 2,
})
: "-",
+ description: !customerActivity?.ltv
+ ? "This customer hasn't made any purchases yet."
+ : "",
},
- ].map(({ label, value }) => (
+ ].map(({ label, value, description }) => (
<div key={label} className="flex flex-col bg-neutral-50 p-3">
- <span className="truncate text-xs text-neutral-400">
- {label}
- </span>
+ {customerActivity?.ltv ? (
+ <span className="truncate text-xs text-neutral-400">
+ {label}
+ </span>
+ ) : (
+ <Tooltip content={description}>
+ <span className="cursor-default truncate text-xs text-neutral-400 underline decoration-dotted underline-offset-2">
+ {label}
+ </span>
+ </Tooltip>
+ )}
<span className="text-base text-neutral-900">{value}</span>
</div>
))}
@@ -308,7 +319,7 @@ function Activity({
)}
</span>
<div className="text-sm text-neutral-500">
- {month} at {time}
+ {month}, {time}
</div>
</li>
);
diff --git a/packages/prisma/schema/customer.prisma b/packages/prisma/schema/customer.prisma
index 202f6e191e..d2b5443541 100644
--- a/packages/prisma/schema/customer.prisma
+++ b/packages/prisma/schema/customer.prisma
@@ -7,7 +7,6 @@ model Customer {
linkId String?
clickId String?
clickedAt DateTime?
- leadCreatedAt DateTime?
country String?
project Project @relation(fields: [projectId], references: [id], onDelete: Cascade)
projectId String