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.

fix custom link previews

Steven Tey617e7263abe3
diff --git a/apps/web/ui/modals/link-builder/conversion-tracking-toggle.tsx b/apps/web/ui/modals/link-builder/conversion-tracking-toggle.tsx
index 605bb176bf..11cfc8afa2 100644
--- a/apps/web/ui/modals/link-builder/conversion-tracking-toggle.tsx
+++ b/apps/web/ui/modals/link-builder/conversion-tracking-toggle.tsx
@@ -4,10 +4,9 @@ import {
InfoTooltip,
SimpleTooltipContent,
Switch,
- Tooltip,
+ TooltipContent,
useKeyboardShortcut,
} from "@dub/ui";
-import { PropsWithChildren } from "react";
import { useFormContext } from "react-hook-form";
import { LinkFormData } from ".";
@@ -16,7 +15,7 @@ const isNew =
new Date().getTime() - new Date("2025-01-13").getTime() < 30 * 86_400_000;
export function ConversionTrackingToggle() {
- const { plan } = useWorkspace();
+ const { slug, plan } = useWorkspace();
const { watch, setValue } = useFormContext<LinkFormData>();
const conversionsEnabled = !!plan && plan !== "free" && plan !== "pro";
@@ -50,35 +49,31 @@ export function ConversionTrackingToggle() {
/>
</span>
</div>
- <DisabledTooltip disabled={!conversionsEnabled}>
- <Switch
- checked={trackConversion}
- fn={(checked) =>
- setValue("trackConversion", checked, {
- shouldDirty: true,
- })
- }
- disabled={!conversionsEnabled}
- thumbIcon={
- conversionsEnabled ? undefined : (
- <CrownSmall className="size-full text-neutral-500" />
- )
- }
- />
- </DisabledTooltip>
+ <Switch
+ checked={trackConversion}
+ fn={(checked) =>
+ setValue("trackConversion", checked, {
+ shouldDirty: true,
+ })
+ }
+ disabledTooltip={
+ conversionsEnabled ? undefined : (
+ <TooltipContent
+ title="Conversion tracking is only available on Business plans and above."
+ cta="Upgrade to Business"
+ href={
+ slug ? `/${slug}/upgrade?exit=close` : "https://dub.co/pricing"
+ }
+ target="_blank"
+ />
+ )
+ }
+ thumbIcon={
+ conversionsEnabled ? undefined : (
+ <CrownSmall className="size-full text-neutral-500" />
+ )
+ }
+ />
</label>
);
}
-
-function DisabledTooltip({
- children,
- disabled,
-}: PropsWithChildren<{ disabled: boolean }>) {
- return disabled ? (
- <Tooltip content="Requires a Dub Business Plan to enable">
- <div>{children}</div>
- </Tooltip>
- ) : (
- children
- );
-}
diff --git a/apps/web/ui/modals/link-builder/link-preview.tsx b/apps/web/ui/modals/link-builder/link-preview.tsx
index 291cd59292..795a0040d8 100644
--- a/apps/web/ui/modals/link-builder/link-preview.tsx
+++ b/apps/web/ui/modals/link-builder/link-preview.tsx
@@ -1,15 +1,17 @@
-import { ProBadgeTooltip } from "@/ui/shared/pro-badge-tooltip";
+import useWorkspace from "@/lib/swr/use-workspace";
import {
Button,
FileUpload,
Icon,
+ InfoTooltip,
ShimmerDots,
- SimpleTooltipContent,
Switch,
+ TooltipContent,
useKeyboardShortcut,
useMediaQuery,
} from "@dub/ui";
import {
+ CrownSmall,
Facebook,
GlobePointer,
LinkedIn,
@@ -68,6 +70,7 @@ const tabComponents: Record<Tab, ComponentType<OGPreviewProps>> = {
};
export function LinkPreview() {
+ const { slug, plan } = useWorkspace();
const { watch, setValue } = useFormContext<LinkFormData>();
const { proxy, title, description, image, url, password } = watch();
@@ -85,7 +88,7 @@ export function LinkPreview() {
const [selectedTab, setSelectedTab] = useState<Tab>("default");
const onImageChange = (image: string) => {
- setValue("image", image);
+ setValue("image", image, { shouldDirty: true });
setValue("proxy", true);
};
@@ -99,19 +102,39 @@ export function LinkPreview() {
<h2 className="text-sm font-medium text-gray-700">
Custom Link Preview
</h2>
- <ProBadgeTooltip
+ <InfoTooltip
content={
- <SimpleTooltipContent
- title="Customize how your links look when shared on social media to improve click-through rates."
- cta="Learn more."
- href="https://dub.co/help/article/custom-social-media-cards"
+ <TooltipContent
+ title="Customize how your links look when shared on social media to improve click-through rates. When enabled, the preview settings below will be shown publicly (instead of the URL's original metatags)."
+ cta="Learn more"
+ href="https://dub.co/help/article/custom-link-previews"
/>
}
/>
</div>
+
<Switch
checked={proxy}
fn={() => setValue("proxy", !proxy, { shouldDirty: true })}
+ disabledTooltip={
+ !plan || plan === "free" ? (
+ <TooltipContent
+ title="Custom Link Previews are only available on the Pro plan and above."
+ cta="Upgrade to Pro"
+ href={
+ slug
+ ? `/${slug}/upgrade?exit=close`
+ : "https://dub.co/pricing"
+ }
+ target="_blank"
+ />
+ ) : undefined
+ }
+ thumbIcon={
+ !plan || plan === "free" ? (
+ <CrownSmall className="size-full text-neutral-500" />
+ ) : undefined
+ }
/>
</div>
<div className="mt-2.5 grid grid-cols-4 gap-2">
@@ -273,6 +296,7 @@ export const ImagePreview = ({
};
function DefaultOGPreview({ title, description, children }: OGPreviewProps) {
+ const { plan } = useWorkspace();
const { setValue } = useFormContext<LinkFormData>();
return (
@@ -286,7 +310,9 @@ function DefaultOGPreview({ title, description, children }: OGPreviewProps) {
maxRows={2}
onChange={(e) => {
setValue("title", e.currentTarget.value, { shouldDirty: true });
- setValue("proxy", true, { shouldDirty: true });
+ if (plan && plan !== "free") {
+ setValue("proxy", true, { shouldDirty: true });
+ }
}}
/>
<ReactTextareaAutosize
@@ -297,7 +323,9 @@ function DefaultOGPreview({ title, description, children }: OGPreviewProps) {
setValue("description", e.currentTarget.value, {
shouldDirty: true,
});
- setValue("proxy", true, { shouldDirty: true });
+ if (plan && plan !== "free") {
+ setValue("proxy", true, { shouldDirty: true });
+ }
}}
/>
</div>
@@ -310,6 +338,7 @@ function FacebookOGPreview({
hostname,
children,
}: OGPreviewProps) {
+ const { plan } = useWorkspace();
const { setValue } = useFormContext<LinkFormData>();
return (
@@ -328,7 +357,9 @@ function FacebookOGPreview({
setValue("title", e.currentTarget.value, {
shouldDirty: true,
});
- setValue("proxy", true, { shouldDirty: true });
+ if (plan && plan !== "free") {
+ setValue("proxy", true, { shouldDirty: true });
+ }
}}
/>
<ReactTextareaAutosize
@@ -339,7 +370,9 @@ function FacebookOGPreview({
setValue("description", e.currentTarget.value, {
shouldDirty: true,
});
- setValue("proxy", true, { shouldDirty: true });
+ if (plan && plan !== "free") {
+ setValue("proxy", true, { shouldDirty: true });
+ }
}}
/>
</div>
@@ -350,6 +383,7 @@ function FacebookOGPreview({
}
function LinkedInOGPreview({ title, hostname, children }: OGPreviewProps) {
+ const { plan } = useWorkspace();
const { setValue } = useFormContext<LinkFormData>();
return (
@@ -369,7 +403,9 @@ function LinkedInOGPreview({ title, hostname, children }: OGPreviewProps) {
setValue("title", e.currentTarget.value, {
shouldDirty: true,
});
- setValue("proxy", true, { shouldDirty: true });
+ if (plan && plan !== "free") {
+ setValue("proxy", true, { shouldDirty: true });
+ }
}}
/>
<p className="text-xs text-[#00000099]">{hostname || "domain.com"}</p>
diff --git a/apps/web/ui/modals/link-builder/og-modal.tsx b/apps/web/ui/modals/link-builder/og-modal.tsx
index b8b1d83bd7..71180d6535 100644
--- a/apps/web/ui/modals/link-builder/og-modal.tsx
+++ b/apps/web/ui/modals/link-builder/og-modal.tsx
@@ -8,8 +8,8 @@ import {
FileUpload,
Modal,
Popover,
- SimpleTooltipContent,
Tooltip,
+ TooltipContent,
} from "@dub/ui";
import { LoadingCircle, Magic, Unsplash } from "@dub/ui/icons";
import { resizeImage } from "@dub/utils";
@@ -51,7 +51,7 @@ function OGModalInner({
showOGModal: boolean;
setShowOGModal: Dispatch<SetStateAction<boolean>>;
}) {
- const { id: workspaceId, mutate, exceededAI } = useWorkspace();
+ const { id: workspaceId, plan, exceededAI, mutate } = useWorkspace();
const { generatingMetatags } = useContext(LinkModalContext);
const {
@@ -91,7 +91,9 @@ function OGModalInner({
if (!image) return;
setValue("image", image, { shouldDirty: true });
- setValue("proxy", true, { shouldDirty: true });
+ if (plan && plan !== "free") {
+ setValue("proxy", true, { shouldDirty: true });
+ }
},
});
@@ -141,7 +143,9 @@ function OGModalInner({
useEffect(() => {
if (completionTitle) {
setValue("title", completionTitle, { shouldDirty: true });
- setValue("proxy", true, { shouldDirty: true });
+ if (plan && plan !== "free") {
+ setValue("proxy", true, { shouldDirty: true });
+ }
}
}, [completionTitle]);
@@ -187,7 +191,9 @@ function OGModalInner({
useEffect(() => {
if (completionDescription) {
setValue("description", completionDescription, { shouldDirty: true });
- setValue("proxy", true, { shouldDirty: true });
+ if (plan && plan !== "free") {
+ setValue("proxy", true, { shouldDirty: true });
+ }
}
}, [completionDescription]);
@@ -216,10 +222,10 @@ function OGModalInner({
<h3 className="text-lg font-medium">Link Preview</h3>
<ProBadgeTooltip
content={
- <SimpleTooltipContent
- title="Customize how your links look when shared on social media to improve click-through rates."
- cta="Learn more."
- href="https://dub.co/help/article/custom-social-media-cards"
+ <TooltipContent
+ title="Customize how your links look when shared on social media to improve click-through rates. When enabled, the preview settings below will be shown publicly (instead of the URL's original metatags)."
+ cta="Learn more"
+ href="https://dub.co/help/article/custom-link-previews"
/>
}
/>
@@ -274,7 +280,9 @@ function OGModalInner({
<UnsplashSearch
onImageSelected={(image) => {
setValue("image", image, { shouldDirty: true });
- setValue("proxy", true, { shouldDirty: true });
+ if (plan && plan !== "free") {
+ setValue("proxy", true, { shouldDirty: true });
+ }
}}
setOpenPopover={setOpenUnsplashPopover}
/>
@@ -304,7 +312,9 @@ function OGModalInner({
const image = await resizeImage(file);
setValue("image", image, { shouldDirty: true });
- setValue("proxy", true, { shouldDirty: true });
+ if (plan && plan !== "free") {
+ setValue("proxy", true, { shouldDirty: true });
+ }
// Delay to prevent flickering
setTimeout(() => setResizing(false), 500);
@@ -366,7 +376,9 @@ function OGModalInner({
value={title || ""}
onChange={(e) => {
setValue("title", e.target.value, { shouldDirty: true });
- setValue("proxy", true, { shouldDirty: true });
+ if (plan && plan !== "free") {
+ setValue("proxy", true, { shouldDirty: true });
+ }
}}
aria-invalid="true"
/>
@@ -422,7 +434,9 @@ function OGModalInner({
setValue("description", e.target.value, {
shouldDirty: true,
});
- setValue("proxy", true, { shouldDirty: true });
+ if (plan && plan !== "free") {
+ setValue("proxy", true, { shouldDirty: true });
+ }
}}
aria-invalid="true"
/>
@@ -431,24 +445,20 @@ function OGModalInner({
</div>
<div className="mt-6 flex items-center justify-between">
- <div>
- {parentProxy && (
- <button
- type="button"
- className="text-xs font-medium text-gray-700 transition-colors hover:text-gray-950"
- onClick={() => {
- setValueParent("proxy", false, { shouldDirty: true });
- ["title", "description", "image"].forEach(
- (key: "title" | "description" | "image") =>
- setValueParent(key, null, { shouldDirty: true }),
- );
- setShowOGModal(false);
- }}
- >
- Reset to default
- </button>
- )}
- </div>
+ <button
+ type="button"
+ className="text-xs font-medium text-gray-700 transition-colors hover:text-gray-950"
+ onClick={() => {
+ setValueParent("proxy", false, { shouldDirty: true });
+ ["title", "description", "image"].forEach(
+ (key: "title" | "description" | "image") =>
+ setValueParent(key, null, { shouldDirty: true }),
+ );
+ setShowOGModal(false);
+ }}
+ >
+ Reset to default
+ </button>
<div className="flex items-center gap-2">
<Button
type="button"
diff --git a/apps/web/ui/modals/link-builder/use-metatags.ts b/apps/web/ui/modals/link-builder/use-metatags.ts
index 70a69e4e6a..498158ea09 100644
--- a/apps/web/ui/modals/link-builder/use-metatags.ts
+++ b/apps/web/ui/modals/link-builder/use-metatags.ts
@@ -25,8 +25,8 @@ export function useMetatags({
const [generatingMetatags, setGeneratingMetatags] = useState(initial);
useEffect(() => {
- // if proxy is enabled, no need to generate metatags
- if (proxy) {
+ // no need to generate metatags if proxy is enabled, or if any of the metatags are set
+ if (proxy || title || description || image) {
setGeneratingMetatags(false);
return;
}
@@ -68,7 +68,7 @@ export function useMetatags({
} else {
setGeneratingMetatags(false);
}
- }, [debouncedUrl, password, proxy, enabled]);
+ }, [debouncedUrl, password, proxy, title, description, image, enabled]);
return { generatingMetatags };
}
diff --git a/apps/web/ui/modals/link-qr-modal.tsx b/apps/web/ui/modals/link-qr-modal.tsx
index a0ba58de46..8df0163f2d 100644
--- a/apps/web/ui/modals/link-qr-modal.tsx
+++ b/apps/web/ui/modals/link-qr-modal.tsx
@@ -19,7 +19,15 @@ import {
useLocalStorage,
useMediaQuery,
} from "@dub/ui";
-import { Check, Check2, Copy, Download, Hyperlink, Photo } from "@dub/ui/icons";
+import {
+ Check,
+ Check2,
+ Copy,
+ CrownSmall,
+ Download,
+ Hyperlink,
+ Photo,
+} from "@dub/ui/icons";
import { API_DOMAIN, cn, DUB_QR_LOGO, linkConstructor } from "@dub/utils";
import { AnimatePresence, motion } from "framer-motion";
import {
@@ -256,14 +264,24 @@ function LinkQRModalInner({
setData((d) => ({ ...d, hideLogo: !d.hideLogo }));
}}
disabledTooltip={
- plan === "free" ? (
+ !plan || plan === "free" ? (
<TooltipContent
title="You need to be on the Pro plan and above to customize your QR Code logo."
cta="Upgrade to Pro"
- href={slug ? `/${slug}/upgrade` : "https://dub.co/pricing"}
+ href={
+ slug
+ ? `/${slug}/upgrade?exit=close`
+ : "https://dub.co/pricing"
+ }
+ target="_blank"
/>
) : undefined
}
+ thumbIcon={
+ !plan || plan === "free" ? (
+ <CrownSmall className="size-full text-neutral-500" />
+ ) : undefined
+ }
/>
</div>