The modern link attribution platform. Loved by world-class engineering teams at Twilio, Zillow, Jobber, Vercel, Raycast, and more.
TypeScript clickhousemysqlnextjsopen-sourceplanetscaleprismatailwindcsstinybirdtypescriptupstashvercel
Warn when the application export hits the 2,000 cap
Rafie14db1d68bbf
diff --git a/apps/web/app/(ee)/api/program-applications/export/route.ts b/apps/web/app/(ee)/api/program-applications/export/route.tsindex ee14164968..e73d7d12b7 100644--- a/apps/web/app/(ee)/api/program-applications/export/route.ts+++ b/apps/web/app/(ee)/api/program-applications/export/route.ts@@ -2,14 +2,13 @@ import { convertToCSV } from "@/lib/analytics/utils/convert-to-csv";import { getDefaultProgramIdOrThrow } from "@/lib/api/programs/get-default-program-id-or-throw";import { withWorkspace } from "@/lib/auth";import { listProgramApplications } from "@/lib/program-applications/list-program-applications";-import { exportApplicationColumns } from "@/lib/zod/schemas/partners";+import {+ exportApplicationColumns,+ MAX_APPLICATIONS_TO_EXPORT,+} from "@/lib/zod/schemas/partners";import { exportApplicationsQuerySchema } from "@/lib/zod/schemas/program-application";import * as z from "zod/v4";-// Limitation: exports are capped at this many applications; any beyond it are silently dropped.-// TODO: In a follow-up PR, process larger exports in the background and email the CSV (like /api/partners/export).-const MAX_APPLICATIONS_TO_EXPORT = 2000;-const columnIdToLabel = exportApplicationColumns.reduce((acc, column) => {acc[column.id] = column.label;return acc;@@ -30,13 +29,18 @@ export const GET = withWorkspace(country,sortOrder,page: 1,- pageSize: MAX_APPLICATIONS_TO_EXPORT,+ // Fetch one extra row to tell the client when the export was cut off.+ pageSize: MAX_APPLICATIONS_TO_EXPORT + 1,});- const applications = programApplications.map(({ partner, createdAt }) => ({- ...partner,- createdAt,- }));+ const isTruncated = programApplications.length > MAX_APPLICATIONS_TO_EXPORT;++ const applications = programApplications+ .slice(0, MAX_APPLICATIONS_TO_EXPORT)+ .map(({ partner, createdAt }) => ({+ ...partner,+ createdAt,+ }));const columnOrderMap = exportApplicationColumns.reduce((acc, column, index) => {@@ -75,6 +79,7 @@ export const GET = withWorkspace(headers: {"Content-Type": "text/csv","Content-Disposition": "attachment",+ ...(isTruncated && { "X-Export-Truncated": "true" }),},});},diff --git a/apps/web/lib/zod/schemas/partners.ts b/apps/web/lib/zod/schemas/partners.tsindex 07a82cc2ba..47b3d18011 100644--- a/apps/web/lib/zod/schemas/partners.ts+++ b/apps/web/lib/zod/schemas/partners.ts@@ -123,6 +123,10 @@ export const exportApplicationColumns = [{ id: "tiktok", label: "TikTok" },];+// Limitation: exports are capped at this many applications. The export modal warns when more match.+// TODO: In a follow-up PR, process larger exports in the background and email the CSV (like /api/partners/export).+export const MAX_APPLICATIONS_TO_EXPORT = 2000;+export const exportApplicationsColumnsDefault = ["id","name",diff --git a/apps/web/ui/modals/export-applications-modal.tsx b/apps/web/ui/modals/export-applications-modal.tsxindex c5dce9433e..cb77a7a42e 100644--- a/apps/web/ui/modals/export-applications-modal.tsx+++ b/apps/web/ui/modals/export-applications-modal.tsx@@ -3,8 +3,10 @@ import useWorkspace from "@/lib/swr/use-workspace";import {exportApplicationColumns,exportApplicationsColumnsDefault,+ MAX_APPLICATIONS_TO_EXPORT,} from "@/lib/zod/schemas/partners";import { Button, Checkbox, Modal, Switch, useRouterStuff } from "@dub/ui";+import { nFormatter } from "@dub/utils";import { ProgramApplicationStatus } from "@prisma/client";import {Dispatch,@@ -92,7 +94,13 @@ function ExportApplicationsModal({a.download = `Dub Applications Export - ${new Date().toISOString()}.csv`;a.click();- toast.success("Exported successfully");+ if (response.headers.get("X-Export-Truncated") === "true") {+ toast.warning(+ `Only the first ${nFormatter(MAX_APPLICATIONS_TO_EXPORT, { full: true })} applications were exported. Use filters to narrow the export.`,+ );+ } else {+ toast.success("Exported successfully");+ }setShowExportApplicationsModal(false);} catch (error) {toast.error(error);