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 support for disabled links (#3082)

Steven Tey987e94af4169
diff --git a/apps/web/lib/api/links/utils/transform-link.ts b/apps/web/lib/api/links/utils/transform-link.ts
index bdf8cdb818..e46c1a2c75 100644
--- a/apps/web/lib/api/links/utils/transform-link.ts
+++ b/apps/web/lib/api/links/utils/transform-link.ts
@@ -39,7 +39,6 @@ export const transformLink = (
dashboard,
partnerGroupDefaultLinkId,
// hide undocumented fields from the API response for now
- disabledAt,
lastLeadAt,
lastConversionAt,
programEnrollment,
diff --git a/apps/web/lib/middleware/link.ts b/apps/web/lib/middleware/link.ts
index 74f8e2600c..d2eb81512f 100644
--- a/apps/web/lib/middleware/link.ts
+++ b/apps/web/lib/middleware/link.ts
@@ -30,10 +30,10 @@ import { linkCache } from "../api/links/cache";
import { isCaseSensitiveDomain } from "../api/links/case-sensitivity";
import { recordClickCache } from "../api/links/record-click-cache";
import { getLinkViaEdge } from "../planetscale";
-import { getDomainViaEdge } from "../planetscale/get-domain-via-edge";
import { getPartnerEnrollmentInfo } from "../planetscale/get-partner-enrollment-info";
import { cacheDeepLinkClickData } from "./utils/cache-deeplink-click-data";
import { crawlBitly } from "./utils/crawl-bitly";
+import { handleNotFoundLink } from "./utils/handle-not-found-link";
import { isIosAppStoreUrl } from "./utils/is-ios-app-store-url";
import { isSingularTrackingUrl } from "./utils/is-singular-tracking-url";
import { resolveABTestURL } from "./utils/resolve-ab-test-url";
@@ -90,23 +90,7 @@ export async function LinkMiddleware(req: NextRequest, ev: NextFetchEvent) {
return await crawlBitly(req);
}
- // check if domain has notFoundUrl configured
- const domainData = await getDomainViaEdge(domain);
- if (domainData?.notFoundUrl) {
- return NextResponse.redirect(domainData.notFoundUrl, {
- headers: {
- ...DUB_HEADERS,
- "X-Robots-Tag": "googlebot: noindex",
- // pass the Referer value to the not found URL
- Referer: req.url,
- },
- status: 302,
- });
- } else {
- return NextResponse.rewrite(new URL(`/${domain}/not-found`, req.url), {
- headers: DUB_HEADERS,
- });
- }
+ return await handleNotFoundLink(req);
}
isPartnerLink = Boolean(linkData.programId && linkData.partnerId);
@@ -144,6 +128,7 @@ export async function LinkMiddleware(req: NextRequest, ev: NextFetchEvent) {
proxy,
rewrite,
expiresAt,
+ disabledAt,
ios,
android,
expiredUrl,
@@ -220,6 +205,11 @@ export async function LinkMiddleware(req: NextRequest, ev: NextFetchEvent) {
});
}
+ // handle disabled links
+ if (disabledAt) {
+ return await handleNotFoundLink(req);
+ }
+
// if the link has expired
if (expiresAt && new Date(expiresAt) < new Date()) {
if (expiredUrl) {
diff --git a/apps/web/lib/middleware/utils/handle-not-found-link.ts b/apps/web/lib/middleware/utils/handle-not-found-link.ts
new file mode 100644
index 0000000000..680a8dd48c
--- /dev/null
+++ b/apps/web/lib/middleware/utils/handle-not-found-link.ts
@@ -0,0 +1,26 @@
+import { getDomainViaEdge } from "@/lib/planetscale/get-domain-via-edge";
+import { DUB_HEADERS } from "@dub/utils";
+import { NextRequest, NextResponse } from "next/server";
+import { parse } from "./parse";
+
+export const handleNotFoundLink = async (req: NextRequest) => {
+ const { domain } = parse(req);
+
+ // check if domain has notFoundUrl configured
+ const domainData = await getDomainViaEdge(domain);
+ if (domainData?.notFoundUrl) {
+ return NextResponse.redirect(domainData.notFoundUrl, {
+ headers: {
+ ...DUB_HEADERS,
+ "X-Robots-Tag": "googlebot: noindex",
+ // pass the Referer value to the not found URL
+ Referer: req.url,
+ },
+ status: 302,
+ });
+ } else {
+ return NextResponse.rewrite(new URL(`/${domain}/not-found`, req.url), {
+ headers: DUB_HEADERS,
+ });
+ }
+};
diff --git a/apps/web/lib/tinybird/record-link.ts b/apps/web/lib/tinybird/record-link.ts
index c0e9cdf01d..b6e284e589 100644
--- a/apps/web/lib/tinybird/record-link.ts
+++ b/apps/web/lib/tinybird/record-link.ts
@@ -44,20 +44,20 @@ export const dubLinksMetadataSchema = z.object({
.transform((v) => (v ? 1 : 0)),
});
-export const recordLinkTB = tb.buildIngestEndpoint({
+const recordLinkTB = tb.buildIngestEndpoint({
datasource: "dub_links_metadata",
event: dubLinksMetadataSchema,
wait: true,
});
// TODO: Remove after Tinybird migration
-export const recordLinkTBOld = tbOld.buildIngestEndpoint({
+const recordLinkTBOld = tbOld.buildIngestEndpoint({
datasource: "dub_links_metadata",
event: dubLinksMetadataSchema,
wait: true,
});
-export const transformLinkTB = (link: ExpandedLink) => {
+const transformLinkTB = (link: ExpandedLink) => {
const key = decodeKeyIfCaseSensitive({
domain: link.domain,
key: link.key,
@@ -68,12 +68,13 @@ export const transformLinkTB = (link: ExpandedLink) => {
domain: link.domain,
key,
url: link.url,
- tag_ids: link.tags?.map(({ tag }) => tag.id),
+ tag_ids: link.tags?.map(({ tag }) => tag.id) ?? [],
folder_id: link.folderId ?? "",
tenant_id: link.tenantId ?? "",
program_id: link.programId ?? "",
partner_id: link.partnerId ?? "",
partner_group_id: link.programEnrollment?.groupId ?? "",
+ partner_tag_ids: [],
workspace_id: link.projectId,
created_at: link.createdAt,
};
diff --git a/apps/web/lib/types.ts b/apps/web/lib/types.ts
index fa2164a9f4..b49fffb29f 100644
--- a/apps/web/lib/types.ts
+++ b/apps/web/lib/types.ts
@@ -163,6 +163,7 @@ export interface RedisLinkProps {
rewrite?: boolean;
expiresAt?: Date;
expiredUrl?: string;
+ disabledAt?: Date;
ios?: string;
android?: string;
geo?: object;
diff --git a/apps/web/lib/upstash/format-redis-link.ts b/apps/web/lib/upstash/format-redis-link.ts
index 62f4a8a702..784a312555 100644
--- a/apps/web/lib/upstash/format-redis-link.ts
+++ b/apps/web/lib/upstash/format-redis-link.ts
@@ -13,6 +13,7 @@ export function formatRedisLink(link: ExpandedLink): RedisLinkProps {
rewrite,
expiresAt,
expiredUrl,
+ disabledAt,
ios,
android,
geo,
@@ -41,6 +42,7 @@ export function formatRedisLink(link: ExpandedLink): RedisLinkProps {
}),
...(expiresAt && { expiresAt: new Date(expiresAt) }),
...(expiredUrl && { expiredUrl }),
+ ...(disabledAt && { disabledAt }),
...(ios && { ios }),
...(android && { android }),
...(geo && { geo: geo as object }),
diff --git a/apps/web/lib/webhook/sample-events/lead-created.json b/apps/web/lib/webhook/sample-events/lead-created.json
index 8d3450d032..9999eccedd 100644
--- a/apps/web/lib/webhook/sample-events/lead-created.json
+++ b/apps/web/lib/webhook/sample-events/lead-created.json
@@ -37,6 +37,7 @@
"archived": false,
"expiresAt": "1970-01-01T00:00:00.000Z",
"expiredUrl": null,
+ "disabledAt": null,
"password": null,
"proxy": false,
"title": "GitHub - dubinc/dub: Open-source link management infrastructure. Loved by modern marketing teams like Vercel, Raycast...",
diff --git a/apps/web/lib/webhook/sample-events/link-clicked.json b/apps/web/lib/webhook/sample-events/link-clicked.json
index b88bec2681..b80c3e2438 100644
--- a/apps/web/lib/webhook/sample-events/link-clicked.json
+++ b/apps/web/lib/webhook/sample-events/link-clicked.json
@@ -28,6 +28,7 @@
"archived": false,
"expiresAt": "1970-01-01T00:00:00.000Z",
"expiredUrl": null,
+ "disabledAt": null,
"password": null,
"proxy": false,
"title": "GitHub - dubinc/dub: Open-source link management infrastructure. Loved by modern marketing teams like Vercel, Raycast...",
diff --git a/apps/web/lib/webhook/sample-events/link-created.json b/apps/web/lib/webhook/sample-events/link-created.json
index b8ef3d55b2..f2ca251ef4 100644
--- a/apps/web/lib/webhook/sample-events/link-created.json
+++ b/apps/web/lib/webhook/sample-events/link-created.json
@@ -11,6 +11,7 @@
"archived": false,
"expiresAt": null,
"expiredUrl": null,
+ "disabledAt": null,
"password": null,
"proxy": false,
"title": null,
diff --git a/apps/web/lib/webhook/sample-events/link-deleted.json b/apps/web/lib/webhook/sample-events/link-deleted.json
index b8ef3d55b2..f2ca251ef4 100644
--- a/apps/web/lib/webhook/sample-events/link-deleted.json
+++ b/apps/web/lib/webhook/sample-events/link-deleted.json
@@ -11,6 +11,7 @@
"archived": false,
"expiresAt": null,
"expiredUrl": null,
+ "disabledAt": null,
"password": null,
"proxy": false,
"title": null,
diff --git a/apps/web/lib/webhook/sample-events/link-updated.json b/apps/web/lib/webhook/sample-events/link-updated.json
index b8ef3d55b2..f2ca251ef4 100644
--- a/apps/web/lib/webhook/sample-events/link-updated.json
+++ b/apps/web/lib/webhook/sample-events/link-updated.json
@@ -11,6 +11,7 @@
"archived": false,
"expiresAt": null,
"expiredUrl": null,
+ "disabledAt": null,
"password": null,
"proxy": false,
"title": null,
diff --git a/apps/web/lib/webhook/sample-events/sale-created.json b/apps/web/lib/webhook/sample-events/sale-created.json
index 68865dac87..5883d87148 100644
--- a/apps/web/lib/webhook/sample-events/sale-created.json
+++ b/apps/web/lib/webhook/sample-events/sale-created.json
@@ -37,6 +37,7 @@
"archived": false,
"expiresAt": "1970-01-01T00:00:00.000Z",
"expiredUrl": null,
+ "disabledAt": null,
"password": null,
"proxy": false,
"title": "GitHub - dubinc/dub: Open-source link management infrastructure. Loved by modern marketing teams like Vercel, Raycast...",
diff --git a/apps/web/lib/zod/schemas/links.ts b/apps/web/lib/zod/schemas/links.ts
index 6f2f13b61b..e5d63b4ad7 100644
--- a/apps/web/lib/zod/schemas/links.ts
+++ b/apps/web/lib/zod/schemas/links.ts
@@ -643,6 +643,12 @@ export const LinkSchema = z
.url()
.nullable()
.describe("The URL to redirect to when the short link has expired."),
+ disabledAt: z
+ .string()
+ .nullable()
+ .describe(
+ "The date and time when the short link was disabled. When a short link is disabled, it will redirect to its domain's not found URL, and its stats will be excluded from your overall stats.",
+ ),
password: z
.string()
.nullable()
@@ -883,8 +889,9 @@ export const linkEventSchema = LinkSchema.extend({
updatedAt: z.coerce.date(),
lastClicked: z.coerce.date(),
expiresAt: z.coerce.date(),
- testCompletedAt: z.coerce.date().nullable(),
- testStartedAt: z.coerce.date().nullable(),
+ disabledAt: z.coerce.date(),
+ testCompletedAt: z.coerce.date(),
+ testStartedAt: z.coerce.date(),
// userId can be null
userId: z.string().nullable(),
});
diff --git a/apps/web/scripts/migrations/backfill-banned-partner-links.ts b/apps/web/scripts/migrations/backfill-banned-partner-links.ts
index 04b3c042b5..ff23d0cf01 100644
--- a/apps/web/scripts/migrations/backfill-banned-partner-links.ts
+++ b/apps/web/scripts/migrations/backfill-banned-partner-links.ts
@@ -1,70 +1,50 @@
import { includeProgramEnrollment } from "@/lib/api/links/include-program-enrollment";
import { includeTags } from "@/lib/api/links/include-tags";
-import { recordLink } from "@/lib/tinybird";
import { prisma } from "@dub/prisma";
import "dotenv-flow/config";
-
-const LINKS_PER_BATCH = 1000;
+import { recordLink } from "../../lib/tinybird/record-link";
async function main() {
- let cursor: string | undefined = undefined;
-
- while (true) {
- // Find links for partners that were banned
- const links = await prisma.link.findMany({
- where: {
- programEnrollment: {
- status: "banned",
- },
- },
- include: {
- ...includeTags,
- ...includeProgramEnrollment,
- },
- orderBy: {
- id: "asc",
+ // Find links for partners that were banned
+ const links = await prisma.link.findMany({
+ where: {
+ programEnrollment: {
+ status: "banned",
},
- take: LINKS_PER_BATCH,
- ...(cursor
- ? {
- cursor: { id: cursor },
- skip: 1,
- }
- : {}),
- });
-
- console.log(`Found ${links.length} links to process.`);
-
- if (links.length === 0) {
- break;
- }
-
- cursor = links[links.length - 1].id;
+ },
+ include: {
+ ...includeTags,
+ ...includeProgramEnrollment,
+ },
+ orderBy: {
+ id: "asc",
+ },
+ skip: 1500,
+ take: 500,
+ });
+
+ if (links.length === 0) {
+ return;
+ }
- const res = await prisma.link.updateMany({
- where: {
- id: {
- in: links.map((link) => link.id),
- },
- },
- data: {
- disabledAt: new Date(),
+ console.log(`Found ${links.length} links to process.`);
+ const prismaRes = await prisma.link.updateMany({
+ where: {
+ id: {
+ in: links.map((link) => link.id),
},
- });
- console.log(`Updated ${res.count} links to be disabled.`);
-
- const { successful_rows, quarantined_rows } = await recordLink(links, {
- deleted: true,
- });
-
- if (successful_rows !== links.length) {
- console.log(`Failed to record ${links.length - successful_rows} links.`);
- }
-
- if (quarantined_rows !== 0) {
- console.log(`Quarantined ${quarantined_rows} links.`);
- }
- }
+ },
+ data: {
+ disabledAt: new Date(),
+ },
+ });
+ console.log(`Updated ${prismaRes.count} links to be disabled.`);
+
+ const tbRes = await recordLink(links, {
+ deleted: true,
+ });
+
+ console.log("Deleted links in Tinybird", tbRes);
}
main();
diff --git a/apps/web/tests/redirects/index.test.ts b/apps/web/tests/redirects/index.test.ts
index ddaae848c3..54b2606d1f 100644
--- a/apps/web/tests/redirects/index.test.ts
+++ b/apps/web/tests/redirects/index.test.ts
@@ -32,6 +32,14 @@ describe.runIf(env.CI)("Link Redirects", async () => {
expect(response.status).toBe(302);
});
+ test("disabled link", async () => {
+ const response = await fetch(`${h.baseUrl}/disabled`, fetchOptions);
+
+ expect(response.headers.get("location")).toBe("https://dub.co/");
+ expect(response.headers.get("x-powered-by")).toBe(poweredBy);
+ expect(response.status).toBe(302);
+ });
+
test("with slash", async () => {
const response = await fetch(`${h.baseUrl}/checkly/check`, fetchOptions);
diff --git a/apps/web/tests/utils/schema.ts b/apps/web/tests/utils/schema.ts
index 3ca5188ddb..2db73838d3 100644
--- a/apps/web/tests/utils/schema.ts
+++ b/apps/web/tests/utils/schema.ts
@@ -21,6 +21,7 @@ export const expectedLink: Partial<Link> & {
trackConversion: false,
archived: false,
expiresAt: null,
+ disabledAt: null,
password: null,
proxy: false,
title: null,
diff --git a/apps/web/ui/domains/domain-card.tsx b/apps/web/ui/domains/domain-card.tsx
index 8c583b695e..ac57f6e8ff 100644
--- a/apps/web/ui/domains/domain-card.tsx
+++ b/apps/web/ui/domains/domain-card.tsx
@@ -11,7 +11,6 @@ import {
Button,
CircleCheck,
Copy,
- NumberTooltip,
Popover,
Refresh2,
StatusBadge,
@@ -36,6 +35,7 @@ import {
fetcher,
formatDate,
nFormatter,
+ timeAgo,
} from "@dub/utils";
import { isPast } from "date-fns";
import { Archive, ChevronDown, FolderInput, QrCode } from "lucide-react";
@@ -184,7 +184,22 @@ export default function DomainCard({ props }: { props: DomainProps }) {
{/* Clicks */}
<div className="hidden md:flex">
- <NumberTooltip value={props.link?.clicks || 0}>
+ <Tooltip
+ content={
+ <div className="block max-w-xs px-4 py-2 text-center text-sm text-neutral-700">
+ <p className="text-sm font-semibold text-neutral-700">
+ {nFormatter(props.link?.clicks || 0, { full: true })}{" "}
+ clicks
+ </p>
+ {props.link?.lastClicked && (
+ <p className="mt-1 text-xs text-neutral-500">
+ Last clicked{" "}
+ {timeAgo(props.link?.lastClicked, { withAgo: true })}
+ </p>
+ )}
+ </div>
+ }
+ >
<Link
href={`/${slug}/analytics?domain=${domain}&key=_root`}
className="flex items-center space-x-1 whitespace-nowrap rounded-md border border-neutral-200 bg-neutral-50 px-3 py-1 transition-colors hover:bg-neutral-100"
@@ -195,7 +210,7 @@ export default function DomainCard({ props }: { props: DomainProps }) {
<span className="ml-1 hidden sm:inline-block">clicks</span>
</p>
</Link>
- </NumberTooltip>
+ </Tooltip>
</div>
{/* Status */}
diff --git a/apps/web/ui/links/disabled-link-tooltip.tsx b/apps/web/ui/links/disabled-link-tooltip.tsx
new file mode 100644
index 0000000000..6525bbbec5
--- /dev/null
+++ b/apps/web/ui/links/disabled-link-tooltip.tsx
@@ -0,0 +1,33 @@
+import { StatusBadge, Tooltip } from "@dub/ui";
+
+export const DisabledLinkTooltip = () => {
+ return (
+ <Tooltip
+ content={
+ <div className="max-w-xs px-4 py-2 text-center text-sm text-neutral-700">
+ This link is disabled. It will redirect to its{" "}
+ <a
+ href="https://dub.co/help/article/setting-not-found-url"
+ target="_blank"
+ className="cursor-alias underline decoration-dotted underline-offset-2"
+ >
+ domain's not found URL
+ </a>
+ , and its stats will be excluded from{" "}
+ <a
+ href="https://dub.co/help/article/dub-analytics"
+ target="_blank"
+ className="cursor-alias underline decoration-dotted underline-offset-2"
+ >
+ your overall stats
+ </a>
+ .
+ </div>
+ }
+ >
+ <StatusBadge variant="neutral" size="sm" icon={null}>
+ Disabled
+ </StatusBadge>
+ </Tooltip>
+ );
+};
diff --git a/apps/web/ui/links/link-builder/link-partner-details.tsx b/apps/web/ui/links/link-builder/link-partner-details.tsx
index 2701985a01..f5e0a56c08 100644
--- a/apps/web/ui/links/link-builder/link-partner-details.tsx
+++ b/apps/web/ui/links/link-builder/link-partner-details.tsx
@@ -1,5 +1,6 @@
import useWorkspace from "@/lib/swr/use-workspace";
import { EnrolledPartnerProps, LinkProps } from "@/lib/types";
+import { PartnerStatusBadgeWithTooltip } from "@/ui/partners/partner-status-badge-with-tooltip";
import { ArrowUpRight } from "@dub/ui/icons";
import { currencyFormatter, OG_AVATAR_URL } from "@dub/utils";
import Link from "next/link";
@@ -32,9 +33,12 @@ export function LinkPartnerDetails({
)}
<div className="min-w-0">
{partner ? (
- <span className="block truncate text-xs font-semibold leading-tight text-neutral-900">
- {partner.name}
- </span>
+ <div className="flex items-center gap-2">
+ <span className="block truncate text-xs font-semibold leading-tight text-neutral-900">
+ {partner.name}
+ </span>
+ <PartnerStatusBadgeWithTooltip partner={partner} size="sm" />
+ </div>
) : (
<div className="h-3 w-24 animate-pulse rounded bg-neutral-200" />
)}
diff --git a/apps/web/ui/links/link-title-column.tsx b/apps/web/ui/links/link-title-column.tsx
index 21c672b64f..dee2ae97ce 100644
--- a/apps/web/ui/links/link-title-column.tsx
+++ b/apps/web/ui/links/link-title-column.tsx
@@ -54,6 +54,7 @@ import {
import { FolderIcon } from "../folders/folder-icon";
import { useLinkBuilder } from "../modals/link-builder";
import { CommentsBadge } from "./comments-badge";
+import { DisabledLinkTooltip } from "./disabled-link-tooltip";
import { useLinkSelection } from "./link-selection-provider";
import { ResponseLink } from "./links-container";
import { LinksDisplayContext } from "./links-display-provider";
@@ -141,6 +142,7 @@ export function LinkTitleColumn({ link }: { link: ResponseLink }) {
</a>
</UnverifiedTooltip>
)}
+ {link.disabledAt && <DisabledLinkTooltip />}
<CopyButton
value={linkConstructor({
domain,
diff --git a/apps/web/ui/links/short-link-input.tsx b/apps/web/ui/links/short-link-input.tsx
index 4cf87b6c73..2595175024 100644
--- a/apps/web/ui/links/short-link-input.tsx
+++ b/apps/web/ui/links/short-link-input.tsx
@@ -44,12 +44,13 @@ import { useDebounce } from "use-debounce";
import { FreeDotLinkBanner } from "../domains/free-dot-link-banner";
import { AlertCircleFill, Random } from "../shared/icons";
import { UpgradeRequiredToast } from "../shared/upgrade-required-toast";
+import { DisabledLinkTooltip } from "./disabled-link-tooltip";
import { useAvailableDomains } from "./use-available-domains";
type ShortLinkInputProps = {
domain?: string;
_key?: string;
- existingLinkProps?: Pick<LinkProps, "key">;
+ existingLinkProps?: Pick<LinkProps, "key" | "disabledAt">;
error?: string;
onChange: (data: { domain?: string; key?: string }) => void;
data: Pick<LinkProps, "url" | "title" | "description">;
@@ -205,9 +206,10 @@ export const ShortLinkInput = forwardRef<HTMLInputElement, ShortLinkInputProps>(
<div className="flex items-center justify-between">
<label
htmlFor={inputId}
- className="block text-sm font-medium text-neutral-700"
+ className="flex items-center gap-2 text-sm font-medium text-neutral-700"
>
Short Link
+ {existingLinkProps?.disabledAt && <DisabledLinkTooltip />}
</label>
{lockKey ? (
<button
diff --git a/apps/web/ui/partners/partner-info-cards.tsx b/apps/web/ui/partners/partner-info-cards.tsx
index fd5683df28..c354b1d63a 100644
--- a/apps/web/ui/partners/partner-info-cards.tsx
+++ b/apps/web/ui/partners/partner-info-cards.tsx
@@ -13,7 +13,6 @@ import {
CopyButton,
Heart,
OfficeBuilding,
- StatusBadge,
Tooltip,
Trophy,
} from "@dub/ui";
@@ -30,7 +29,7 @@ import useSWR from "swr";
import { ConversionScoreIcon } from "./conversion-score-icon";
import { PartnerInfoGroup } from "./partner-info-group";
import { ConversionScoreTooltip } from "./partner-network/conversion-score-tooltip";
-import { PartnerStatusBadges } from "./partner-status-badges";
+import { PartnerStatusBadgeWithTooltip } from "./partner-status-badge-with-tooltip";
import { ProgramRewardList } from "./program-reward-list";
type PartnerInfoCardsProps = {
@@ -149,11 +148,6 @@ export function PartnerInfoCards({
]
: [];
- const badge =
- isEnrolled && partner && !hideStatuses.includes(partner.status)
- ? PartnerStatusBadges[partner.status]
- : null;
-
return (
<div className="flex flex-col gap-4">
<div className="border-border-subtle flex flex-col rounded-xl border p-4">
@@ -181,10 +175,8 @@ export function PartnerInfoCards({
)}
</div>
- {badge && (
- <StatusBadge icon={null} variant={badge.variant}>
- {badge.label}
- </StatusBadge>
+ {isEnrolled && partner && !hideStatuses.includes(partner.status) && (
+ <PartnerStatusBadgeWithTooltip partner={partner} />
)}
</div>
<div className="mt-4">
diff --git a/apps/web/ui/partners/partner-info-section.tsx b/apps/web/ui/partners/partner-info-section.tsx
index fb7eff346b..ca86c4061e 100644
--- a/apps/web/ui/partners/partner-info-section.tsx
+++ b/apps/web/ui/partners/partner-info-section.tsx
@@ -1,14 +1,8 @@
import { EnrolledPartnerProps } from "@/lib/types";
-import { BAN_PARTNER_REASONS } from "@/lib/zod/schemas/partners";
-import {
- CopyButton,
- DynamicTooltipWrapper,
- StatusBadge,
- Tooltip,
-} from "@dub/ui";
-import { COUNTRIES, OG_AVATAR_URL, formatDate } from "@dub/utils";
+import { CopyButton, Tooltip } from "@dub/ui";
+import { COUNTRIES, OG_AVATAR_URL } from "@dub/utils";
import { PropsWithChildren } from "react";
-import { PartnerStatusBadges } from "./partner-status-badges";
+import { PartnerStatusBadgeWithTooltip } from "./partner-status-badge-with-tooltip";
export function PartnerInfoSection({
partner,
@@ -27,8 +21,6 @@ export function PartnerInfoSection({
| "country"
>;
}>) {
- const badge = showPartnerStatus ? PartnerStatusBadges[partner.status] : null;
-
return (
<div className="flex items-start justify-between gap-6">
<div>
@@ -57,51 +49,8 @@ export function PartnerInfoSection({
>
{partner.name}
</span>
- {badge && (
- <DynamicTooltipWrapper
- {...(partner.status === "banned" &&
- partner.bannedAt &&
- partner.bannedReason
- ? {
- tooltipProps: {
- content: (
- <div className="w-60 p-4">
- <div className="flex items-center gap-2">
- <div className="size-2 rounded-full bg-red-500" />
- <div className="text-sm font-medium text-neutral-700">
- Banned
- </div>
- </div>
- <div className="mt-2 flex flex-col gap-1">
- <div className="flex items-center justify-between">
- <span className="text-xs text-neutral-500">
- Date
- </span>
- <span className="text-xs font-medium text-neutral-700">
- {formatDate(partner.bannedAt)}
- </span>
- </div>
- <div className="flex items-center justify-between">
- <span className="text-xs text-neutral-500">
- Reason
- </span>
- <span className="text-xs font-medium text-neutral-700">
- {BAN_PARTNER_REASONS[partner.bannedReason]}
- </span>
- </div>
- </div>
- </div>
- ),
- align: "start",
- contentClassName: "text-left w-60",
- },
- }
- : {})}
- >
- <StatusBadge icon={null} variant={badge.variant}>
- {badge.label}
- </StatusBadge>
- </DynamicTooltipWrapper>
+ {showPartnerStatus && (
+ <PartnerStatusBadgeWithTooltip partner={partner} />
)}
</div>
{partner.email && (
diff --git a/apps/web/ui/partners/partner-status-badge-with-tooltip.tsx b/apps/web/ui/partners/partner-status-badge-with-tooltip.tsx
new file mode 100644
index 0000000000..464f64a68e
--- /dev/null
+++ b/apps/web/ui/partners/partner-status-badge-with-tooltip.tsx
@@ -0,0 +1,57 @@
+import { EnrolledPartnerProps } from "@/lib/types";
+import { BAN_PARTNER_REASONS } from "@/lib/zod/schemas/partners";
+import { DynamicTooltipWrapper, StatusBadge } from "@dub/ui";
+import { formatDate } from "@dub/utils";
+import { PartnerStatusBadges } from "./partner-status-badges";
+
+export const PartnerStatusBadgeWithTooltip = ({
+ partner,
+ size = "md",
+}: {
+ partner: Pick<EnrolledPartnerProps, "status" | "bannedAt" | "bannedReason">;
+ size?: "sm" | "md";
+}) => {
+ const badge = PartnerStatusBadges[partner.status];
+ return (
+ <DynamicTooltipWrapper
+ {...(partner.status === "banned" &&
+ partner.bannedAt &&
+ partner.bannedReason
+ ? {
+ tooltipProps: {
+ content: (
+ <div className="w-60 p-4">
+ <div className="flex items-center gap-2">
+ <div className="size-2 rounded-full bg-red-500" />
+ <div className="text-sm font-medium text-neutral-700">
+ Banned
+ </div>
+ </div>
+ <div className="mt-2 flex flex-col gap-1">
+ <div className="flex items-center justify-between">
+ <span className="text-xs text-neutral-500">Date</span>
+ <span className="text-xs font-medium text-neutral-700">
+ {formatDate(partner.bannedAt)}
+ </span>
+ </div>
+ <div className="flex items-center justify-between">
+ <span className="text-xs text-neutral-500">Reason</span>
+ <span className="text-xs font-medium text-neutral-700">
+ {BAN_PARTNER_REASONS[partner.bannedReason]}
+ </span>
+ </div>
+ </div>
+ </div>
+ ),
+ align: "start",
+ contentClassName: "text-left w-60",
+ },
+ }
+ : {})}
+ >
+ <StatusBadge icon={null} variant={badge.variant} size={size}>
+ {badge.label}
+ </StatusBadge>
+ </DynamicTooltipWrapper>
+ );
+};
diff --git a/packages/ui/src/status-badge.tsx b/packages/ui/src/status-badge.tsx
index da27abcb82..e81d536c11 100644
--- a/packages/ui/src/status-badge.tsx
+++ b/packages/ui/src/status-badge.tsx
@@ -22,6 +22,10 @@ const statusBadgeVariants = cva(
warning: "bg-yellow-500/[.15] text-yellow-600",
error: "bg-red-500/[.15] text-red-600",
},
+ size: {
+ sm: "px-1.5 py-0.5",
+ md: "px-2 py-1",
+ },
},
defaultVariants: {
variant: "neutral",
@@ -48,6 +52,7 @@ interface BadgeProps
function StatusBadge({
className,
variant,
+ size,
icon,
tooltip,
onClick,
@@ -61,7 +66,7 @@ function StatusBadge({
<DynamicTooltipWrapper tooltipProps={{ content: tooltip }}>
<span
className={cn(
- statusBadgeVariants({ variant }),
+ statusBadgeVariants({ variant, size }),
tooltip && "cursor-help",
onClick &&
"cursor-pointer select-none transition-[filter] duration-150 hover:brightness-75 hover:saturate-[1.25]",