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.

WIP

Tim Wilsondb4387cb2a48
diff --git a/apps/web/app/app.dub.co/(dashboard)/[slug]/page-client.tsx b/apps/web/app/app.dub.co/(dashboard)/[slug]/page-client.tsx
index ff1eb519ea..b65077b569 100644
--- a/apps/web/app/app.dub.co/(dashboard)/[slug]/page-client.tsx
+++ b/apps/web/app/app.dub.co/(dashboard)/[slug]/page-client.tsx
@@ -22,8 +22,7 @@ import {
TooltipContent,
useRouterStuff,
} from "@dub/ui";
-import { CloudUpload, Download, Tag } from "@dub/ui/src/icons";
-import { Sheet } from "lucide-react";
+import { CloudUpload, Download, Table, Tag } from "@dub/ui/src/icons";
import { useRouter } from "next/navigation";
import {
Dispatch,
@@ -242,16 +241,18 @@ const MoreLinkOptions = () => {
}
/>
</ImportOption>
- </div>
- <div className="p-2">
- <Tooltip content="This feature is still in development – we'll let you know when it's ready!">
- <div className="flex w-full cursor-not-allowed items-center justify-between space-x-2 rounded-md p-2 text-sm text-gray-400">
- <IconMenu
- text="Import from CSV"
- icon={<Sheet className="h-4 w-4" />}
- />
- </div>
- </Tooltip>
+ <ImportOption
+ onClick={() => {
+ setOpenPopover(false);
+ router.push(`/${slug}?import=csv`);
+ }}
+ setOpenPopover={setOpenPopover}
+ >
+ <IconMenu
+ text="Import from CSV"
+ icon={<Table className="h-4 w-4" />}
+ />
+ </ImportOption>
</div>
</>
)}
diff --git a/apps/web/ui/modals/import-csv-modal.tsx b/apps/web/ui/modals/import-csv-modal.tsx
new file mode 100644
index 0000000000..e36070d5ab
--- /dev/null
+++ b/apps/web/ui/modals/import-csv-modal.tsx
@@ -0,0 +1,145 @@
+import useWorkspace from "@/lib/swr/use-workspace";
+import { Button, FileUpload, Logo, Modal, useRouterStuff } from "@dub/ui";
+import { Table } from "@dub/ui/src/icons";
+import { truncate } from "@dub/utils";
+import { ArrowRight } from "lucide-react";
+import { useParams, useRouter, useSearchParams } from "next/navigation";
+import {
+ Dispatch,
+ SetStateAction,
+ useCallback,
+ useEffect,
+ useMemo,
+ useState,
+} from "react";
+import { Controller, useForm } from "react-hook-form";
+import { toast } from "sonner";
+
+type FormData = {
+ file: File | null;
+};
+
+function ImportCsvModal({
+ showImportCsvModal,
+ setShowImportCsvModal,
+}: {
+ showImportCsvModal: boolean;
+ setShowImportCsvModal: Dispatch<SetStateAction<boolean>>;
+}) {
+ const router = useRouter();
+ const { slug } = useParams() as { slug?: string };
+ const searchParams = useSearchParams();
+ const { id: workspaceId } = useWorkspace();
+
+ useEffect(
+ () => setShowImportCsvModal(searchParams?.get("import") === "csv"),
+ [searchParams],
+ );
+
+ const {
+ control,
+ handleSubmit,
+ formState: { isLoading },
+ } = useForm<FormData>({
+ defaultValues: {},
+ });
+
+ const { queryParams } = useRouterStuff();
+
+ return (
+ <Modal
+ showModal={showImportCsvModal}
+ setShowModal={setShowImportCsvModal}
+ onClose={() =>
+ queryParams({
+ del: "import",
+ })
+ }
+ >
+ <div className="flex flex-col items-center justify-center space-y-3 border-b border-gray-200 px-4 py-8 sm:px-16">
+ <div className="flex items-center space-x-3 py-4">
+ <div className="flex size-10 items-center justify-center rounded-xl border border-gray-200 bg-gray-50">
+ <Table className="size-5" />
+ </div>
+ <ArrowRight className="size-5 text-gray-600" />
+ <Logo className="size-10" />
+ </div>
+ <h3 className="text-lg font-medium">Import Your Csv Links</h3>
+ <p className="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>
+
+ <div className="flex flex-col space-y-6 bg-gray-50 px-4 py-8 text-left sm:px-16">
+ <form
+ onSubmit={handleSubmit(async (data) => {
+ toast.promise(
+ fetch(`/api/workspaces/${workspaceId}/import/csv`, {
+ method: "POST",
+ headers: {
+ "Content-Type": "application/json",
+ },
+ body: JSON.stringify({}),
+ }).then(async (res) => {
+ if (res.ok) {
+ router.push(`/${slug}`);
+ } else {
+ throw new Error();
+ }
+ }),
+ {
+ loading: "Adding links to import queue...",
+ 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.",
+ error: "Error adding links to import queue",
+ },
+ );
+ })}
+ className="flex flex-col space-y-4"
+ >
+ <Controller
+ name="file"
+ control={control}
+ render={({ field: { value, onChange } }) => (
+ <FileUpload
+ accept="csv"
+ maxFileSizeMB={10}
+ onChange={({ file }) => onChange(file)}
+ content={
+ value
+ ? truncate(value.name, 20)
+ : "Click or drag and drop a CSV file."
+ }
+ className="aspect-auto h-20"
+ iconClassName="size-6"
+ />
+ )}
+ />
+ <Button text="Confirm import" loading={isLoading} disabled={true} />
+ </form>
+ </div>
+ </Modal>
+ );
+}
+
+export function useImportCsvModal() {
+ const [showImportCsvModal, setShowImportCsvModal] = useState(false);
+
+ const ImportCsvModalCallback = useCallback(() => {
+ return (
+ <ImportCsvModal
+ showImportCsvModal={showImportCsvModal}
+ setShowImportCsvModal={setShowImportCsvModal}
+ />
+ );
+ }, [showImportCsvModal, setShowImportCsvModal]);
+
+ return useMemo(
+ () => ({
+ setShowImportCsvModal,
+ ImportCsvModal: ImportCsvModalCallback,
+ }),
+ [setShowImportCsvModal, ImportCsvModalCallback],
+ );
+}
diff --git a/apps/web/ui/modals/provider.tsx b/apps/web/ui/modals/provider.tsx
index a3bc5fb1c5..a21f9c8198 100644
--- a/apps/web/ui/modals/provider.tsx
+++ b/apps/web/ui/modals/provider.tsx
@@ -9,6 +9,7 @@ import { useAddEditLinkModal } from "@/ui/modals/add-edit-link-modal";
import { useAddWorkspaceModal } from "@/ui/modals/add-workspace-modal";
import { useCompleteSetupModal } from "@/ui/modals/complete-setup-modal";
import { useImportBitlyModal } from "@/ui/modals/import-bitly-modal";
+import { useImportCsvModal } from "@/ui/modals/import-csv-modal";
import { useImportShortModal } from "@/ui/modals/import-short-modal";
import { useUpgradePlanModal } from "@/ui/modals/upgrade-plan-modal";
import { useCookies } from "@dub/ui";
@@ -38,6 +39,7 @@ export const ModalContext = createContext<{
setShowImportBitlyModal: Dispatch<SetStateAction<boolean>>;
setShowImportShortModal: Dispatch<SetStateAction<boolean>>;
setShowImportRebrandlyModal: Dispatch<SetStateAction<boolean>>;
+ setShowImportCsvModal: Dispatch<SetStateAction<boolean>>;
}>({
setShowAddWorkspaceModal: () => {},
setShowCompleteSetupModal: () => {},
@@ -48,6 +50,7 @@ export const ModalContext = createContext<{
setShowImportBitlyModal: () => {},
setShowImportShortModal: () => {},
setShowImportRebrandlyModal: () => {},
+ setShowImportCsvModal: () => {},
});
export default function ModalProvider({ children }: { children: ReactNode }) {
@@ -89,6 +92,7 @@ export default function ModalProvider({ children }: { children: ReactNode }) {
const { setShowImportShortModal, ImportShortModal } = useImportShortModal();
const { setShowImportRebrandlyModal, ImportRebrandlyModal } =
useImportRebrandlyModal();
+ const { setShowImportCsvModal, ImportCsvModal } = useImportCsvModal();
const [hashes, setHashes] = useCookies<SimpleLinkProps[]>("hashes__dub", [], {
domain: !!process.env.NEXT_PUBLIC_VERCEL_URL ? ".dub.co" : undefined,
@@ -176,6 +180,7 @@ export default function ModalProvider({ children }: { children: ReactNode }) {
setShowImportBitlyModal,
setShowImportShortModal,
setShowImportRebrandlyModal,
+ setShowImportCsvModal,
}}
>
<AddWorkspaceModal />
@@ -188,6 +193,7 @@ export default function ModalProvider({ children }: { children: ReactNode }) {
<ImportBitlyModal />
<ImportShortModal />
<ImportRebrandlyModal />
+ <ImportCsvModal />
{children}
</ModalContext.Provider>
);
diff --git a/packages/ui/src/file-upload.tsx b/packages/ui/src/file-upload.tsx
index 3dbe664b8b..0ab0a98638 100644
--- a/packages/ui/src/file-upload.tsx
+++ b/packages/ui/src/file-upload.tsx
@@ -14,6 +14,10 @@ const acceptFileTypes: Record<
types: ["image/png", "image/jpeg"],
errorMessage: "File type not supported (.png or .jpg only)",
},
+ csv: {
+ types: ["text/csv"],
+ errorMessage: "File type not supported (.csv only)",
+ },
};
const imageUploadVariants = cva(
@@ -198,7 +202,7 @@ export function FileUpload({
>
<UploadCloud
className={cn(
- "h-7 w-7 text-gray-500 transition-all duration-75 group-hover:scale-110 group-active:scale-95",
+ "size-7 text-gray-500 transition-all duration-75 group-hover:scale-110 group-active:scale-95",
dragActive ? "scale-110" : "scale-100",
iconClassName,
)}
diff --git a/packages/ui/src/icons/nucleo/index.ts b/packages/ui/src/icons/nucleo/index.ts
index 7e1f7d0a2f..a8408ce7b3 100644
--- a/packages/ui/src/icons/nucleo/index.ts
+++ b/packages/ui/src/icons/nucleo/index.ts
@@ -54,6 +54,7 @@ export * from "./robot";
export * from "./shield-check";
export * from "./sliders";
export * from "./stars2";
+export * from "./table";
export * from "./table-rows2";
export * from "./tablet";
export * from "./tag";
diff --git a/packages/ui/src/icons/nucleo/table.tsx b/packages/ui/src/icons/nucleo/table.tsx
new file mode 100644
index 0000000000..d5b51fa55a
--- /dev/null
+++ b/packages/ui/src/icons/nucleo/table.tsx
@@ -0,0 +1,62 @@
+import { SVGProps } from "react";
+
+export function Table(props: SVGProps<SVGSVGElement>) {
+ return (
+ <svg
+ height="18"
+ width="18"
+ viewBox="0 0 18 18"
+ xmlns="http://www.w3.org/2000/svg"
+ {...props}
+ >
+ <g fill="currentColor">
+ <line
+ fill="none"
+ stroke="currentColor"
+ strokeLinecap="round"
+ strokeLinejoin="round"
+ strokeWidth="1.5"
+ x1="1.75"
+ x2="16.25"
+ y1="6.75"
+ y2="6.75"
+ />
+ <line
+ fill="none"
+ stroke="currentColor"
+ strokeLinecap="round"
+ strokeLinejoin="round"
+ strokeWidth="1.5"
+ x1="1.75"
+ x2="16.25"
+ y1="11.25"
+ y2="11.25"
+ />
+ <line
+ fill="none"
+ stroke="currentColor"
+ strokeLinecap="round"
+ strokeLinejoin="round"
+ strokeWidth="1.5"
+ x1="5.75"
+ x2="5.75"
+ y1="2.75"
+ y2="15.25"
+ />
+ <rect
+ height="12.5"
+ width="14.5"
+ fill="none"
+ rx="2"
+ ry="2"
+ stroke="currentColor"
+ strokeLinecap="round"
+ strokeLinejoin="round"
+ strokeWidth="1.5"
+ x="1.75"
+ y="2.75"
+ />
+ </g>
+ </svg>
+ );
+}