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.

Improve `partnerLinksDisplay`

Steven Tey768d3eec26b2
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 ac55f64f66..d41e18fbf4 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
@@ -26,6 +26,7 @@ import {
useRouterStuff,
} from "@dub/ui";
import { Areas, TimeSeriesChart, XAxis } from "@dub/ui/charts";
+import { ArrowRight } from "@dub/ui/icons";
import {
cn,
currencyFormatter,
@@ -98,8 +99,18 @@ export function PartnerLinkCard({ link }: { link: PartnerProfileLinkProps }) {
const isDeactivated = programEnrollment?.status === "deactivated";
const isQueryLinkStructure =
programEnrollment?.group?.linkStructure === "query";
+ const descriptionEnabled = displayProperties.includes("description");
+ const hasDescription = Boolean(link.partnerLinkComments?.trim());
const showTitle =
displayProperties.includes("title") && Boolean(link.partnerLinkTitle);
+ const showInlineShortLink = showTitle && displayProperties.includes("link");
+ const showDescription = descriptionEnabled && hasDescription;
+ // Description only replaces rewards on links that actually have one.
+ const rewardsEnabled =
+ (displayProperties.includes("rewards") || descriptionEnabled) &&
+ !showDescription;
+ const showRewardDetails =
+ rewardsEnabled && hasIncentives && Boolean(primaryText);
const shortLink = (
<Tooltip
@@ -115,8 +126,13 @@ export function PartnerLinkCard({ link }: { link: PartnerProfileLinkProps }) {
href={isDeactivated ? undefined : partnerLink}
target="_blank"
rel="noopener noreferrer"
+ title={
+ isQueryLinkStructure && !isDeactivated
+ ? undefined
+ : getPrettyUrl(partnerLink)
+ }
className={cn(
- "truncate text-sm transition-colors",
+ "min-w-0 truncate text-sm transition-colors",
showTitle
? "text-neutral-500 hover:text-neutral-700 hover:underline hover:underline-offset-2"
: "font-semibold leading-6",
@@ -168,12 +184,13 @@ export function PartnerLinkCard({ link }: { link: PartnerProfileLinkProps }) {
</div>
<div className="flex min-w-0 flex-col">
- <div className="flex flex-col gap-0.5">
- <div className="flex items-center gap-1">
+ <div className="flex min-w-0 flex-col gap-0.5">
+ <div className="flex min-w-0 items-center gap-1">
{showTitle ? (
<span
className={cn(
- "truncate text-sm font-semibold leading-6",
+ "min-w-0 truncate text-sm font-semibold leading-6",
+ showInlineShortLink && "max-w-[45%] shrink-0",
isDeactivated ? "text-neutral-400" : "text-neutral-900",
)}
title={link.partnerLinkTitle ?? undefined}
@@ -181,25 +198,36 @@ export function PartnerLinkCard({ link }: { link: PartnerProfileLinkProps }) {
{link.partnerLinkTitle}
</span>
) : (
- shortLink
+ <div className="flex min-w-0 items-center">{shortLink}</div>
)}
{!isDeactivated && (
- <CopyButton value={partnerLink} variant="neutral" />
+ <CopyButton
+ value={partnerLink}
+ variant="neutral"
+ className="shrink-0"
+ />
)}
-
- {link.partnerLinkComments && (
- <CommentsBadge comments={link.partnerLinkComments} />
+ {link.partnerLinkComments && !showDescription && (
+ <div className="hidden shrink-0 sm:block">
+ <CommentsBadge comments={link.partnerLinkComments} />
+ </div>
+ )}
+ {showInlineShortLink && (
+ <div className="flex min-w-0 items-center gap-1">
+ <ArrowRight className="size-3 shrink-0 text-neutral-400" />
+ {shortLink}
+ </div>
)}
</div>
- {showTitle && (
- <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" />
- {shortLink}
- </div>
- )}
-
- {hasIncentives && primaryText ? (
+ {showDescription ? (
+ <p
+ className="min-w-0 truncate pl-0.5 text-sm text-neutral-500"
+ title={link.partnerLinkComments ?? undefined}
+ >
+ {link.partnerLinkComments}
+ </p>
+ ) : showRewardDetails && primaryText ? (
<PartnerLinkRewardsSummary
primaryText={primaryText}
primaryReward={primaryReward}
@@ -208,7 +236,8 @@ export function PartnerLinkCard({ link }: { link: PartnerProfileLinkProps }) {
onToggleRewards={toggleRewards}
/>
) : (
- !showTitle && (
+ !showTitle &&
+ !showDescription && (
/* 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" />
@@ -258,12 +287,14 @@ export function PartnerLinkCard({ link }: { link: PartnerProfileLinkProps }) {
</div>
</div>
{displayOption === "full" && <StatsCharts link={link} />}
- <PartnerLinkRewardsPanel
- rewards={rewards}
- discount={discount}
- showRewards={showRewards}
- additionalCount={additionalCount}
- />
+ {rewardsEnabled && (
+ <PartnerLinkRewardsPanel
+ rewards={rewards}
+ discount={discount}
+ showRewards={showRewards}
+ additionalCount={additionalCount}
+ />
+ )}
</CardList.Card>
);
}
diff --git a/apps/web/app/(ee)/partners.dub.co/(dashboard)/programs/[programSlug]/(enrolled)/links/partner-link-display.tsx b/apps/web/app/(ee)/partners.dub.co/(dashboard)/programs/[programSlug]/(enrolled)/links/partner-link-display.tsx
index 9891e6c307..02f9347881 100644
--- a/apps/web/app/(ee)/partners.dub.co/(dashboard)/programs/[programSlug]/(enrolled)/links/partner-link-display.tsx
+++ b/apps/web/app/(ee)/partners.dub.co/(dashboard)/programs/[programSlug]/(enrolled)/links/partner-link-display.tsx
@@ -1,5 +1,6 @@
"use client";
+import { partnerLinksDisplayProperties } from "@/lib/partners/partner-links-display";
import { PartnerLinksDisplayContext } from "@/lib/swr/use-partner-links-display";
import useProgramEnrollment from "@/lib/swr/use-program-enrollment";
import { Button, Popover } from "@dub/ui";
@@ -9,11 +10,6 @@ import { ChevronDown } from "lucide-react";
import { AnimatePresence, motion } from "motion/react";
import { useContext, useState } from "react";
-const DISPLAY_PROPERTIES = [
- { id: "link" as const, label: "Short link", switch: "title" as const },
- { id: "title" as const, label: "Title", switch: "link" as const },
-];
-
export function PartnerLinkDisplay() {
const { showDetailedAnalytics } = useProgramEnrollment();
const {
@@ -68,7 +64,7 @@ export function PartnerLinkDisplay() {
Display Properties
</span>
<div className="mt-4 flex flex-wrap gap-2">
- {DISPLAY_PROPERTIES.map((property) => {
+ {partnerLinksDisplayProperties.map((property) => {
const active = displayProperties.includes(property.id);
return (
<button
@@ -80,11 +76,13 @@ export function PartnerLinkDisplay() {
? displayProperties.filter((p) => p !== property.id)
: [...displayProperties, property.id];
- // Toggle switched property (short link ↔ title)
- next = [
- ...next.filter((p) => p !== property.switch),
- ...(active ? [property.switch] : []),
- ];
+ if (property.switch) {
+ // Reward details and description replace each other
+ next = [
+ ...next.filter((p) => p !== property.switch),
+ ...(active ? [property.switch] : []),
+ ];
+ }
setDisplayProperties(next);
}}
diff --git a/apps/web/lib/partners/partner-links-display.ts b/apps/web/lib/partners/partner-links-display.ts
new file mode 100644
index 0000000000..6e3db6649d
--- /dev/null
+++ b/apps/web/lib/partners/partner-links-display.ts
@@ -0,0 +1,42 @@
+export const partnerLinksDisplayPropertyIds = [
+ "link",
+ "rewards",
+ "title",
+ "description",
+] as const;
+
+export type PartnerLinksDisplayProperty =
+ (typeof partnerLinksDisplayPropertyIds)[number];
+
+export const partnerLinksDisplayProperties: {
+ id: PartnerLinksDisplayProperty;
+ label: string;
+ switch?: PartnerLinksDisplayProperty;
+}[] = [
+ { id: "link", label: "Short link" },
+ { id: "rewards", label: "Reward details", switch: "description" },
+ { id: "title", label: "Link title" },
+ { id: "description", label: "Link description", switch: "rewards" },
+];
+
+export const defaultPartnerLinksDisplayProperties: PartnerLinksDisplayProperty[] =
+ ["link", "rewards"];
+
+/**
+ * Preferences saved before reward details / description only stored "link"
+ * and/or "title". Those views always showed the short link and reward line.
+ */
+export function normalizePartnerLinksDisplayProperties(
+ properties: PartnerLinksDisplayProperty[],
+): PartnerLinksDisplayProperty[] {
+ const hasSecondaryLine =
+ properties.includes("rewards") || properties.includes("description");
+
+ if (hasSecondaryLine) return properties;
+
+ const next = new Set<PartnerLinksDisplayProperty>(properties);
+ next.add("link");
+ next.add("rewards");
+
+ return partnerLinksDisplayPropertyIds.filter((id) => next.has(id));
+}
diff --git a/apps/web/lib/swr/use-partner-links-display.tsx b/apps/web/lib/swr/use-partner-links-display.tsx
index f2774efc80..04bc0ea9f8 100644
--- a/apps/web/lib/swr/use-partner-links-display.tsx
+++ b/apps/web/lib/swr/use-partner-links-display.tsx
@@ -1,6 +1,11 @@
"use client";
import { updateProgramEnrollmentPreferences } from "@/lib/actions/partners/update-program-enrollment-preferences";
+import {
+ defaultPartnerLinksDisplayProperties,
+ normalizePartnerLinksDisplayProperties,
+ type PartnerLinksDisplayProperty,
+} from "@/lib/partners/partner-links-display";
import useProgramEnrollment from "@/lib/swr/use-program-enrollment";
import { useAction } from "next-safe-action/hooks";
import {
@@ -15,23 +20,21 @@ import {
import { mutate } from "swr";
type PartnerLinksDisplayOption = "full" | "cards";
-type PartnerLinksDisplayProperty = "link" | "title";
type PartnerLinksDisplayPreferences = {
displayOption: PartnerLinksDisplayOption;
displayProperties: PartnerLinksDisplayProperty[];
};
-const DEFAULT_DISPLAY_PROPERTIES: PartnerLinksDisplayProperty[] = ["link"];
-
/** Read persisted partner links display prefs (for Analytics / Events / filters). */
export function usePartnerLinksDisplay() {
const { programEnrollment } = useProgramEnrollment();
return {
- displayProperties:
+ displayProperties: normalizePartnerLinksDisplayProperties(
programEnrollment?.partnerPreferences?.linksDisplay?.displayProperties ??
- DEFAULT_DISPLAY_PROPERTIES,
+ defaultPartnerLinksDisplayProperties,
+ ),
};
}
@@ -49,7 +52,7 @@ export const PartnerLinksDisplayContext =
createContext<PartnerLinksDisplayContextValue>({
displayOption: "full",
setDisplayOption: () => {},
- displayProperties: DEFAULT_DISPLAY_PROPERTIES,
+ displayProperties: defaultPartnerLinksDisplayProperties,
setDisplayProperties: () => {},
isDirty: false,
persist: () => {},
@@ -70,13 +73,15 @@ export function PartnerLinksDisplayProvider({
const persisted = programEnrollment?.partnerPreferences?.linksDisplay ?? null;
const resolvedPersisted = useMemo<PartnerLinksDisplayPreferences>(() => {
- if (persisted) return persisted;
return {
displayOption:
- (linksCount && linksCount > 5) || !showDetailedAnalytics
+ persisted?.displayOption ??
+ ((linksCount && linksCount > 5) || !showDetailedAnalytics
? "cards"
- : "full",
- displayProperties: DEFAULT_DISPLAY_PROPERTIES,
+ : "full"),
+ displayProperties: normalizePartnerLinksDisplayProperties(
+ persisted?.displayProperties ?? defaultPartnerLinksDisplayProperties,
+ ),
};
}, [persisted, linksCount, showDetailedAnalytics]);
diff --git a/apps/web/lib/zod/schemas/programs.ts b/apps/web/lib/zod/schemas/programs.ts
index 53d3a7d59a..a687e00f10 100644
--- a/apps/web/lib/zod/schemas/programs.ts
+++ b/apps/web/lib/zod/schemas/programs.ts
@@ -3,6 +3,7 @@ import {
DUB_PARTNERS_ANALYTICS_INTERVAL,
} from "@/lib/analytics/constants";
import { PAYOUT_HOLDING_PERIOD_DAYS } from "@/lib/constants/payouts";
+import { partnerLinksDisplayPropertyIds } from "@/lib/partners/partner-links-display";
import { COUNTRY_CODES } from "@dub/utils";
import {
Category,
@@ -154,7 +155,7 @@ export const ProgramEnrollmentApplicationSchema = z.object({
const partnerLinksDisplaySchema = z.object({
displayOption: z.enum(["full", "cards"]),
- displayProperties: z.array(z.enum(["link", "title"])),
+ displayProperties: z.array(z.enum(partnerLinksDisplayPropertyIds)),
});
export const programEnrollmentPreferencesValueSchemas = {