The modern link attribution platform. Loved by world-class engineering teams at Twilio, Zillow, Jobber, Vercel, Raycast, and more.
TypeScript clickhousemysqlnextjsopen-sourceplanetscaleprismatailwindcsstinybirdtypescriptupstashvercel
Add createdAt to CSV imports
Tim Wilson9208920276ee
diff --git a/apps/web/app/api/cron/import/csv/route.ts b/apps/web/app/api/cron/import/csv/route.tsindex 407220d983..bf4c80bddd 100644--- a/apps/web/app/api/cron/import/csv/route.ts+++ b/apps/web/app/api/cron/import/csv/route.ts@@ -37,6 +37,9 @@ export async function POST(req: Request) {?.replace(/^https?:\/\//, "").split("/").at(-1) ?? "",+ createdAt: mapping.createdAt+ ? new Date(row[mapping.createdAt])+ : undefined,tags: mapping.tags? row[mapping.tags]?.split(",").map((tag) => tag.trim()): undefined,@@ -192,10 +195,11 @@ export async function POST(req: Request) {bulk: true,}),),- ...linksToCreate.map(({ tags, ...link }) =>+ ...linksToCreate.map(({ createdAt, tags, ...link }) =>processLink({payload: createLinkBodySchema.parse({...link,+ createdAt: createdAt?.toISOString(),tagNames: tags || undefined,}),workspace: workspace as WorkspaceProps,diff --git a/apps/web/app/api/cron/import/csv/utils.ts b/apps/web/app/api/cron/import/csv/utils.tsindex 28def14a58..8428c8d086 100644--- a/apps/web/app/api/cron/import/csv/utils.ts+++ b/apps/web/app/api/cron/import/csv/utils.ts@@ -62,7 +62,6 @@ export async function sendCsvImportEmails({sendEmail({subject: `Your CSV links have been imported!`,email: ownerEmail,- from: "[email protected]", // TODO: REMOVE THIS!!!!react: LinksImported({email: ownerEmail,provider: "CSV",@@ -79,7 +78,6 @@ export async function sendCsvImportEmails({sendEmail({subject: `Some CSV links failed to import`,email: ownerEmail,- from: "[email protected]", // TODO: REMOVE THIS!!!!react: LinksImportErrors({email: ownerEmail,provider: "CSV",diff --git a/apps/web/lib/ai/generate-csv-mapping.ts b/apps/web/lib/ai/generate-csv-mapping.tsindex 8ed21a672c..8b391922b0 100644--- a/apps/web/lib/ai/generate-csv-mapping.ts+++ b/apps/web/lib/ai/generate-csv-mapping.ts@@ -27,6 +27,10 @@ export async function generateCsvMapping(.describe("The key/slug of the shortlink (a shortlink is: https://[domain]/[key]). Can be mapped to a full URL if there is not a separate key column",),+ createdAt: z+ .string()+ .optional()+ .describe("The date and time the shortlink was created"),tags: z.string().optional()diff --git a/apps/web/lib/api/links/process-link.ts b/apps/web/lib/api/links/process-link.tsindex 15d0d97142..d9b38442cb 100644--- a/apps/web/lib/api/links/process-link.ts+++ b/apps/web/lib/api/links/process-link.ts@@ -374,6 +374,7 @@ export async function processLink<T extends Record<string, any>>({key,// we're redefining these fields because they're processed in the functionurl,+ createdAt: createdAt ? new Date(createdAt) : undefined,expiresAt,expiredUrl,// make sure projectId is set to the current workspacediff --git a/apps/web/lib/zod/schemas/import-csv.ts b/apps/web/lib/zod/schemas/import-csv.tsindex a94679244a..6d8b613141 100644--- a/apps/web/lib/zod/schemas/import-csv.ts+++ b/apps/web/lib/zod/schemas/import-csv.ts@@ -4,6 +4,7 @@ export const linkMappingSchema = z.object({domain: z.string(),url: z.string(),key: z.string(),+ createdAt: z.string().optional(),tags: z.string().optional(),title: z.string().optional(),description: z.string().optional(),diff --git a/apps/web/lib/zod/schemas/links.ts b/apps/web/lib/zod/schemas/links.tsindex b380c4cbf7..48e8cdab52 100644--- a/apps/web/lib/zod/schemas/links.ts+++ b/apps/web/lib/zod/schemas/links.ts@@ -202,6 +202,10 @@ export const createLinkBodySchema = z.object({"The unique name of the tags assigned to the short link (case insensitive).",),comments: z.string().nullish().describe("The comments for the short link."),+ createdAt: z+ .string()+ .nullish()+ .describe("The date and time when the short link was created."),expiresAt: z.string().nullish()diff --git a/apps/web/ui/modals/import-csv-modal/field-mapping.tsx b/apps/web/ui/modals/import-csv-modal/field-mapping.tsxindex 473ec3d2bf..29e71d751b 100644--- a/apps/web/ui/modals/import-csv-modal/field-mapping.tsx+++ b/apps/web/ui/modals/import-csv-modal/field-mapping.tsx@@ -9,7 +9,7 @@ import {TableIcon,Xmark,} from "@dub/ui/src/icons";-import { cn, truncate } from "@dub/utils";+import { cn, formatDate, truncate } from "@dub/utils";import { readStreamableValue } from "ai/rsc";import { ChevronDown } from "lucide-react";import { useEffect, useMemo, useState } from "react";@@ -47,7 +47,7 @@ export function FieldMapping() {}, [fileColumns, firstRows]);return (- <div className="flex flex-col gap-3">+ <div className="flex flex-col gap-2"><p className="text-sm text-gray-600">Please select the column that corresponds to each field:</p>@@ -104,6 +104,11 @@ function FieldRow({.map((e) => e.trim()).join(" & "),);+ case "createdAt":+ // Convert to date+ values = values.map((e) =>+ formatDate(new Date(e), { month: "short", year: undefined }),+ );break;}@@ -115,7 +120,7 @@ function FieldRow({return (<div key={field} className="flex items-center justify-between gap-6"><span className="flex items-center gap-1">- <span className="text-sm font-medium text-gray-950">+ <span className="whitespace-nowrap text-sm font-medium text-gray-950">{label} {required && <span className="text-red-700">*</span>}</span>{["domain", "key"].includes(field) && (@@ -173,7 +178,7 @@ function FieldRow({><Buttonvariant="secondary"- className="min-w-16 px-3"+ className="h-9 min-w-16 px-3"onClick={() => setIsOpen((o) => !o)}disabled={isLoading}text={diff --git a/apps/web/ui/modals/import-csv-modal/index.tsx b/apps/web/ui/modals/import-csv-modal/index.tsxindex 36c8f5591a..b4634ad9b2 100644--- a/apps/web/ui/modals/import-csv-modal/index.tsx+++ b/apps/web/ui/modals/import-csv-modal/index.tsx@@ -45,6 +45,10 @@ export const mappableFields = {label: "URL",required: true,},+ createdAt: {+ label: "Created",+ required: false,+ },tags: {label: "Tags",required: false,