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.

simplify customers activity route

Steven Tey28b7b597ee56
diff --git a/apps/web/app/api/customers/[id]/activity/route.ts b/apps/web/app/api/customers/[id]/activity/route.ts
index 0188fdb429..7e7deef534 100644
--- a/apps/web/app/api/customers/[id]/activity/route.ts
+++ b/apps/web/app/api/customers/[id]/activity/route.ts
@@ -2,7 +2,6 @@ import { getCustomerEvents } from "@/lib/analytics/get-customer-events";
import { getCustomerOrThrow } from "@/lib/api/customers/get-customer-or-throw";
import { decodeLinkIfCaseSensitive } from "@/lib/api/links/case-sensitivity";
import { withWorkspace } from "@/lib/auth";
-import { verifyFolderAccess } from "@/lib/folder/permissions";
import { customerActivityResponseSchema } from "@/lib/zod/schemas/customer-activity";
import { prisma } from "@dub/prisma";
import { NextResponse } from "next/server";
@@ -16,46 +15,24 @@ export const GET = withWorkspace(async ({ workspace, params, session }) => {
id: customerId,
});
- if (!customer.linkId) {
- return NextResponse.json(
- customerActivityResponseSchema.parse({
- customer,
- events: [],
- ltv: 0,
- timeToLead: null,
- timeToSale: null,
- link: null,
- }),
- );
- }
+ const events = await getCustomerEvents({
+ customerId: customer.id,
+ });
- let [events, link] = await Promise.all([
- getCustomerEvents({
- customerId: customer.id,
- }),
+ // get the first partner link that this customer interacted with
+ const firstLinkId = events[events.length - 1].link_id;
- prisma.link.findUniqueOrThrow({
- where: {
- id: customer.linkId!,
- },
- select: {
- id: true,
- domain: true,
- key: true,
- shortLink: true,
- folderId: true,
- },
- }),
- ]);
-
- if (link.folderId) {
- await verifyFolderAccess({
- workspace,
- userId: session.user.id,
- folderId: link.folderId,
- requiredPermission: "folders.read",
- });
- }
+ let link = await prisma.link.findUniqueOrThrow({
+ where: {
+ id: firstLinkId,
+ },
+ select: {
+ id: true,
+ domain: true,
+ key: true,
+ shortLink: true,
+ },
+ });
link = decodeLinkIfCaseSensitive(link);
diff --git a/apps/web/ui/customers/customer-partner-earnings-table.tsx b/apps/web/ui/customers/customer-partner-earnings-table.tsx
index 161a7fa129..337447a4ab 100644
--- a/apps/web/ui/customers/customer-partner-earnings-table.tsx
+++ b/apps/web/ui/customers/customer-partner-earnings-table.tsx
@@ -70,6 +70,7 @@ export function CustomerPartnerEarningsTable({
getCoreRowModel: getCoreRowModel(),
});
+ const As = viewAllHref ? Link : "div";
return (
<div className="overflow-x-auto">
{isLoading ? (
@@ -117,22 +118,18 @@ export function CustomerPartnerEarningsTable({
))}
</tbody>
</table>
- {viewAllHref && (
- <div className="mt-2 flex items-center gap-1 px-2 text-sm text-neutral-600">
- {commissions.length} of
- {totalCommissions ? (
- <Link
- href={viewAllHref}
- className="font-medium text-neutral-700 hover:text-neutral-900"
- >
- {totalCommissions}
- </Link>
- ) : (
+ <div className="mt-2 flex items-center gap-1 px-2 text-sm text-neutral-600">
+ {commissions.length} of
+ <As
+ href={viewAllHref ?? "#"}
+ className="flex items-center gap-1.5 font-medium text-neutral-700 hover:text-neutral-900"
+ >
+ {totalCommissions ?? (
<div className="size-3 animate-pulse rounded-md bg-neutral-100" />
- )}
+ )}{" "}
results
- </div>
- )}
+ </As>
+ </div>
</>
)}
</div>
diff --git a/apps/web/ui/customers/customer-sales-table.tsx b/apps/web/ui/customers/customer-sales-table.tsx
index 9497efeb7c..71af32542a 100644
--- a/apps/web/ui/customers/customer-sales-table.tsx
+++ b/apps/web/ui/customers/customer-sales-table.tsx
@@ -91,6 +91,7 @@ export function CustomerSalesTable({
getCoreRowModel: getCoreRowModel(),
});
+ const As = viewAllHref ? Link : "div";
return (
<div className="overflow-x-auto">
{isLoading ? (
@@ -136,22 +137,18 @@ export function CustomerSalesTable({
))}
</tbody>
</table>
- {viewAllHref && (
- <div className="mt-2 flex items-center gap-1 px-2 text-sm text-neutral-600">
- {sales.length} of
- {totalSales ? (
- <Link
- href={viewAllHref}
- className="font-medium text-neutral-700 hover:text-neutral-900"
- >
- {totalSales}
- </Link>
- ) : (
+ <div className="mt-2 flex items-center gap-1 px-2 text-sm text-neutral-600">
+ {sales.length} of
+ <As
+ href={viewAllHref ?? "#"}
+ className="flex items-center gap-1.5 font-medium text-neutral-700 hover:text-neutral-900"
+ >
+ {totalSales ?? (
<div className="size-3 animate-pulse rounded-md bg-neutral-100" />
- )}
+ )}{" "}
results
- </div>
- )}
+ </As>
+ </div>
</>
)}
</div>