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 admin verify UX

Steven Teyb0b2e2907991
diff --git a/apps/web/scripts/migrations/backfill-partner-usernames.ts b/apps/web/scripts/migrations/backfill-partner-usernames.ts
index aac9628f87..9fae1e705c 100644
--- a/apps/web/scripts/migrations/backfill-partner-usernames.ts
+++ b/apps/web/scripts/migrations/backfill-partner-usernames.ts
@@ -33,13 +33,17 @@ async function main() {
const seenInBatch = new Set<string>();
for (const partner of partners) {
- let username = partner.name
- ? slugify(partner.name)
- : partner.email
- ? `${slugify(partner.email.split("@")[0])}`
- : null;
+ let username =
+ partner.name && slugify(partner.name)
+ ? slugify(partner.name)
+ : partner.email
+ ? `${slugify(partner.email.split("@")[0])}`
+ : null;
if (!username) {
+ console.log(
+ `No username for ${partner.id}: ${partner.name} ${partner.email}`,
+ );
continue;
}
@@ -72,6 +76,7 @@ async function main() {
entry.username = `${entry.username.slice(0, -5)}-${nanoid(4).toLowerCase()}`;
}
}
+ console.table(usernameEntries);
await Promise.allSettled(
usernameEntries.map(({ id, username }) =>
diff --git a/apps/web/ui/partners/partner-about.tsx b/apps/web/ui/partners/partner-about.tsx
index 68cd277876..2af8482a71 100644
--- a/apps/web/ui/partners/partner-about.tsx
+++ b/apps/web/ui/partners/partner-about.tsx
@@ -16,6 +16,7 @@ export function PartnerAbout({
}: {
partner?: Pick<
EnrolledPartnerExtendedProps,
+ | "id"
| "description"
| "industryInterests"
| "salesChannels"
@@ -46,7 +47,7 @@ export function PartnerAbout({
</h3>
<PartnerPlatformSummary
platforms={partner.platforms}
- showLabels={false}
+ partnerId={partner.id}
className="gap-y-2"
/>
</div>
diff --git a/apps/web/ui/partners/partner-platform-card.tsx b/apps/web/ui/partners/partner-platform-card.tsx
index df80e244ae..67bda8572b 100644
--- a/apps/web/ui/partners/partner-platform-card.tsx
+++ b/apps/web/ui/partners/partner-platform-card.tsx
@@ -7,7 +7,7 @@ import {
Trash,
} from "@dub/ui";
import { cn } from "@dub/utils";
-import { PropsWithChildren } from "react";
+import { MouseEventHandler, PropsWithChildren } from "react";
export function PartnerPlatformCard({
icon: Icon,
@@ -17,6 +17,8 @@ export function PartnerPlatformCard({
info,
href,
onRemove,
+ onVerify,
+ isVerifying = false,
}: {
icon: Icon;
prefix?: string;
@@ -25,7 +27,15 @@ export function PartnerPlatformCard({
info?: string[];
href?: string;
onRemove?: () => void;
+ onVerify?: () => void;
+ isVerifying?: boolean;
}) {
+ const onVerifyClick: MouseEventHandler<HTMLButtonElement> = (e) => {
+ e.preventDefault();
+ e.stopPropagation();
+ onVerify?.();
+ };
+
return (
<Container
href={href}
@@ -59,19 +69,25 @@ export function PartnerPlatformCard({
)}
</div>
</div>
- {href ? (
- <ArrowUpRight className="text-content-subtle mr-1 size-4 -translate-x-0.5 translate-y-0.5 opacity-0 transition-[opacity,transform] group-hover:translate-x-0 group-hover:translate-y-0 group-hover:opacity-100" />
+ {onVerify && !verified ? (
+ <Button
+ variant="outline"
+ text="Verify"
+ className="h-8 w-fit px-2.5 text-xs"
+ loading={isVerifying}
+ onClick={onVerifyClick}
+ />
+ ) : onRemove ? (
+ <div className="flex items-center gap-2">
+ <Button
+ variant="outline"
+ icon={<Trash className="size-4" />}
+ className="text-content-subtle hover:text-content-default size-8 p-0"
+ onClick={onRemove}
+ />
+ </div>
) : (
- onRemove && (
- <div className="flex items-center gap-2">
- <Button
- variant="outline"
- icon={<Trash className="size-4" />}
- className="text-content-subtle hover:text-content-default size-8 p-0"
- onClick={onRemove}
- />
- </div>
- )
+ <ArrowUpRight className="text-content-subtle mr-1 size-4 -translate-x-0.5 translate-y-0.5 opacity-0 transition-[opacity,transform] group-hover:translate-x-0 group-hover:translate-y-0 group-hover:opacity-100" />
)}
</Container>
);
diff --git a/apps/web/ui/partners/partner-platform-summary.tsx b/apps/web/ui/partners/partner-platform-summary.tsx
index af0d09a86d..da83b347cb 100644
--- a/apps/web/ui/partners/partner-platform-summary.tsx
+++ b/apps/web/ui/partners/partner-platform-summary.tsx
@@ -1,66 +1,146 @@
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 { Fragment } from "react";
+import { Fragment, useMemo, useState } from "react";
+import { toast } from "sonner";
+import { useSWRConfig } from "swr";
import { PartnerPlatformCard } from "./partner-platform-card";
export function PartnerPlatformSummary({
platforms,
- showLabels = true,
+ partnerId,
className,
- emptyClassName,
}: {
platforms: PartnerPlatformProps[] | undefined;
- showLabels?: boolean;
+ partnerId: string;
className?: string;
- emptyClassName?: string;
}) {
+ const { subdomain } = useCurrentSubdomain();
+ const { mutate } = useSWRConfig();
+ const [verifyingPlatforms, setVerifyingPlatforms] = useState<
+ Partial<Record<PartnerPlatformProps["type"], boolean>>
+ >({});
+
if (!platforms || platforms.length === 0) {
return (
- <div
- className={cn(
- "text-sm italic text-neutral-400",
- className,
- emptyClassName,
- )}
- >
+ <div className={cn("text-sm italic text-neutral-400", className)}>
No platforms connected
</div>
);
}
- const fieldData = PARTNER_PLATFORM_FIELDS.map((field) => ({
- label: field.label,
- icon: field.icon,
- ...field.data(platforms),
- })).filter((field) => field.value && field.href);
+ const fieldByType = useMemo(
+ () =>
+ ({
+ website: PARTNER_PLATFORM_FIELDS[0],
+ youtube: PARTNER_PLATFORM_FIELDS[1],
+ twitter: PARTNER_PLATFORM_FIELDS[2],
+ linkedin: PARTNER_PLATFORM_FIELDS[3],
+ instagram: PARTNER_PLATFORM_FIELDS[4],
+ tiktok: PARTNER_PLATFORM_FIELDS[5],
+ }) as Record<
+ PartnerPlatformProps["type"],
+ (typeof PARTNER_PLATFORM_FIELDS)[number]
+ >,
+ [],
+ );
+
+ const fieldData = (Object.keys(fieldByType) as PartnerPlatformProps["type"][])
+ .map((type) => {
+ const field = fieldByType[type];
+ const platform = platforms.find((p) => p.type === type);
+ const data = field.data(platforms);
+ return {
+ type,
+ label: field.label,
+ icon: field.icon,
+ identifier: platform?.identifier ?? null,
+ ...data,
+ };
+ })
+ .filter((field) => field.value && field.href && field.identifier);
+
+ const handleVerifyPlatform = async (
+ platform: PartnerPlatformProps["type"],
+ identifier: string,
+ label: string,
+ ) => {
+ if (subdomain !== "admin") {
+ return;
+ }
+
+ setVerifyingPlatforms((prev) => ({ ...prev, [platform]: true }));
+
+ try {
+ const response = await fetch(
+ `/api/admin/partners/${partnerId}/platforms`,
+ {
+ method: "POST",
+ headers: { "Content-Type": "application/json" },
+ body: JSON.stringify({ platform, identifier }),
+ },
+ );
+
+ if (!response.ok) {
+ throw new Error(
+ (await response.text()) || "Failed to verify platform.",
+ );
+ }
+
+ await mutate(
+ (key) =>
+ typeof key === "string" &&
+ key.startsWith("/api/admin/partners/network"),
+ );
+ toast.success(`${label} verified manually.`);
+ } catch (error) {
+ toast.error(
+ error instanceof Error ? error.message : "Failed to verify platform.",
+ );
+ } finally {
+ setVerifyingPlatforms((prev) => ({ ...prev, [platform]: false }));
+ }
+ };
return (
<div
className={cn(
- "grid items-center gap-x-4 gap-y-5 text-sm md:gap-x-16",
- showLabels ? "grid-cols-[max-content_minmax(0,1fr)]" : "grid-cols-1",
+ "grid grid-cols-1 items-center gap-x-4 gap-y-5 text-sm md:gap-x-16",
className,
)}
>
- {fieldData.map(({ label, icon: Icon, value, verified, href, info }) => {
- return (
- <Fragment key={label}>
- {showLabels && (
- <span className="text-content-default font-medium">{label}</span>
- )}
- <div>
- <PartnerPlatformCard
- icon={Icon}
- value={value ?? ""}
- verified={verified}
- info={info}
- href={href ?? undefined}
- />
- </div>
- </Fragment>
- );
- })}
+ {fieldData.map(
+ ({
+ type,
+ label,
+ icon: Icon,
+ value,
+ verified,
+ href,
+ info,
+ identifier,
+ }) => {
+ return (
+ <Fragment key={label}>
+ <div>
+ <PartnerPlatformCard
+ icon={Icon}
+ value={value ?? ""}
+ verified={verified}
+ info={info}
+ href={href ?? undefined}
+ {...(subdomain === "admin" && {
+ onVerify: () =>
+ handleVerifyPlatform(type, identifier as string, label),
+ isVerifying: Boolean(verifyingPlatforms[type]),
+ })}
+ />
+ </div>
+ </Fragment>
+ );
+ },
+ )}
</div>
);
}