The modern link attribution platform. Loved by world-class engineering teams at Twilio, Zillow, Jobber, Vercel, Raycast, and more.
TypeScript clickhousemysqlnextjsopen-sourceplanetscaleprismatailwindcsstinybirdtypescriptupstashvercel
reuse types
Kiran K91939aed32a4
diff --git a/apps/web/app/api/customers/[id]/activity/route.ts b/apps/web/app/api/customers/[id]/activity/route.tsindex 4df4f3374b..cddddc4950 100644--- a/apps/web/app/api/customers/[id]/activity/route.ts+++ b/apps/web/app/api/customers/[id]/activity/route.ts@@ -1,13 +1,9 @@import { getEvents } from "@/lib/analytics/get-events";import { getCustomerOrThrow } from "@/lib/api/customers/get-customer-or-throw";import { withWorkspace } from "@/lib/auth";-import { CustomerActivity } from "@/lib/types";+import { CustomerActivity, SaleEvent } from "@/lib/types";import { customerActivityResponseSchema } from "@/lib/zod/schemas/customers";-import { saleEventResponseSchema } from "@/lib/zod/schemas/sales";import { NextResponse } from "next/server";-import { z } from "zod";--type SaleEvent = z.infer<typeof saleEventResponseSchema>;// GET /api/customers/[id]/activities - get a customer's activityexport const GET = withWorkspace(async ({ workspace, params }) => {diff --git a/apps/web/app/api/events/export/route.ts b/apps/web/app/api/events/export/route.tsindex 7f8dc98b3d..0d6523bc41 100644--- a/apps/web/app/api/events/export/route.ts+++ b/apps/web/app/api/events/export/route.ts@@ -4,17 +4,11 @@ import { getDomainOrThrow } from "@/lib/api/domains/get-domain-or-throw";import { getLinkOrThrow } from "@/lib/api/links/get-link-or-throw";import { throwIfClicksUsageExceeded } from "@/lib/api/links/usage-checks";import { withWorkspace } from "@/lib/auth";+import { ClickEvent, LeadEvent, SaleEvent } from "@/lib/types";import { eventsQuerySchema } from "@/lib/zod/schemas/analytics";-import { clickEventResponseSchema } from "@/lib/zod/schemas/clicks";-import { leadEventResponseSchema } from "@/lib/zod/schemas/leads";-import { saleEventResponseSchema } from "@/lib/zod/schemas/sales";import { COUNTRIES, capitalize } from "@dub/utils";import { z } from "zod";-type ClickEvent = z.infer<typeof clickEventResponseSchema>;-type LeadEvent = z.infer<typeof leadEventResponseSchema>;-type SaleEvent = z.infer<typeof saleEventResponseSchema>;-type Row = ClickEvent | LeadEvent | SaleEvent;const columnNames: Record<string, string> = {diff --git a/apps/web/lib/actions/partners/backfill-link-data.ts b/apps/web/lib/actions/partners/backfill-link-data.tsindex 9b0377f4eb..168ac31091 100644--- a/apps/web/lib/actions/partners/backfill-link-data.ts+++ b/apps/web/lib/actions/partners/backfill-link-data.ts@@ -1,7 +1,6 @@import { getEvents } from "@/lib/analytics/get-events";import { createSaleData } from "@/lib/api/sales/sale";-import z from "@/lib/zod";-import { saleEventResponseSchema } from "@/lib/zod/schemas/sales";+import { SaleEvent } from "@/lib/types";import { prisma } from "@dub/prisma";export const backfillLinkData = async (programEnrollmentId: string) => {@@ -51,7 +50,7 @@ export const backfillLinkData = async (programEnrollmentId: string) => {sortBy: "timestamp",});- const data = saleEvents.map((e: z.infer<typeof saleEventResponseSchema>) => ({+ const data = saleEvents.map((e: SaleEvent) => ({...createSaleData({customerId: e.customer.id,linkId: e.link.id,diff --git a/apps/web/lib/types.ts b/apps/web/lib/types.tsindex e824c7a0a7..e8c7b22ade 100644--- a/apps/web/lib/types.ts+++ b/apps/web/lib/types.ts@@ -11,6 +11,7 @@ import {Webhook,} from "@dub/prisma/client";import { WEBHOOK_TRIGGER_DESCRIPTIONS } from "./webhook/constants";+import { clickEventResponseSchema } from "./zod/schemas/clicks";import {customerActivityResponseSchema,customerActivitySchema,@@ -20,7 +21,10 @@ import {import { dashboardSchema } from "./zod/schemas/dashboard";import { integrationSchema } from "./zod/schemas/integration";import { InvoiceSchema } from "./zod/schemas/invoices";-import { trackLeadResponseSchema } from "./zod/schemas/leads";+import {+ leadEventResponseSchema,+ trackLeadResponseSchema,+} from "./zod/schemas/leads";import { createLinkBodySchema } from "./zod/schemas/links";import { createOAuthAppSchema, oAuthAppSchema } from "./zod/schemas/oauth";import {@@ -41,7 +45,10 @@ import {ProgramInviteSchema,ProgramSchema,} from "./zod/schemas/programs";-import { trackSaleResponseSchema } from "./zod/schemas/sales";+import {+ saleEventResponseSchema,+ trackSaleResponseSchema,+} from "./zod/schemas/sales";import { tokenSchema } from "./zod/schemas/token";import { usageResponse } from "./zod/schemas/usage";import {@@ -364,3 +371,9 @@ export type CustomerActivity = z.infer<typeof customerActivitySchema>;export type CustomerActivityResponse = z.infer<typeof customerActivityResponseSchema>;++export type ClickEvent = z.infer<typeof clickEventResponseSchema>;++export type SaleEvent = z.infer<typeof saleEventResponseSchema>;++export type LeadEvent = z.infer<typeof leadEventResponseSchema>;diff --git a/apps/web/scripts/backfill-sales.ts b/apps/web/scripts/backfill-sales.tsindex 2a8cc04618..5de3b3c965 100644--- a/apps/web/scripts/backfill-sales.ts+++ b/apps/web/scripts/backfill-sales.ts@@ -1,7 +1,6 @@import { getEvents } from "@/lib/analytics/get-events";import { createSaleData } from "@/lib/api/sales/sale";-import z from "@/lib/zod";-import { saleEventResponseSchema } from "@/lib/zod/schemas/sales";+import { SaleEvent } from "@/lib/types";import { prisma } from "@dub/prisma";import "dotenv-flow/config";@@ -46,7 +45,7 @@ async function main() {sortBy: "timestamp",});- const data = saleEvents.map((e: z.infer<typeof saleEventResponseSchema>) => ({+ const data = saleEvents.map((e: SaleEvent) => ({...createSaleData({customerId: e.customer.id,linkId: e.link.id,diff --git a/apps/web/ui/analytics/events/events-table.tsx b/apps/web/ui/analytics/events/events-table.tsxindex 41fc206e42..4dff7c6b4b 100644--- a/apps/web/ui/analytics/events/events-table.tsx+++ b/apps/web/ui/analytics/events/events-table.tsx@@ -2,9 +2,7 @@import { editQueryString } from "@/lib/analytics/utils";import { generateRandomName } from "@/lib/names";-import { clickEventResponseSchema } from "@/lib/zod/schemas/clicks";-import { leadEventResponseSchema } from "@/lib/zod/schemas/leads";-import { saleEventResponseSchema } from "@/lib/zod/schemas/sales";+import { ClickEvent, LeadEvent, SaleEvent } from "@/lib/types";import EmptyState from "@/ui/shared/empty-state";import {Avatar,@@ -32,7 +30,6 @@ import { Cell, ColumnDef } from "@tanstack/react-table";import { Link2 } from "lucide-react";import { ReactNode, useContext, useEffect, useMemo } from "react";import useSWR from "swr";-import z from "zod";import { AnalyticsContext } from "../analytics-provider";import ContinentIcon from "../continent-icon";import DeviceIcon from "../device-icon";@@ -43,10 +40,7 @@ import FilterButton from "./filter-button";import { RowMenuButton } from "./row-menu-button";import { eventColumns, useColumnVisibility } from "./use-column-visibility";-export type EventDatum =- | z.infer<typeof clickEventResponseSchema>- | z.infer<typeof leadEventResponseSchema>- | z.infer<typeof saleEventResponseSchema>;+export type EventDatum = ClickEvent | LeadEvent | SaleEvent;type ColumnMeta = {filterParams?: (diff --git a/apps/web/ui/partners/customer-details-sheet.tsx b/apps/web/ui/partners/customer-details-sheet.tsxindex 6beed1317a..d0ab12155a 100644--- a/apps/web/ui/partners/customer-details-sheet.tsx+++ b/apps/web/ui/partners/customer-details-sheet.tsx@@ -8,6 +8,7 @@ import { X } from "@/ui/shared/icons";import {ArrowRight,Button,+ CopyButton,CursorRays,FilterBars,GreekTemple,@@ -50,7 +51,6 @@ function CustomerDetailsSheetContent({setIsOpen,}: CustomerDetailsSheetProps) {const { id: workspaceId, slug } = useWorkspace();- const { queryParams } = useRouterStuff();const { data: customerActivity, isLoading } =useSWR<CustomerActivityResponse>(@@ -58,6 +58,8 @@ function CustomerDetailsSheetContent({fetcher,);+ console.log(customerActivity);+return (<><div className="flex grow flex-col">@@ -89,7 +91,7 @@ function CustomerDetailsSheetContent({<div className="flex min-w-[40%] shrink grow basis-1/2 flex-col items-end justify-end gap-2">{link && (<Link- href={`/events?domain=${link.domain}&key=${link.key}`}+ href={`/${slug}/events?domain=${link.domain}&key=${link.key}`}target="_blank"className="group flex min-w-0 items-center gap-1 overflow-hidden rounded-full border border-neutral-200 bg-white px-1.5 py-0.5 text-xs text-neutral-700 group-hover:translate-x-0 group-hover:opacity-100">@@ -103,7 +105,7 @@ function CustomerDetailsSheetContent({{customer.country && (<Link- href={`/events?country=${customer.country}`}+ href={`/${slug}/events?country=${customer.country}`}target="_blank"className="group flex min-w-20 items-center gap-2 rounded-full border border-neutral-200 bg-white px-1.5 py-0.5 text-xs text-neutral-700 group-hover:translate-x-0 group-hover:opacity-100">@@ -126,7 +128,7 @@ function CustomerDetailsSheetContent({<span className="text-lg font-semibold leading-tight text-neutral-900">{customer.name}</span>- <span className="rounded-full border border-neutral-200 bg-gray-200 px-1 text-xs text-neutral-900">+ <span className="rounded-full border border-neutral-200 bg-gray-200 px-1.5 py-0.5 text-xs text-neutral-900">{new Date(customer.createdAt).toLocaleDateString("en-US", {month: "short",day: "numeric",@@ -134,7 +136,20 @@ function CustomerDetailsSheetContent({})}</span></div>- <span className="text-sm text-neutral-500">{customer.email}</span>++ {customer.email && (+ <div className="flex items-center gap-1">+ <span className="text-sm text-neutral-500">+ {customer.email}+ </span>+ <CopyButton+ value={customer.email}+ variant="neutral"+ className="p-1 [&>*]:h-3 [&>*]:w-3"+ successMessage="Copied email to clipboard!"+ />+ </div>+ )}</div><div className="mt-6 grid grid-cols-2 gap-2">