The modern link attribution platform. Loved by world-class engineering teams at Twilio, Zillow, Jobber, Vercel, Raycast, and more.
TypeScript clickhousemysqlnextjsopen-sourceplanetscaleprismatailwindcsstinybirdtypescriptupstashvercel
fix UI and AI generation
Steven Tey51f78be995a6
diff --git a/apps/web/lib/ai/generate-csv-mapping.ts b/apps/web/lib/ai/generate-csv-mapping.tsindex ef74bb59b6..16639ec067 100644--- a/apps/web/lib/ai/generate-csv-mapping.ts+++ b/apps/web/lib/ai/generate-csv-mapping.ts@@ -15,30 +15,30 @@ export async function generateCsvMapping(const { partialObjectStream } = await streamObject({model: anthropic("claude-3-sonnet-20240229"),schema: z.object({- domain: z+ link: z.string().optional().describe("The shortlink (link), including the domain and path."),url: z.string().optional().describe("The full URL of the shortlink"),- createdAt: z+ title: z.string().optional().describe("The title of the shortlink"),+ description: z.string().optional()- .describe("The date and time the shortlink was created (createdAt)"),+ .describe("The description of the shortlink"),tags: z.string().optional().describe("A comma-separated list of tags for shortlink organization (NOT to be mapped to a description).",),- title: z.string().optional().describe("The title of the shortlink"),- description: z+ createdAt: z.string().optional()- .describe("The description of the shortlink"),+ .describe("The date and time the shortlink was created (createdAt)"),}),prompt:`The following columns are the headings from a CSV import file for importing a company's short links. ` +- `Map these column names to the correct fields in our database (domain, key, url, title, description) by providing the matching column name for each field.` ++ `Map these column names to the correct fields in our database (link, url, title, description, tags, createdAt) by providing the matching column name for each field.` +`You may also consult the first few rows of data to help you make the mapping, but you are mapping the columns, not the values. ` +`If you are not sure or there is no matching column, omit the value.\n\n` +`Columns:\n${fieldColumns.join(",")}\n\n` +diff --git a/apps/web/ui/modals/import-csv-modal/field-mapping.tsx b/apps/web/ui/modals/import-csv-modal/field-mapping.tsxindex dcffbb3882..e43a020da9 100644--- a/apps/web/ui/modals/import-csv-modal/field-mapping.tsx+++ b/apps/web/ui/modals/import-csv-modal/field-mapping.tsx@@ -1,12 +1,11 @@"use client";import { generateCsvMapping } from "@/lib/ai/generate-csv-mapping";-import { Button, IconMenu, InfoTooltip, Popover, Tooltip } from "@dub/ui";+import { Button, IconMenu, InfoTooltip, Popover } from "@dub/ui";import {ArrowRight,Check,LoadingSpinner,- Magnifier,TableIcon,Xmark,} from "@dub/ui/src/icons";@@ -54,17 +53,12 @@ export function FieldMapping() {}, [fileColumns, firstRows]);return (- <div>- <p className="text-sm text-gray-600">- Please select the column that corresponds to each field:- </p>- <div className="mt-4 grid grid-cols-[1fr_min-content_1fr] gap-x-4 gap-y-2">- {(Object.keys(mappableFields) as (keyof typeof mappableFields)[]).map(- (field) => (- <FieldRow key={field} field={field} isStreaming={isStreaming} />- ),- )}- </div>+ <div className="grid grid-cols-[1fr_min-content_1fr] gap-x-4 gap-y-2">+ {(Object.keys(mappableFields) as (keyof typeof mappableFields)[]).map(+ (field) => (+ <FieldRow key={field} field={field} isStreaming={isStreaming} />+ ),+ )}</div>);}@@ -152,10 +146,10 @@ function FieldRow({><IconMenutext={column}- icon={<Icon className="h-4 w-4 flex-none" />}+ icon={<Icon className="size-4 flex-none" />}/>{field.value === column && (- <Check className="h-4 w-4 shrink-0" />+ <Check className="size-4 shrink-0" />)}</button>);@@ -178,9 +172,9 @@ function FieldRow({)}</span>{isLoading ? (- <LoadingSpinner className="h-4 w-4 shrink-0" />+ <LoadingSpinner className="size-4 shrink-0" />) : (- <ChevronDown className="h-4 w-4 shrink-0 text-gray-400 transition-transform duration-75 group-data-[state=open]:rotate-180" />+ <ChevronDown className="size-4 shrink-0 text-gray-400 transition-transform duration-75 group-data-[state=open]:rotate-180" />)}</div>}@@ -188,7 +182,7 @@ function FieldRow({</Popover>)}/>- {Boolean(examples?.length) ? (+ {/* {Boolean(examples?.length) ? (<div className="hidden shrink-0 sm:block"><Tooltipcontent={@@ -213,16 +207,16 @@ function FieldRow({}><div>- <Magnifier className="h-4 w-4 text-gray-400 transition-colors hover:text-gray-500" />+ <Magnifier className="size-4 text-gray-400 transition-colors hover:text-gray-500" /></div></Tooltip></div>) : (<div className="w-4 shrink-0" />- )}+ )} */}</div><div className="flex items-center justify-end">- <ArrowRight className="h-4 w-4 text-gray-500" />+ <ArrowRight className="size-4 text-gray-500" /></div><span className="flex h-9 items-center gap-1 rounded-md border border-gray-200 bg-gray-100 px-3"><span className="grow whitespace-nowrap text-sm font-normal text-gray-700">diff --git a/apps/web/ui/modals/import-csv-modal/index.tsx b/apps/web/ui/modals/import-csv-modal/index.tsxindex 41134f6b46..7630b214d8 100644--- a/apps/web/ui/modals/import-csv-modal/index.tsx+++ b/apps/web/ui/modals/import-csv-modal/index.tsx@@ -9,7 +9,7 @@ import {useRouterStuff,} from "@dub/ui";import { TableIcon } from "@dub/ui/src/icons";-import { ArrowRight, ChevronLeft } from "lucide-react";+import { ArrowRight } from "lucide-react";import { useParams, useRouter, useSearchParams } from "next/navigation";import {Dispatch,@@ -41,14 +41,6 @@ export const mappableFields = {label: "Destination URL",required: true,},- createdAt: {- label: "Created",- required: false,- },- tags: {- label: "Tags",- required: false,- },title: {label: "Title",required: false,@@ -57,6 +49,14 @@ export const mappableFields = {label: "Description",required: false,},+ tags: {+ label: "Tags",+ required: false,+ },+ createdAt: {+ label: "Created At",+ required: false,+ },} as const;export type ImportCsvFormData = {@@ -151,121 +151,130 @@ function ImportCsvModal({<Logo className="size-10" /></div><h3 className="text-lg font-medium">Import Links From a CSV File</h3>- <p className="text-center text-sm text-gray-500">+ <p className="text-balance text-center text-sm text-gray-500">Easily import all your links into {process.env.NEXT_PUBLIC_APP_NAME}{" "}with just a few clicks.</p></div>- <AnimatedSizeContainer height>- <ImportCsvContext.Provider- value={{- fileColumns,- setFileColumns,- firstRows,- setFirstRows,- control,- watch,- setValue,- }}- >- <div className="flex flex-col space-y-6 bg-gray-50 px-4 py-8 text-left sm:px-12">- <form- onSubmit={handleSubmit(async (data) => {- const loadingId = toast.loading(- "Adding links to import queue...",- );- try {- // Get signed upload URL- const uploadRes = await fetch(- `/api/workspaces/${workspaceId}/import/csv/upload-url`,- {- method: "POST",- },+ <div className="relative">+ {page === "confirm-import" && (+ <div className="absolute inset-x-0 -top-6 mx-4 grid grid-cols-[1fr_min-content_1fr] items-center gap-x-4 gap-y-2 rounded-md border border-gray-200 bg-white p-2 text-center text-sm font-medium uppercase text-gray-600 sm:mx-12">+ <p>CSV data column</p>+ <ArrowRight className="size-4 text-gray-500" />+ <p>Dub data field</p>+ </div>+ )}++ <AnimatedSizeContainer height>+ <ImportCsvContext.Provider+ value={{+ fileColumns,+ setFileColumns,+ firstRows,+ setFirstRows,+ control,+ watch,+ setValue,+ }}+ >+ <div className="flex flex-col gap-y-6 bg-gray-50 px-4 py-8 text-left sm:px-12">+ <form+ onSubmit={handleSubmit(async (data) => {+ const loadingId = toast.loading(+ "Adding links to import queue...",);+ try {+ // Get signed upload URL+ const uploadRes = await fetch(+ `/api/workspaces/${workspaceId}/import/csv/upload-url`,+ {+ method: "POST",+ },+ );- if (!uploadRes.ok || !data.file) {- toast.error("Error getting signed upload URL");- return;- }+ if (!uploadRes.ok || !data.file) {+ toast.error("Error getting signed upload URL");+ return;+ }- const { id, signedUrl } = await uploadRes.json();+ const { id, signedUrl } = await uploadRes.json();- // Upload the file- await fetch(signedUrl, {- method: "PUT",- body: data.file,- headers: {- "Content-Type": "multipart/form-data",- },- });+ // Upload the file+ await fetch(signedUrl, {+ method: "PUT",+ body: data.file,+ headers: {+ "Content-Type": "multipart/form-data",+ },+ });- const formData = new FormData();- for (const key in data) {- if (key !== "file" && data[key] !== null) {- formData.append(key, data[key]);+ const formData = new FormData();+ for (const key in data) {+ if (key !== "file" && data[key] !== null) {+ formData.append(key, data[key]);+ }}- }- formData.append("id", id);+ formData.append("id", id);- const res = await fetch(- `/api/workspaces/${workspaceId}/import/csv`,- {- method: "POST",- body: formData,- },- );+ const res = await fetch(+ `/api/workspaces/${workspaceId}/import/csv`,+ {+ method: "POST",+ body: formData,+ },+ );- if (!res.ok) throw new Error();+ if (!res.ok) throw new Error();- router.push(`/${slug}`);- mutate(- (key) =>- typeof key === "string" &&- (key.startsWith("/api/links") ||- key.startsWith("/api/domains")),- );+ router.push(`/${slug}`);+ mutate(+ (key) =>+ typeof key === "string" &&+ (key.startsWith("/api/links") ||+ key.startsWith("/api/domains")),+ );- toast.success(- "Successfully added links to import queue! You can now safely navigate from this tab – we will send you an email when your links have been fully imported.",- );- } catch (error) {- toast.error("Error adding links to import queue");- } finally {- toast.dismiss(loadingId);- }- })}- className="flex flex-col space-y-4"- >- {page === "select-file" && <SelectFile />}+ toast.success(+ "Successfully added links to import queue! You can now safely navigate from this tab – we will send you an email when your links have been fully imported.",+ );+ } catch (error) {+ toast.error("Error adding links to import queue");+ } finally {+ toast.dismiss(loadingId);+ }+ })}+ className="flex flex-col gap-y-4"+ >+ {page === "select-file" && <SelectFile />}- {page === "confirm-import" && (- <>- <FieldMapping />- <Button- text="Confirm import"- loading={isSubmitting}- disabled={!isValid}- />- <button- type="button"- className="flex w-fit items-center gap-1 text-xs text-gray-600 transition-colors hover:text-gray-950"- onClick={() => {- setPageNumber(0);- reset();- setFileColumns(null);- setFirstRows(null);- }}- >- <ChevronLeft className="size-3.5" />- Choose another file- </button>- </>- )}- </form>- </div>- </ImportCsvContext.Provider>- </AnimatedSizeContainer>+ {page === "confirm-import" && (+ <>+ <FieldMapping />+ <Button+ text="Confirm import"+ loading={isSubmitting}+ disabled={!isValid}+ />+ <button+ type="button"+ className="-mt-1 text-center text-xs text-gray-600 underline underline-offset-2 transition-colors hover:text-gray-800"+ onClick={() => {+ setPageNumber(0);+ reset();+ setFileColumns(null);+ setFirstRows(null);+ }}+ >+ Choose another file+ </button>+ </>+ )}+ </form>+ </div>+ </ImportCsvContext.Provider>+ </AnimatedSizeContainer>+ </div></Modal>);}