The modern link attribution platform. Loved by world-class engineering teams at Twilio, Zillow, Jobber, Vercel, Raycast, and more.
TypeScript clickhousemysqlnextjsopen-sourceplanetscaleprismatailwindcsstinybirdtypescriptupstashvercel
Show partners sharing verified platforms on partner applications (#4017)
Kiran K6f902f4c60e0
diff --git a/apps/web/app/(ee)/admin.dub.co/(dashboard)/partners/network/page.tsx b/apps/web/app/(ee)/admin.dub.co/(dashboard)/partners/network/page.tsxindex c49e92e2a0..f9d4a5d0a7 100644--- a/apps/web/app/(ee)/admin.dub.co/(dashboard)/partners/network/page.tsx+++ b/apps/web/app/(ee)/admin.dub.co/(dashboard)/partners/network/page.tsx@@ -20,10 +20,10 @@ import {import { CircleDotted, FlagWavy } from "@dub/ui/icons";import { cn, COUNTRIES, fetcher, formatDate } from "@dub/utils";import { Row } from "@tanstack/react-table";-import { NetworkPartnerApplicationSheet } from "app/(ee)/admin.dub.co/(dashboard)/partners/network/network-partner-application-sheet";import { useEffect, useMemo, useState } from "react";import { toast } from "sonner";import useSWR from "swr";+import { NetworkPartnerApplicationSheet } from "./network-partner-application-sheet";const SOCIAL_FIELDS = [{ id: "website", label: "Website" },diff --git a/apps/web/app/(ee)/api/admin/partners/[partnerId]/shared-platforms/route.ts b/apps/web/app/(ee)/api/admin/partners/[partnerId]/shared-platforms/route.tsnew file mode 100644index 0000000000..65f3c9958d--- /dev/null+++ b/apps/web/app/(ee)/api/admin/partners/[partnerId]/shared-platforms/route.ts@@ -0,0 +1,121 @@+import { withAdmin } from "@/lib/auth";+import { partnerSharedPlatformSchema } from "@/lib/zod/schemas/partners";+import { prisma } from "@dub/prisma";+import { Prisma } from "@dub/prisma/client";+import { getDomainWithoutWWW } from "@dub/utils";+import { NextResponse } from "next/server";+import * as z from "zod/v4";++// GET /api/admin/partners/:partnerId/shared-platforms – other partners in the network with the same verified platform identifiers+export const GET = withAdmin(async ({ params }) => {+ const { partnerId } = params;++ const partner = await prisma.partner.findUnique({+ where: { id: partnerId },+ include: {+ platforms: true,+ },+ });++ if (!partner) {+ return new Response("Partner not found.", { status: 404 });+ }+ const verifiedPlatforms = partner.platforms.filter(+ (platform) => platform.verifiedAt !== null,+ );++ // a partner has at most one platform per type, so there is at most one website+ const websitePlatform = verifiedPlatforms.find(+ (platform) => platform.type === "website",+ );++ const websiteDomain = websitePlatform+ ? getDomainWithoutWWW(websitePlatform.identifier) ?? null+ : null;++ const matchConditions: Prisma.PartnerPlatformWhereInput[] = [];++ for (const platform of verifiedPlatforms) {+ if (platform.type === "website") {+ // website identifiers are full URLs with inconsistent normalization,+ // so match on the domain instead of the exact identifier+ if (websiteDomain) {+ matchConditions.push({+ type: platform.type,+ identifier: {+ contains: websiteDomain,+ },+ });+ }+ continue;+ }++ matchConditions.push({+ type: platform.type,+ identifier: platform.identifier,+ });+ }++ if (matchConditions.length === 0) {+ return NextResponse.json([]);+ }++ const sharedPlatformMatches = await prisma.partnerPlatform.findMany({+ where: {+ partnerId: {+ not: partner.id,+ },+ verifiedAt: {+ not: null,+ },+ OR: matchConditions,+ },+ include: {+ partner: {+ select: {+ id: true,+ name: true,+ email: true,+ image: true,+ },+ },+ },+ orderBy: {+ createdAt: "asc",+ },+ take: 10,+ });++ const sharedPlatforms = verifiedPlatforms+ .map((platform) => {+ let platformMatches = sharedPlatformMatches.filter(+ (match) => match.type === platform.type,+ );++ // "contains" matches on the domain need exact verification+ // (e.g. contains "example.com" would also match "notexample.com")+ if (platform.type === "website") {+ platformMatches = platformMatches.filter(+ (match) =>+ websiteDomain !== null &&+ getDomainWithoutWWW(match.identifier) === websiteDomain,+ );+ }++ return {+ type: platform.type,+ identifier: platform.identifier,+ partners: platformMatches.map((match) => ({+ id: match.partner.id,+ name: match.partner.name,+ email: match.partner.email,+ image: match.partner.image,+ })),+ };+ })+ .filter((platform) => platform.partners.length > 0);++ return NextResponse.json(+ z.array(partnerSharedPlatformSchema).parse(sharedPlatforms),+ );+});diff --git a/apps/web/lib/types.ts b/apps/web/lib/types.tsindex 6cbb675b58..ea80069ed9 100644--- a/apps/web/lib/types.ts+++ b/apps/web/lib/types.ts@@ -146,6 +146,7 @@ import {partnerPlatformSchema,PartnerRewindSchema,PartnerSchema,+ partnerSharedPlatformSchema,WebhookPartnerSchema,} from "./zod/schemas/partners";import {@@ -522,6 +523,10 @@ export type CustomerProps = z.infer<typeof CustomerSchema>;export type PartnerPlatformProps = z.infer<typeof partnerPlatformSchema>;+export type PartnerSharedPlatformProps = z.infer<+ typeof partnerSharedPlatformSchema+>;+export type PartnerProps = z.infer<typeof PartnerSchema> & {role: PartnerRole;userId: string;diff --git a/apps/web/lib/zod/schemas/partners.ts b/apps/web/lib/zod/schemas/partners.tsindex c86ea6c652..42da11be64 100644--- a/apps/web/lib/zod/schemas/partners.ts+++ b/apps/web/lib/zod/schemas/partners.ts@@ -1050,3 +1050,16 @@ export const partnerCrossProgramSummarySchema = z.object({activePrograms: z.number(),bannedPrograms: z.number(),});++export const partnerSharedPlatformSchema = z.object({+ type: z.enum(PlatformType),+ identifier: z.string(),+ partners: z.array(+ z.object({+ id: z.string(),+ name: z.string(),+ email: z.email().nullable(),+ image: z.string().nullable(),+ }),+ ),+});diff --git a/apps/web/ui/partners/partner-platform-shared-partners.tsx b/apps/web/ui/partners/partner-platform-shared-partners.tsxnew file mode 100644index 0000000000..bf8328545d--- /dev/null+++ b/apps/web/ui/partners/partner-platform-shared-partners.tsx@@ -0,0 +1,74 @@+import { PartnerSharedPlatformProps } from "@/lib/types";+import { Duplicate } from "@dub/ui/icons";+import { cn, pluralize } from "@dub/utils";+import { ChevronDown } from "lucide-react";+import { useId, useState } from "react";+import { PartnerAvatar } from "./partner-avatar";++export function PartnerPlatformSharedPartners({+ sharedPartners,+}: {+ sharedPartners: PartnerSharedPlatformProps["partners"];+}) {+ const [isExpanded, setIsExpanded] = useState(false);+ const panelId = useId();++ return (+ <div className="border-subtle mx-2 rounded-b-lg border border-t-0 bg-white px-3">+ <button+ type="button"+ onClick={() => setIsExpanded((prev) => !prev)}+ aria-expanded={isExpanded}+ aria-controls={panelId}+ className="flex h-9 w-full items-center justify-between gap-2"+ >+ <div className="flex min-w-0 items-center gap-2">+ <Duplicate className="size-3.5 shrink-0 text-neutral-500" />+ <span className="truncate text-xs font-medium text-neutral-600">+ Added by {sharedPartners.length} other{" "}+ {pluralize("partner", sharedPartners.length)}+ </span>+ </div>+ <ChevronDown+ className={cn(+ "size-3.5 shrink-0 text-neutral-400 transition-transform duration-200",+ isExpanded && "rotate-180",+ )}+ />+ </button>++ {isExpanded && (+ <div id={panelId} className="flex flex-col gap-2.5 pb-3 pt-1">+ {sharedPartners.map((partner) => (+ <SharedPartner key={partner.id} partner={partner} />+ ))}+ </div>+ )}+ </div>+ );+}++function SharedPartner({+ partner,+}: {+ partner: PartnerSharedPlatformProps["partners"][number];+}) {+ return (+ <div className="flex items-center justify-between gap-3">+ <div className="flex min-w-0 items-center gap-2">+ <PartnerAvatar partner={partner} className="size-3.5" />+ <span className="min-w-0 truncate text-xs font-medium text-neutral-700">+ {partner.name}+ </span>+ </div>+ <a+ href={`/partners/network?partnerId=${partner.id}&search=${encodeURIComponent(partner.email ?? "")}`}+ target="_blank"+ rel="noopener noreferrer"+ className="text-content-subtle hover:text-content-default shrink-0 text-xs font-medium"+ >+ View+ </a>+ </div>+ );+}diff --git a/apps/web/ui/partners/partner-platform-summary.tsx b/apps/web/ui/partners/partner-platform-summary.tsxindex ad9e73b4c2..4b2e983e93 100644--- a/apps/web/ui/partners/partner-platform-summary.tsx+++ b/apps/web/ui/partners/partner-platform-summary.tsx@@ -1,11 +1,12 @@import { PARTNER_PLATFORM_FIELDS } from "@/lib/partners/partner-platforms";-import { PartnerPlatformProps } from "@/lib/types";-import { useCurrentSubdomain } from "@dub/ui";-import { cn } from "@dub/utils";+import { PartnerPlatformProps, PartnerSharedPlatformProps } from "@/lib/types";+import { AnimatedSizeContainer, useCurrentSubdomain } from "@dub/ui";+import { cn, fetcher } from "@dub/utils";import { Fragment, useMemo, useState } from "react";import { toast } from "sonner";-import { useSWRConfig } from "swr";+import useSWR, { useSWRConfig } from "swr";import { PartnerPlatformCard } from "./partner-platform-card";+import { PartnerPlatformSharedPartners } from "./partner-platform-shared-partners";export function PartnerPlatformSummary({platforms,@@ -18,6 +19,14 @@ export function PartnerPlatformSummary({}) {const { subdomain } = useCurrentSubdomain();const { mutate } = useSWRConfig();++ const { data: sharedPlatforms } = useSWR<PartnerSharedPlatformProps[]>(+ subdomain === "admin" && partnerId+ ? `/api/admin/partners/${partnerId}/shared-platforms`+ : null,+ fetcher,+ );+const [verifyingPlatforms, setVerifyingPlatforms] = useState<Partial<Record<PartnerPlatformProps["type"], boolean>>>({});@@ -121,6 +130,10 @@ export function PartnerPlatformSummary({info,identifier,}) => {+ const sharedPlatform = sharedPlatforms?.find(+ (platform) => platform.type === type,+ );+return (<Fragment key={label}><div>@@ -136,6 +149,14 @@ export function PartnerPlatformSummary({isVerifying: Boolean(verifyingPlatforms[type]),})}/>++ <AnimatedSizeContainer height>+ {sharedPlatform && (+ <PartnerPlatformSharedPartners+ sharedPartners={sharedPlatform.partners}+ />+ )}+ </AnimatedSizeContainer></div></Fragment>);diff --git a/packages/prisma/schema/platform.prisma b/packages/prisma/schema/platform.prismaindex 7903a43a91..8ffde40a82 100644--- a/packages/prisma/schema/platform.prisma+++ b/packages/prisma/schema/platform.prisma@@ -26,5 +26,5 @@ model PartnerPlatform {partner Partner @relation(fields: [partnerId], references: [id], onDelete: Cascade)@@unique([partnerId, type])- @@index(type)+ @@index([type, identifier])}