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 includeClickEvent

Tim Wilson0f23d38e6f42
diff --git a/apps/web/app/api/customers/[id]/route.ts b/apps/web/app/api/customers/[id]/route.ts
index 25a451a942..6fe829b879 100644
--- a/apps/web/app/api/customers/[id]/route.ts
+++ b/apps/web/app/api/customers/[id]/route.ts
@@ -4,27 +4,22 @@ import { transformCustomer } from "@/lib/api/customers/transform-customer";
import { DubApiError } from "@/lib/api/errors";
import { parseRequestBody } from "@/lib/api/utils";
import { withWorkspace } from "@/lib/auth";
-import { getClickEvent } from "@/lib/tinybird";
-import { clickEventSchema, clickEventSchemaTB } from "@/lib/zod/schemas/clicks";
import {
CustomerEnrichedSchema,
CustomerSchema,
- getCustomerQuerySchema,
getCustomersQuerySchema,
updateCustomerBodySchema,
} from "@/lib/zod/schemas/customers";
import { prisma } from "@dub/prisma";
-import { toCamelCase } from "@dub/utils";
import { Discount } from "@prisma/client";
import { NextResponse } from "next/server";
-import { z } from "zod";
// GET /api/customers/:id – Get a customer by ID
export const GET = withWorkspace(
async ({ workspace, params, searchParams }) => {
const { id } = params;
- const { includeExpandedFields, includeClickEvent } =
- getCustomerQuerySchema.parse(searchParams);
+ const { includeExpandedFields } =
+ getCustomersQuerySchema.parse(searchParams);
const customer = await getCustomerOrThrow(
{
@@ -36,12 +31,6 @@ export const GET = withWorkspace(
},
);
- let clickEvent: z.infer<typeof clickEventSchemaTB> | undefined = undefined;
- if (includeClickEvent && customer.clickId) {
- clickEvent = (await getClickEvent({ clickId: customer.clickId }))
- ?.data[0];
- }
-
let discount: Discount | null = null;
if (includeExpandedFields) {
@@ -64,16 +53,9 @@ export const GET = withWorkspace(
});
}
- console.log({ clickEvent });
- const responseSchema = (
- includeExpandedFields ? CustomerEnrichedSchema : CustomerSchema
- ).extend(
- clickEvent
- ? {
- clickEvent: clickEventSchema.nullish(),
- }
- : {},
- );
+ const responseSchema = includeExpandedFields
+ ? CustomerEnrichedSchema
+ : CustomerSchema;
return NextResponse.json(
responseSchema.parse({
@@ -81,19 +63,6 @@ export const GET = withWorkspace(
...customer,
...(includeExpandedFields ? { discount } : {}),
}),
-
- ...(clickEvent && {
- clickEvent: clickEventSchema.parse({
- ...Object.fromEntries(
- Object.entries(clickEvent).map(([key, value]) => [
- toCamelCase(key),
- value,
- ]),
- ),
- timestamp: new Date(clickEvent.timestamp),
- id: clickEvent.click_id,
- }),
- }),
}),
);
},
diff --git a/apps/web/app/app.dub.co/(dashboard)/[slug]/customers/[customerId]/page-client.tsx b/apps/web/app/app.dub.co/(dashboard)/[slug]/customers/[customerId]/page-client.tsx
index bcc32d6bd9..313646665a 100644
--- a/apps/web/app/app.dub.co/(dashboard)/[slug]/customers/[customerId]/page-client.tsx
+++ b/apps/web/app/app.dub.co/(dashboard)/[slug]/customers/[customerId]/page-client.tsx
@@ -34,7 +34,6 @@ export function CustomerPageClient() {
} = useCustomer({
customerId,
query: { includeExpandedFields: true },
- includeClickEvent: true,
});
let { data: customerActivity, isLoading: isCustomerActivityLoading } =
diff --git a/apps/web/lib/swr/use-customer.ts b/apps/web/lib/swr/use-customer.ts
index 2b1d9bb048..4162f6b322 100644
--- a/apps/web/lib/swr/use-customer.ts
+++ b/apps/web/lib/swr/use-customer.ts
@@ -2,7 +2,6 @@ import { fetcher } from "@dub/utils";
import useSWR from "swr";
import { z } from "zod";
import { CustomerProps } from "../types";
-import { clickEventSchema } from "../zod/schemas/clicks";
import { getCustomersQuerySchema } from "../zod/schemas/customers";
import useWorkspace from "./use-workspace";
@@ -10,29 +9,22 @@ const partialQuerySchema = getCustomersQuerySchema.pick({
includeExpandedFields: true,
});
-export default function useCustomer<IncludeClickEvent extends boolean = false>({
+export default function useCustomer({
customerId,
query,
enabled = true,
- includeClickEvent,
}: {
customerId: CustomerProps["id"];
query?: z.infer<typeof partialQuerySchema>;
enabled?: boolean;
- includeClickEvent?: IncludeClickEvent;
}) {
const { id: workspaceId } = useWorkspace();
- const { data, error, isLoading } = useSWR<
- IncludeClickEvent extends true
- ? CustomerProps & { clickEvent: z.infer<typeof clickEventSchema> }
- : CustomerProps
- >(
+ const { data, error, isLoading } = useSWR<CustomerProps>(
enabled && workspaceId
? `/api/customers/${customerId}?${new URLSearchParams({
workspaceId: workspaceId,
...query,
- includeClickEvent,
} as Record<string, any>).toString()}`
: undefined,
fetcher,
diff --git a/apps/web/lib/zod/schemas/customers.ts b/apps/web/lib/zod/schemas/customers.ts
index 7c1870e847..d4b3252dd0 100644
--- a/apps/web/lib/zod/schemas/customers.ts
+++ b/apps/web/lib/zod/schemas/customers.ts
@@ -24,12 +24,6 @@ export const getCustomersQuerySchema = z.object({
),
});
-export const getCustomerQuerySchema = getCustomersQuerySchema.extend({
- includeClickEvent: booleanQuerySchema
- .optional()
- .describe("Whether to include the customer's click event."),
-});
-
export const createCustomerBodySchema = z.object({
email: z
.string()