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.

Added Short.io importer

Steven Teyc773091e3855
diff --git a/app/ui/modal-provider.tsx b/app/ui/modal-provider.tsx
index 61e476742b..3f30012a19 100644
--- a/app/ui/modal-provider.tsx
+++ b/app/ui/modal-provider.tsx
@@ -16,6 +16,7 @@ import { useAddProjectModal } from "@/components/app/modals/add-project-modal";
import { useAcceptInviteModal } from "@/components/app/modals/accept-invite-modal";
import { useAddEditLinkModal } from "@/components/app/modals/add-edit-link-modal";
import { useImportBitlyModal } from "@/components/app/modals/import-bitly-modal";
+import { useImportShortModal } from "@/components/app/modals/import-short-modal";
import { useAddEditDomainModal } from "@/components/app/modals/add-edit-domain-modal";
import { useGoogleOauthModal } from "@/components/app/modals/google-oauth-modal";
import { mutate } from "swr";
@@ -32,6 +33,7 @@ export const ModalContext = createContext<{
setShowAddEditLinkModal: Dispatch<SetStateAction<boolean>>;
setShowUpgradePlanModal: Dispatch<SetStateAction<boolean>>;
setShowImportBitlyModal: Dispatch<SetStateAction<boolean>>;
+ setShowImportShortModal: Dispatch<SetStateAction<boolean>>;
setPollLinks: Dispatch<SetStateAction<boolean>>;
setShowCMDK: Dispatch<SetStateAction<boolean>>;
}>({
@@ -41,6 +43,7 @@ export const ModalContext = createContext<{
setShowAddEditLinkModal: () => {},
setShowUpgradePlanModal: () => {},
setShowImportBitlyModal: () => {},
+ setShowImportShortModal: () => {},
setPollLinks: () => {},
setShowCMDK: () => {},
});
@@ -59,6 +62,7 @@ export default function ModalProvider({ children }: { children: ReactNode }) {
const { setShowAddEditLinkModal, AddEditLinkModal } = useAddEditLinkModal();
const { setShowUpgradePlanModal, UpgradePlanModal } = useUpgradePlanModal();
const { setShowImportBitlyModal, ImportBitlyModal } = useImportBitlyModal();
+ const { setShowImportShortModal, ImportShortModal } = useImportShortModal();
const { error, loading } = useProject();
const { data: session } = useSession();
@@ -115,6 +119,7 @@ export default function ModalProvider({ children }: { children: ReactNode }) {
setShowAddEditLinkModal,
setShowUpgradePlanModal,
setShowImportBitlyModal,
+ setShowImportShortModal,
setPollLinks,
setShowCMDK,
}}
@@ -130,6 +135,7 @@ export default function ModalProvider({ children }: { children: ReactNode }) {
<AddEditLinkModal />
<UpgradePlanModal />
<ImportBitlyModal />
+ <ImportShortModal />
{children}
</ModalContext.Provider>
);
diff --git a/components/app/modals/import-bitly-modal.tsx b/components/app/modals/import-bitly-modal.tsx
index 2b8093e585..19090fe1a2 100644
--- a/components/app/modals/import-bitly-modal.tsx
+++ b/components/app/modals/import-bitly-modal.tsx
@@ -56,7 +56,7 @@ function ImportBitlyModal({
const { setPollLinks } = useContext(ModalContext);
useEffect(() => {
- if (importSource) {
+ if (importSource === "bitly") {
setShowImportBitlyModal(true);
} else {
setShowImportBitlyModal(false);
@@ -90,7 +90,7 @@ function ImportBitlyModal({
<img
src="/_static/icons/bitly.svg"
alt="Bitly logo"
- className="h-10 w-10 rounded-full border border-gray-200"
+ className="h-10 w-10 rounded-full"
/>
<ArrowRight className="h-5 w-5 text-gray-600" />
<Logo />
diff --git a/components/app/modals/import-short-modal.tsx b/components/app/modals/import-short-modal.tsx
new file mode 100644
index 0000000000..e0e872ae92
--- /dev/null
+++ b/components/app/modals/import-short-modal.tsx
@@ -0,0 +1,236 @@
+import { NextRouter, useRouter } from "next/router";
+import {
+ Dispatch,
+ SetStateAction,
+ useCallback,
+ useContext,
+ useEffect,
+ useMemo,
+ useState,
+} from "react";
+import Modal from "#/ui/modal";
+import useProject from "#/lib/swr/use-project";
+import Switch from "#/ui/switch";
+import Button from "#/ui/button";
+import { toast } from "sonner";
+import { ArrowRight } from "lucide-react";
+import { Logo, LoadingSpinner } from "#/ui/icons";
+import { ModalContext } from "#/ui/modal-provider";
+import useSWR, { mutate } from "swr";
+import { BitlyGroupProps } from "#/lib/types";
+import Tooltip from "#/ui/tooltip";
+import { fetcher } from "#/lib/utils";
+
+function ImportShortModal({
+ showImportShortModal,
+ setShowImportShortModal,
+}: {
+ showImportShortModal: boolean;
+ setShowImportShortModal: Dispatch<SetStateAction<boolean>>;
+}) {
+ const { id: projectId } = useProject();
+ const router = useRouter();
+ const { slug, import: importSource } = router.query;
+
+ const [redirecting, setRedirecting] = useState(false);
+
+ const { data: groups, isLoading } = useSWR<BitlyGroupProps[]>(
+ slug && `/api/projects/${slug}/import/short`,
+ fetcher,
+ {
+ revalidateOnFocus: false,
+ revalidateOnReconnect: false,
+ refreshInterval: 0,
+ },
+ );
+
+ const [selectedDomains, setSelectedDomains] = useState<
+ {
+ domain: string;
+ bitlyGroup: string;
+ }[]
+ >([]);
+ const [selectedGroupTags, setSelectedGroupTags] = useState<string[]>([]);
+
+ const [importing, setImporting] = useState(false);
+ const { setPollLinks } = useContext(ModalContext);
+
+ useEffect(() => {
+ if (importSource === "short") {
+ setShowImportShortModal(true);
+ } else {
+ setShowImportShortModal(false);
+ }
+ }, [importSource]);
+
+ const closeModal = (router: NextRouter) => {
+ delete router.query.import;
+ // here, we omit the slug from the query string as well
+ const { slug, ...finalQuery } = router.query;
+ router.push({
+ pathname: `/${router.query.slug}`,
+ query: finalQuery,
+ });
+ };
+
+ const isSelected = (domain: string) => {
+ return selectedDomains.find((d) => d.domain === domain) ? true : false;
+ };
+
+ return (
+ <Modal
+ showModal={showImportShortModal}
+ setShowModal={setShowImportShortModal}
+ onClose={() => closeModal(router)}
+ >
+ <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">
+ <img
+ src="/_static/icons/short.svg"
+ alt="Bitly logo"
+ className="h-10 w-10"
+ />
+ <ArrowRight className="h-5 w-5 text-gray-600" />
+ <Logo />
+ </div>
+ <h3 className="text-lg font-medium">Import Your Short.io Links</h3>
+ <p className="text-center text-sm text-gray-500">
+ Easily import all your existing Short.io links into Dub 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">
+ {isLoading ? (
+ <button className="flex flex-col items-center justify-center space-y-4 bg-none">
+ <LoadingSpinner />
+ <p className="text-sm text-gray-500">Connecting to Bitly</p>
+ </button>
+ ) : groups ? (
+ <form
+ onSubmit={async (e) => {
+ e.preventDefault();
+ setImporting(true);
+ toast.promise(
+ fetch(`/api/projects/${slug}/import/bitly`, {
+ method: "POST",
+ headers: {
+ "Content-Type": "application/json",
+ },
+ body: JSON.stringify({
+ selectedDomains,
+ selectedGroupTags,
+ }),
+ }).then((res) => {
+ setImporting(false);
+ if (res.ok) {
+ closeModal(router);
+ mutate(`/api/projects/${slug}/domains`);
+ setPollLinks(true);
+ } 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"
+ >
+ <div className="divide-y divide-gray-200">
+ {groups.map(({ guid, bsds, tags }) => (
+ <div key={guid} className="flex flex-col space-y-2">
+ <div className="flex items-center justify-between">
+ <p className="text-sm font-medium text-gray-700">Domains</p>
+ <Tooltip content="Your Bitly group ID">
+ <p className="cursor-default text-xs uppercase text-gray-400 transition-colors hover:text-gray-700">
+ {guid}
+ </p>
+ </Tooltip>
+ </div>
+ {bsds.map((bsd) => (
+ <div
+ key={bsd}
+ className="flex items-center justify-between space-x-2 rounded-md border border-gray-200 bg-white px-4 py-2"
+ >
+ <p className="font-medium text-gray-800">{bsd}</p>
+ <Switch
+ fn={() => {
+ const selected = isSelected(bsd);
+ if (selected) {
+ setSelectedDomains((prev) =>
+ prev.filter((d) => d.domain !== bsd),
+ );
+ } else {
+ setSelectedDomains((prev) => [
+ ...prev,
+ {
+ domain: bsd,
+ bitlyGroup: guid,
+ },
+ ]);
+ }
+ }}
+ checked={isSelected(bsd)}
+ />
+ </div>
+ ))}
+ <div className="flex items-center justify-between space-x-2 rounded-md py-1 pl-2 pr-4">
+ <p className="text-xs text-gray-500">
+ {tags.length} tags found. Import all?
+ </p>
+ <Switch
+ fn={() => {
+ if (selectedGroupTags.includes(guid)) {
+ setSelectedGroupTags((prev) =>
+ prev.filter((g) => g !== guid),
+ );
+ } else {
+ setSelectedGroupTags((prev) => [...prev, guid]);
+ }
+ }}
+ checked={selectedGroupTags.includes(guid)}
+ />
+ </div>
+ </div>
+ ))}
+ </div>
+ <Button
+ text="Confirm import"
+ loading={importing}
+ disabled={selectedDomains.length === 0}
+ />
+ </form>
+ ) : (
+ // form to add API key to redis manually
+ <form />
+ )}
+ </div>
+ </Modal>
+ );
+}
+
+export function useImportShortModal() {
+ const [showImportShortModal, setShowImportShortModal] = useState(false);
+
+ const ImportShortModalCallback = useCallback(() => {
+ return (
+ <ImportShortModal
+ showImportShortModal={showImportShortModal}
+ setShowImportShortModal={setShowImportShortModal}
+ />
+ );
+ }, [showImportShortModal, setShowImportShortModal]);
+
+ return useMemo(
+ () => ({
+ setShowImportShortModal,
+ ImportShortModal: ImportShortModalCallback,
+ }),
+ [setShowImportShortModal, ImportShortModalCallback],
+ );
+}
diff --git a/pages/app/[slug]/index.tsx b/pages/app/[slug]/index.tsx
index 94c72f3664..024b788fbe 100644
--- a/pages/app/[slug]/index.tsx
+++ b/pages/app/[slug]/index.tsx
@@ -26,7 +26,7 @@ export default function ProjectLinks() {
<h1 className="text-2xl text-gray-600">Links</h1>
<div className="flex space-x-2">
<AddEditLinkButton />
- {/* <Popover
+ <Popover
content={
<div className="w-full p-2 md:w-52">
<button
@@ -71,7 +71,7 @@ export default function ProjectLinks() {
} transition-all group-hover:text-gray-700`}
/>
</button>
- </Popover> */}
+ </Popover>
</div>
</div>
</MaxWidthWrapper>
diff --git a/public/_static/icons/short.svg b/public/_static/icons/short.svg
new file mode 100644
index 0000000000..71a81077a2
--- /dev/null
+++ b/public/_static/icons/short.svg
@@ -0,0 +1,136 @@
+<?xml version="1.0" encoding="UTF-8" standalone="no"?>
+<svg xmlns="http://www.w3.org/2000/svg" version="1.2" baseProfile="tiny" viewBox="0.00 0.00 1024.00 1024.00">
+<g stroke-width="2.00" fill="none" stroke-linecap="butt">
+<path stroke="#99ebd7" vector-effect="non-scaling-stroke" d="
+ M 459.56 0.00
+ L 461.92 0.27
+ Q 462.64 0.35 461.92 0.48
+ C 352.26 19.15 254.86 81.95 224.52 194.16
+ C 213.42 235.18 211.99 277.34 217.55 319.99
+ C 224.20 370.95 244.05 418.03 276.89 456.92
+ C 342.95 535.16 444.46 571.48 535.50 611.25
+ C 567.67 625.31 601.46 641.56 629.65 663.71
+ C 653.58 682.52 671.24 707.60 673.67 738.67
+ C 678.62 801.79 641.91 852.99 579.56 865.62
+ C 540.54 873.53 498.46 867.52 460.41 855.88
+ C 398.31 836.89 339.68 804.55 289.00 764.28
+ Q 288.39 763.80 288.01 764.47
+ L 202.07 919.33
+ Q 201.76 919.89 202.28 920.25
+ C 273.19 969.94 350.55 1007.70 435.68 1023.45
+ Q 436.43 1023.59 435.67 1023.70
+ L 433.44 1024.00"
+/>
+<path stroke="#9a9c9f" vector-effect="non-scaling-stroke" d="
+ M 627.56 0.00
+ L 625.27 0.36
+ Q 624.34 0.51 625.27 0.64
+ Q 630.93 1.46 636.49 2.76
+ C 712.22 20.45 779.39 57.67 841.35 103.70
+ Q 841.80 104.04 841.54 104.54
+ L 760.04 261.07
+ A 0.46 0.45 33.6 0 1 759.34 261.21
+ C 694.58 207.68 609.67 157.57 522.82 158.96
+ C 473.98 159.74 430.08 183.90 416.22 232.71
+ C 408.71 259.12 411.31 286.89 424.00 311.07
+ C 440.40 342.34 474.18 365.65 504.49 382.27
+ C 599.64 434.42 710.10 466.52 785.81 547.18
+ C 829.06 593.26 851.93 651.15 854.95 714.99
+ C 857.69 772.63 848.74 831.72 822.17 883.36
+ C 780.47 964.45 698.78 1007.88 611.83 1023.20
+ C 611.41 1023.27 610.58 1023.12 610.38 1023.42
+ Q 610.16 1023.75 610.55 1023.77
+ L 613.69 1024.00"
+/>
+</g>
+<path fill="#32d6ae" d="
+ M 0.00 0.00
+ L 459.56 0.00
+ L 461.92 0.27
+ Q 462.64 0.35 461.92 0.48
+ C 352.26 19.15 254.86 81.95 224.52 194.16
+ C 213.42 235.18 211.99 277.34 217.55 319.99
+ C 224.20 370.95 244.05 418.03 276.89 456.92
+ C 342.95 535.16 444.46 571.48 535.50 611.25
+ C 567.67 625.31 601.46 641.56 629.65 663.71
+ C 653.58 682.52 671.24 707.60 673.67 738.67
+ C 678.62 801.79 641.91 852.99 579.56 865.62
+ C 540.54 873.53 498.46 867.52 460.41 855.88
+ C 398.31 836.89 339.68 804.55 289.00 764.28
+ Q 288.39 763.80 288.01 764.47
+ L 202.07 919.33
+ Q 201.76 919.89 202.28 920.25
+ C 273.19 969.94 350.55 1007.70 435.68 1023.45
+ Q 436.43 1023.59 435.67 1023.70
+ L 433.44 1024.00
+ L 0.00 1024.00
+ L 0.00 0.00
+ Z"
+/>
+<path fill="#ffffff" d="
+ M 459.56 0.00
+ L 627.56 0.00
+ L 625.27 0.36
+ Q 624.34 0.51 625.27 0.64
+ Q 630.93 1.46 636.49 2.76
+ C 712.22 20.45 779.39 57.67 841.35 103.70
+ Q 841.80 104.04 841.54 104.54
+ L 760.04 261.07
+ A 0.46 0.45 33.6 0 1 759.34 261.21
+ C 694.58 207.68 609.67 157.57 522.82 158.96
+ C 473.98 159.74 430.08 183.90 416.22 232.71
+ C 408.71 259.12 411.31 286.89 424.00 311.07
+ C 440.40 342.34 474.18 365.65 504.49 382.27
+ C 599.64 434.42 710.10 466.52 785.81 547.18
+ C 829.06 593.26 851.93 651.15 854.95 714.99
+ C 857.69 772.63 848.74 831.72 822.17 883.36
+ C 780.47 964.45 698.78 1007.88 611.83 1023.20
+ C 611.41 1023.27 610.58 1023.12 610.38 1023.42
+ Q 610.16 1023.75 610.55 1023.77
+ L 613.69 1024.00
+ L 433.44 1024.00
+ L 435.67 1023.70
+ Q 436.43 1023.59 435.68 1023.45
+ C 350.55 1007.70 273.19 969.94 202.28 920.25
+ Q 201.76 919.89 202.07 919.33
+ L 288.01 764.47
+ Q 288.39 763.80 289.00 764.28
+ C 339.68 804.55 398.31 836.89 460.41 855.88
+ C 498.46 867.52 540.54 873.53 579.56 865.62
+ C 641.91 852.99 678.62 801.79 673.67 738.67
+ C 671.24 707.60 653.58 682.52 629.65 663.71
+ C 601.46 641.56 567.67 625.31 535.50 611.25
+ C 444.46 571.48 342.95 535.16 276.89 456.92
+ C 244.05 418.03 224.20 370.95 217.55 319.99
+ C 211.99 277.34 213.42 235.18 224.52 194.16
+ C 254.86 81.95 352.26 19.15 461.92 0.48
+ Q 462.64 0.35 461.92 0.27
+ L 459.56 0.00
+ Z"
+/>
+<path fill="#35393f" d="
+ M 627.56 0.00
+ L 1024.00 0.00
+ L 1024.00 1024.00
+ L 613.69 1024.00
+ L 610.55 1023.77
+ Q 610.16 1023.75 610.38 1023.42
+ C 610.58 1023.12 611.41 1023.27 611.83 1023.20
+ C 698.78 1007.88 780.47 964.45 822.17 883.36
+ C 848.74 831.72 857.69 772.63 854.95 714.99
+ C 851.93 651.15 829.06 593.26 785.81 547.18
+ C 710.10 466.52 599.64 434.42 504.49 382.27
+ C 474.18 365.65 440.40 342.34 424.00 311.07
+ C 411.31 286.89 408.71 259.12 416.22 232.71
+ C 430.08 183.90 473.98 159.74 522.82 158.96
+ C 609.67 157.57 694.58 207.68 759.34 261.21
+ A 0.46 0.45 33.6 0 0 760.04 261.07
+ L 841.54 104.54
+ Q 841.80 104.04 841.35 103.70
+ C 779.39 57.67 712.22 20.45 636.49 2.76
+ Q 630.93 1.46 625.27 0.64
+ Q 624.34 0.51 625.27 0.36
+ L 627.56 0.00
+ Z"
+/>
+</svg>