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.

Partner link via improvements

Marcus Farrellf37f019b0381
diff --git a/apps/web/app/(ee)/partners.dub.co/(dashboard)/programs/[programSlug]/(enrolled)/links/partner-link-card.tsx b/apps/web/app/(ee)/partners.dub.co/(dashboard)/programs/[programSlug]/(enrolled)/links/partner-link-card.tsx
index fd49a495a3..717e5c6f0f 100644
--- a/apps/web/app/(ee)/partners.dub.co/(dashboard)/programs/[programSlug]/(enrolled)/links/partner-link-card.tsx
+++ b/apps/web/app/(ee)/partners.dub.co/(dashboard)/programs/[programSlug]/(enrolled)/links/partner-link-card.tsx
@@ -18,6 +18,7 @@ import {
LinkLogo,
LoadingSpinner,
StatusBadge,
+ Tooltip,
useInViewport,
UserCheck,
useRouterStuff,
@@ -91,6 +92,8 @@ export function PartnerLinkCard({ link }: { link: PartnerProfileLinkProps }) {
});
const isDeactivated = programEnrollment?.status === "deactivated";
+ const isQueryLinkStructure =
+ programEnrollment?.group?.linkStructure === "query";
const discountCodeSection = link.discountCode ? (
<div className="hidden h-8 items-center gap-1.5 rounded-lg border border-neutral-200 pl-2 pr-1.5 sm:flex">
@@ -128,22 +131,35 @@ export function PartnerLinkCard({ link }: { link: PartnerProfileLinkProps }) {
<div className="flex min-w-0 flex-col">
<div className="flex flex-col gap-0.5">
<div className="flex items-center gap-1">
- <a
- href={isDeactivated ? undefined : partnerLink}
- target="_blank"
- rel="noopener noreferrer"
- className={cn(
- "truncate text-sm font-semibold leading-6 transition-colors",
- isDeactivated
- ? "cursor-default text-neutral-400"
- : "text-neutral-900 hover:text-black",
- )}
- onClick={
- isDeactivated ? (e) => e.preventDefault() : undefined
+ <Tooltip
+ content={
+ <QueryLinkStructureHelpText
+ link={link}
+ className="px-3 py-2 first-letter:uppercase"
+ />
}
+ disabled={!isQueryLinkStructure || isDeactivated}
>
- {getPrettyUrl(partnerLink)}
- </a>
+ <a
+ href={isDeactivated ? undefined : partnerLink}
+ target="_blank"
+ rel="noopener noreferrer"
+ className={cn(
+ "truncate text-sm font-semibold leading-6 transition-colors",
+ isDeactivated
+ ? "cursor-default text-neutral-400"
+ : "text-neutral-900 hover:text-black",
+ isQueryLinkStructure &&
+ !isDeactivated &&
+ "cursor-copy underline decoration-dotted underline-offset-2",
+ )}
+ onClick={
+ isDeactivated ? (e) => e.preventDefault() : undefined
+ }
+ >
+ {getPrettyUrl(partnerLink)}
+ </a>
+ </Tooltip>
{!isDeactivated && (
<CopyButton value={partnerLink} variant="neutral" />
)}
@@ -163,35 +179,20 @@ export function PartnerLinkCard({ link }: { link: PartnerProfileLinkProps }) {
/* The max width implementation here is a bit hacky, we should improve in the future */
<div className="flex max-w-[100px] items-center gap-1 py-0 pl-1 pr-1.5 sm:w-fit sm:max-w-[400px]">
<ArrowTurnRight2 className="h-3 w-3 shrink-0 text-neutral-400" />
- {programEnrollment?.group?.linkStructure === "query" ? (
- <QueryLinkStructureHelpText
- link={link}
- className="mt-0.5"
- />
- ) : (
- <a
- href={isDeactivated ? undefined : link.url}
- target="_blank"
- rel="noopener noreferrer"
- className="cursor-alias truncate text-sm text-neutral-500 decoration-dotted transition-colors hover:text-neutral-700 hover:underline hover:underline-offset-2"
- title={getPrettyUrl(link.url)}
- onClick={
- isDeactivated ? (e) => e.preventDefault() : undefined
- }
- >
- {getPrettyUrl(link.url)}
- </a>
- )}
+ <a
+ href={isDeactivated ? undefined : link.url}
+ target="_blank"
+ rel="noopener noreferrer"
+ className="cursor-alias truncate text-sm text-neutral-500 decoration-dotted transition-colors hover:text-neutral-700 hover:underline hover:underline-offset-2"
+ title={getPrettyUrl(link.url)}
+ onClick={
+ isDeactivated ? (e) => e.preventDefault() : undefined
+ }
+ >
+ {getPrettyUrl(link.url)}
+ </a>
</div>
)}
-
- {hasIncentives &&
- programEnrollment?.group?.linkStructure === "query" && (
- <QueryLinkStructureHelpText
- link={link}
- className="mt-0.5 pl-0.5"
- />
- )}
</div>
</div>
</div>
diff --git a/apps/web/app/(ee)/partners.dub.co/(dashboard)/programs/[programSlug]/(enrolled)/page-client.tsx b/apps/web/app/(ee)/partners.dub.co/(dashboard)/programs/[programSlug]/(enrolled)/page-client.tsx
index 95e6a119c6..69ea47e1ef 100644
--- a/apps/web/app/(ee)/partners.dub.co/(dashboard)/programs/[programSlug]/(enrolled)/page-client.tsx
+++ b/apps/web/app/(ee)/partners.dub.co/(dashboard)/programs/[programSlug]/(enrolled)/page-client.tsx
@@ -620,26 +620,36 @@ function RewardsTermsList() {
return null;
}
+ // Every item ends with a separator; the list is shifted right by one
+ // separator width and clipped, so the separator ending each line (including
+ // the last item's) is hidden when the items wrap
return (
- <div className="flex flex-wrap items-center gap-x-1.5 text-xs">
- {items.map((item, idx) => (
- <span key={item.label} className="inline-flex items-center gap-1.5">
- <span>
- <span className="font-semibold text-neutral-600">{item.value}</span>{" "}
- <a
- href={item.href}
- target="_blank"
- rel="noopener noreferrer"
- className="font-medium text-neutral-500 underline decoration-dotted underline-offset-2"
+ <div className="min-w-0 overflow-x-clip">
+ <div className="-mr-4 flex flex-wrap items-center justify-end text-xs">
+ {items.map((item) => (
+ <span key={item.label} className="inline-flex items-center">
+ <span>
+ <span className="font-semibold text-neutral-600">
+ {item.value}
+ </span>{" "}
+ <a
+ href={item.href}
+ target="_blank"
+ rel="noopener noreferrer"
+ className="font-medium text-neutral-500 underline decoration-dotted underline-offset-2"
+ >
+ {item.label}
+ </a>
+ </span>
+ <span
+ aria-hidden="true"
+ className="w-4 text-center font-semibold text-neutral-600"
>
- {item.label}
- </a>
+ •
+ </span>
</span>
- {idx < items.length - 1 && (
- <span className="font-semibold text-neutral-600">•</span>
- )}
- </span>
- ))}
+ ))}
+ </div>
</div>
);
}
@@ -667,7 +677,7 @@ function getRewardLinkOptions({
}
const LINK_SELECTOR_BOX_CLASSNAME =
- "h-10 w-[241px] min-w-0 max-w-full rounded-lg border border-border-subtle bg-bg-default";
+ "h-10 min-w-0 max-w-full rounded-lg pl-1.5 pr-2.5";
function RewardList() {
const { programEnrollment } = useProgramEnrollment();
@@ -862,6 +872,15 @@ function RewardListItem({
const [copied, copyToClipboard] = useCopyToClipboard();
const copyDisabled =
isDeactivated || !link.copyValue || link.copyValue.length === 0;
+ const [isLinkSelectorOpen, setIsLinkSelectorOpen] = useState(false);
+
+ const queryLinkHelpText = queryLinkHelpTextLink ? (
+ <QueryLinkStructureHelpText
+ link={queryLinkHelpTextLink}
+ className="px-3 py-2 first-letter:uppercase"
+ />
+ ) : null;
+
const showLinkSelector =
Boolean(linkSelectorLoading) ||
Boolean(linkOptions && linkOptions.length > 1);
@@ -882,7 +901,7 @@ function RewardListItem({
comboboxOptions?.find((option) => option.value === selectedLinkId) ?? null;
const discountCodeSection = discountCode ? (
- <div className="hidden items-center gap-1.5 rounded-lg border border-neutral-200 py-1 pl-2 pr-1.5 sm:flex">
+ <div className="hidden h-8 items-center gap-1.5 rounded-lg border border-neutral-200 pl-2 pr-1.5 sm:flex">
<span className="text-sm font-medium leading-5 tracking-tight text-neutral-500">
Discount code
</span>
@@ -901,7 +920,7 @@ function RewardListItem({
isDeactivated && "opacity-80",
)}
>
- <div className="flex items-center justify-between">
+ <div className="flex items-center justify-between gap-3">
<h3 className="text-base font-semibold tracking-tight text-neutral-800">
{title}
</h3>
@@ -912,14 +931,14 @@ function RewardListItem({
<div className="bg-neutral-50 px-3 py-2.5">
<div className="flex items-center justify-between gap-2">
{showLinkSelector ? (
- <div className="w-[241px] shrink-0">
+ <div className="-my-1 -ml-1.5 min-w-0">
{linkSelectorLoading ? (
<div
role="status"
aria-label="Loading links"
className={cn(
LINK_SELECTOR_BOX_CLASSNAME,
- "flex items-center justify-center",
+ "flex items-center",
)}
>
<LoadingSpinner className="size-4" />
@@ -932,32 +951,47 @@ function RewardListItem({
onSelectLink?.(option.value);
}}
options={comboboxOptions}
+ open={isLinkSelectorOpen}
+ onOpenChange={setIsLinkSelectorOpen}
forceDropdown
matchTriggerWidth
placeholder="No link yet"
inputClassName="text-sm h-10"
popoverProps={{
contentClassName:
- "w-[241px] rounded-lg border border-border-subtle p-1",
+ "sm:w-auto min-w-[var(--radix-popover-trigger-width)] max-w-[min(400px,calc(100vw-16px))] rounded-lg border border-border-subtle p-1",
}}
trigger={
<button
type="button"
className={cn(
LINK_SELECTOR_BOX_CLASSNAME,
- "text-content-default focus:border-border-emphasis flex items-center gap-2 px-3 text-left text-sm outline-none focus:ring-0",
+ "text-content-default flex w-fit items-center gap-2.5 text-left text-sm outline-none transition-colors hover:bg-neutral-200/60 focus-visible:bg-neutral-200/60 data-[state=open]:bg-neutral-200/60",
)}
>
{link.apexDomain && (
- <LinkLogo
- apexDomain={link.apexDomain}
- className="size-4 shrink-0 sm:size-4"
- imageProps={{ width: 16, height: 16 }}
- />
+ <div className="shrink-0 rounded-full border border-neutral-200 bg-white p-1">
+ <LinkLogo
+ apexDomain={link.apexDomain}
+ className="size-4.5 sm:size-4.5 shrink-0 rounded-full"
+ imageProps={{ width: 18, height: 18 }}
+ />
+ </div>
)}
- <span className="min-w-0 shrink grow truncate">
- {link.displayText}
- </span>
+ <Tooltip
+ content={queryLinkHelpText}
+ disabled={!queryLinkHelpText || isLinkSelectorOpen}
+ >
+ <span
+ className={cn(
+ "min-w-0 truncate",
+ queryLinkHelpText &&
+ "underline decoration-dotted underline-offset-2",
+ )}
+ >
+ {link.displayText}
+ </span>
+ </Tooltip>
<ChevronDown className="text-content-muted size-4 shrink-0" />
</button>
}
@@ -973,23 +1007,20 @@ function RewardListItem({
imageProps={{ width: 18, height: 18 }}
/>
</div>
- <CopyText
- value={link.copyValue}
- className="min-w-0 truncate text-sm font-medium -tracking-wider text-neutral-600"
+ <Tooltip
+ content={queryLinkHelpText}
+ disabled={!queryLinkHelpText}
>
- {link.displayText}
- </CopyText>
- {queryLinkHelpTextLink && (
- <>
- <span className="hidden text-sm text-neutral-500 sm:block">
- →
- </span>
- <QueryLinkStructureHelpText
- link={queryLinkHelpTextLink}
- className="hidden sm:block"
- />
- </>
- )}
+ <CopyText
+ value={link.copyValue}
+ className={cn(
+ "text-content-default min-w-0 truncate text-sm",
+ queryLinkHelpText && "underline",
+ )}
+ >
+ {link.displayText}
+ </CopyText>
+ </Tooltip>
</div>
)}
@@ -1038,12 +1069,6 @@ function RewardListItem({
)}
</div>
</div>
- {showLinkSelector && queryLinkHelpTextLink && (
- <QueryLinkStructureHelpText
- link={queryLinkHelpTextLink}
- className="mt-1.5 hidden sm:block"
- />
- )}
</div>
{rewards.length > 0 ? (
diff --git a/apps/web/lib/partners/query-link-structure-help-text.tsx b/apps/web/lib/partners/query-link-structure-help-text.tsx
index 10d68c7bf8..e7dff58bba 100644
--- a/apps/web/lib/partners/query-link-structure-help-text.tsx
+++ b/apps/web/lib/partners/query-link-structure-help-text.tsx
@@ -21,14 +21,14 @@ export const QueryLinkStructureHelpText = ({
href={link.url}
target="_blank"
rel="noopener noreferrer"
- className="cursor-alias text-neutral-700 decoration-dotted underline-offset-2 hover:underline"
+ className="cursor-alias font-medium text-neutral-700 decoration-dotted underline-offset-2 hover:underline"
>
{getDomainWithoutWWW(link.url)}
</a>{" "}
by adding{" "}
<CopyText
value={appendValue}
- className="font-mono text-xs text-neutral-700"
+ className="font-mono text-xs font-medium text-neutral-700"
>
{appendValue}
</CopyText>{" "}
diff --git a/packages/ui/src/copy-text.tsx b/packages/ui/src/copy-text.tsx
index 916673e402..0585362f53 100644
--- a/packages/ui/src/copy-text.tsx
+++ b/packages/ui/src/copy-text.tsx
@@ -1,32 +1,33 @@
"use client";
import { cn } from "@dub/utils";
-import { ReactNode } from "react";
+import { ComponentPropsWithoutRef, forwardRef, ReactNode } from "react";
import { toast } from "sonner";
import { useCopyToClipboard } from "./hooks";
-export function CopyText({
- value,
- children,
- className,
- successMessage,
-}: {
- value: string;
- children: ReactNode;
- className?: string;
- successMessage?: string;
-}) {
+// Forwards its ref and props so it can be used as a Radix `asChild` trigger (e.g. inside a Tooltip)
+export const CopyText = forwardRef<
+ HTMLButtonElement,
+ Omit<ComponentPropsWithoutRef<"button">, "value" | "children"> & {
+ value: string;
+ children: ReactNode;
+ successMessage?: string;
+ }
+>(({ value, children, className, successMessage, onClick, ...rest }, ref) => {
const [copied, copyToClipboard] = useCopyToClipboard();
return (
<button
+ ref={ref}
+ type="button"
+ {...rest}
onClick={(e) => {
+ onClick?.(e);
e.stopPropagation();
toast.promise(copyToClipboard(value), {
success: successMessage || "Copied to clipboard!",
});
}}
- type="button"
className={cn(
"cursor-copy text-sm text-neutral-700 decoration-dotted underline-offset-2 hover:underline",
copied && "cursor-default",
@@ -36,4 +37,6 @@ export function CopyText({
{children}
</button>
);
-}
+});
+
+CopyText.displayName = "CopyText";