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.

add default domain suggestion

Steven Teyfcc2dcd87a3a
diff --git a/apps/web/ui/modals/add-edit-link-modal/index.tsx b/apps/web/ui/modals/add-edit-link-modal/index.tsx
index b2a044e2cb..c8cd2db922 100644
--- a/apps/web/ui/modals/add-edit-link-modal/index.tsx
+++ b/apps/web/ui/modals/add-edit-link-modal/index.tsx
@@ -21,9 +21,11 @@ import {
useMediaQuery,
useRouterStuff,
} from "@dub/ui";
+import { ArrowTurnRight2 } from "@dub/ui/src/icons";
import { InfoTooltip } from "@dub/ui/src/tooltip";
import {
DEFAULT_LINK_PROPS,
+ DUB_DOMAINS,
cn,
deepEqual,
getApexDomain,
@@ -714,8 +716,8 @@ function AddEditLinkModal({
</Tooltip>
)}
</div>
- {keyError &&
- (keyError.includes("Upgrade to Pro") ? (
+ {keyError ? (
+ keyError.includes("Upgrade to Pro") ? (
<p className="mt-2 text-sm text-red-600" id="key-error">
{keyError.split("Upgrade to Pro")[0]}
<span
@@ -732,7 +734,10 @@ function AddEditLinkModal({
<p className="mt-2 text-sm text-red-600" id="key-error">
{keyError}
</p>
- ))}
+ )
+ ) : (
+ <DefaultDomainPrompt data={data} setData={setData} />
+ )}
</div>
)}
</div>
@@ -804,6 +809,32 @@ function AddEditLinkModal({
);
}
+function DefaultDomainPrompt({
+ data,
+ setData,
+}: {
+ data: LinkWithTagsProps;
+ setData: Dispatch<SetStateAction<LinkWithTagsProps>>;
+}) {
+ const apexDomain = getApexDomain(data.url);
+ const hostnameFor = DUB_DOMAINS.find((domain) =>
+ domain?.allowedHostnames?.includes(apexDomain),
+ );
+ const domain = hostnameFor?.slug;
+
+ if (!domain || data.domain === domain) return null;
+
+ return (
+ <button
+ className="flex items-center gap-1 p-2 text-sm text-gray-500 transition-all duration-75 hover:text-gray-700 active:scale-[0.98]"
+ onClick={() => setData({ ...data, domain })}
+ >
+ <ArrowTurnRight2 className="h-4 w-4" />
+ <p>Use the {domain} domain instead?</p>
+ </button>
+ );
+}
+
function AddEditLinkButton({
setShowAddEditLinkModal,
}: {
diff --git a/apps/web/ui/modals/add-edit-link-modal/tags-section.tsx b/apps/web/ui/modals/add-edit-link-modal/tags-section.tsx
index e3eecff521..1627e42947 100644
--- a/apps/web/ui/modals/add-edit-link-modal/tags-section.tsx
+++ b/apps/web/ui/modals/add-edit-link-modal/tags-section.tsx
@@ -16,6 +16,7 @@ import { Check, ChevronDown, Tag, X } from "lucide-react";
import { Dispatch, SetStateAction, useEffect, useRef, useState } from "react";
import { toast } from "sonner";
import { mutate } from "swr";
+import { useDebounce } from "use-debounce";
export default function TagsSection({
data,
@@ -62,10 +63,12 @@ export default function TagsSection({
},
});
+ const [debouncedUrl] = useDebounce(url, 500);
+
useEffect(() => {
if (
!linkId &&
- url &&
+ debouncedUrl &&
title &&
description &&
!exceededAI &&
@@ -77,7 +80,7 @@ export default function TagsSection({
complete(
`From the list of avaialble tags below, suggest relevant tags for this link:
- - URL: ${url}
+ - URL: ${debouncedUrl}
- Meta title: ${title}
- Meta description: ${description}.
@@ -86,7 +89,7 @@ export default function TagsSection({
Available tags: ${availableTags.map(({ name }) => name).join(", ")}`,
);
}
- }, [url, title, description]);
+ }, [debouncedUrl, title, description]);
const [creatingTag, setCreatingTag] = useState(false);