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

Steven Tey53188b7f90c5
diff --git a/apps/web/app/(ee)/admin.dub.co/(dashboard)/partners/network/identity-verification.tsx b/apps/web/app/(ee)/admin.dub.co/(dashboard)/partners/network/identity-verification.tsx
new file mode 100644
index 0000000000..61a985dd79
--- /dev/null
+++ b/apps/web/app/(ee)/admin.dub.co/(dashboard)/partners/network/identity-verification.tsx
@@ -0,0 +1,189 @@
+"use client";
+
+import { AdminNetworkPartner } from "@/lib/types";
+import { useConfirmModal } from "@/ui/modals/confirm-modal";
+import { Button, CopyButton } from "@dub/ui";
+import { ShieldCheck, Veriff, VerifiedBadge } from "@dub/ui/icons";
+import { useEffect, useRef, useState } from "react";
+import { toast } from "sonner";
+
+export function NetworkIdentityVerification({
+ partner,
+}: {
+ partner: Pick<AdminNetworkPartner, "id" | "identityVerifiedAt">;
+}) {
+ const [sessionUrl, setSessionUrl] = useState<string | null>(null);
+ const [isGeneratingSession, setIsGeneratingSession] = useState(false);
+ const [isVerifyingIdentity, setIsVerifyingIdentity] = useState(false);
+ const partnerIdRef = useRef(partner.id);
+
+ useEffect(() => {
+ partnerIdRef.current = partner.id;
+ setSessionUrl(null);
+ setIsGeneratingSession(false);
+ setIsVerifyingIdentity(false);
+ }, [partner.id]);
+
+ const handleGenerateSession = async () => {
+ const requestPartnerId = partner.id;
+ setIsGeneratingSession(true);
+
+ try {
+ const response = await fetch(
+ `/api/admin/partners/${requestPartnerId}/generate-veriff-session`,
+ {
+ method: "POST",
+ },
+ );
+
+ if (!response.ok) {
+ throw new Error(
+ (await response.text()) || "Failed to generate Veriff session.",
+ );
+ }
+
+ const { sessionUrl: url } = (await response.json()) as {
+ sessionUrl: string;
+ };
+
+ if (partnerIdRef.current !== requestPartnerId) {
+ return;
+ }
+
+ setSessionUrl(url);
+ toast.success("Veriff session generated.");
+ } catch (error) {
+ if (partnerIdRef.current !== requestPartnerId) {
+ return;
+ }
+
+ toast.error(
+ error instanceof Error
+ ? error.message
+ : "Failed to generate Veriff session.",
+ );
+ } finally {
+ if (partnerIdRef.current === requestPartnerId) {
+ setIsGeneratingSession(false);
+ }
+ }
+ };
+
+ const handleVerifyIdentity = async () => {
+ const requestPartnerId = partner.id;
+ setIsVerifyingIdentity(true);
+
+ try {
+ const response = await fetch(
+ `/api/admin/partners/${requestPartnerId}/verify-identity`,
+ {
+ method: "POST",
+ },
+ );
+
+ if (!response.ok) {
+ throw new Error(
+ (await response.text()) || "Failed to verify partner identity.",
+ );
+ }
+
+ if (partnerIdRef.current !== requestPartnerId) {
+ return;
+ }
+
+ toast.success("Partner identity verified.");
+ } catch (error) {
+ if (partnerIdRef.current !== requestPartnerId) {
+ return;
+ }
+
+ toast.error(
+ error instanceof Error
+ ? error.message
+ : "Failed to verify partner identity.",
+ );
+ } finally {
+ if (partnerIdRef.current === requestPartnerId) {
+ setIsVerifyingIdentity(false);
+ }
+ }
+ };
+
+ const { setShowConfirmModal: setShowGenerateSessionModal, confirmModal } =
+ useConfirmModal({
+ title: "Identity verification",
+ description:
+ "This will trigger a new Veriff session URL that you can send to the partner. Are you sure you want to proceed?",
+ confirmText: "Generate session",
+ onConfirm: handleGenerateSession,
+ });
+
+ const {
+ setShowConfirmModal: setShowVerifyIdentityModal,
+ confirmModal: verifyIdentityConfirmModal,
+ } = useConfirmModal({
+ title: "Identity verification",
+ description:
+ "This will manually verify the partner's identity (for partners with US LLC). Are you sure you want to proceed?",
+ confirmText: "Verify identity",
+ onConfirm: handleVerifyIdentity,
+ });
+
+ return (
+ <>
+ {confirmModal}
+ {verifyIdentityConfirmModal}
+ <section className="w-full min-w-0 max-w-full overflow-x-hidden rounded-xl border border-neutral-200 bg-neutral-100 p-4">
+ <div className="flex items-center gap-2">
+ <ShieldCheck className="size-4 text-neutral-500" />
+ <h3 className="text-sm font-semibold text-neutral-900">
+ Identity verification
+ </h3>
+ </div>
+
+ <div className="mt-2 flex flex-wrap items-center gap-2">
+ <Button
+ variant="secondary"
+ text="Generate Veriff Session"
+ loading={isGeneratingSession}
+ className="h-8"
+ icon={<Veriff className="size-4" />}
+ onClick={() => setShowGenerateSessionModal(true)}
+ />
+ <Button
+ variant="secondary"
+ text="Verify identity"
+ loading={isVerifyingIdentity}
+ className="h-8"
+ icon={<VerifiedBadge className="size-4" />}
+ disabledTooltip={
+ partner.identityVerifiedAt !== null
+ ? "Identity already verified"
+ : undefined
+ }
+ onClick={() => setShowVerifyIdentityModal(true)}
+ />
+ </div>
+
+ {sessionUrl && (
+ <div className="mt-2 flex items-center gap-2 rounded-lg border border-neutral-200 bg-white px-3 py-2">
+ <a
+ href={sessionUrl}
+ target="_blank"
+ rel="noopener noreferrer"
+ className="min-w-0 flex-1 truncate text-xs text-blue-600 underline-offset-2 hover:underline"
+ >
+ {sessionUrl}
+ </a>
+ <CopyButton
+ value={sessionUrl}
+ variant="neutral"
+ className="shrink-0 p-1 [&>*]:h-3 [&>*]:w-3"
+ successMessage="Copied verification URL to clipboard!"
+ />
+ </div>
+ )}
+ </section>
+ </>
+ );
+}
diff --git a/apps/web/app/(ee)/admin.dub.co/(dashboard)/partners/network/network-partner-application-sheet.tsx b/apps/web/app/(ee)/admin.dub.co/(dashboard)/partners/network/network-partner-application-sheet.tsx
index 6f4ee86709..dd38147df5 100644
--- a/apps/web/app/(ee)/admin.dub.co/(dashboard)/partners/network/network-partner-application-sheet.tsx
+++ b/apps/web/app/(ee)/admin.dub.co/(dashboard)/partners/network/network-partner-application-sheet.tsx
@@ -27,8 +27,8 @@ import { cn, COUNTRIES, currencyFormatter, OG_AVATAR_URL } from "@dub/utils";
import { LayoutGroup, motion } from "motion/react";
import Link from "next/link";
import { useEffect, useId, useState } from "react";
+import { NetworkIdentityVerification } from "./identity-verification";
import { NetworkPartnerChangeHistory } from "./network-partner-change-history";
-import { NetworkRequestIdentityVerification } from "./request-identity-verification";
type NetworkPartnerSheetTabId = "about" | "programs" | "duplicates";
@@ -303,14 +303,14 @@ export function NetworkPartnerApplicationSheet({
/>
</div>
</div>
+ <div className="overflow-x-hidden">
+ <NetworkIdentityVerification partner={partner} />
+ </div>
<div className="overflow-x-hidden">
<NetworkPartnerChangeHistory
changeHistoryLog={partner.changeHistoryLog}
/>
</div>
- <div className="overflow-x-hidden">
- <NetworkRequestIdentityVerification partner={partner} />
- </div>
</div>
<div className="@3xl/sheet:order-1 @3xl/sheet:min-h-0 @3xl/sheet:overflow-y-auto scrollbar-hide">
<div className="border-border-subtle overflow-hidden rounded-xl border bg-neutral-100">
diff --git a/apps/web/app/(ee)/admin.dub.co/(dashboard)/partners/network/request-identity-verification.tsx b/apps/web/app/(ee)/admin.dub.co/(dashboard)/partners/network/request-identity-verification.tsx
deleted file mode 100644
index bb8e60e547..0000000000
--- a/apps/web/app/(ee)/admin.dub.co/(dashboard)/partners/network/request-identity-verification.tsx
+++ /dev/null
@@ -1,122 +0,0 @@
-"use client";
-
-import { AdminNetworkPartner } from "@/lib/types";
-import { useConfirmModal } from "@/ui/modals/confirm-modal";
-import { Button, CopyButton } from "@dub/ui";
-import { ShieldCheck } from "@dub/ui/icons";
-import { useEffect, useRef, useState } from "react";
-import { toast } from "sonner";
-
-export function NetworkRequestIdentityVerification({
- partner,
-}: {
- partner: Pick<AdminNetworkPartner, "id">;
-}) {
- const [sessionUrl, setSessionUrl] = useState<string | null>(null);
- const [isLoading, setIsLoading] = useState(false);
- const partnerIdRef = useRef(partner.id);
-
- useEffect(() => {
- partnerIdRef.current = partner.id;
- setSessionUrl(null);
- setIsLoading(false);
- }, [partner.id]);
-
- const handleGenerateSession = async () => {
- const requestPartnerId = partner.id;
- setIsLoading(true);
-
- try {
- const response = await fetch(
- `/api/admin/partners/${requestPartnerId}/identity-verification`,
- {
- method: "POST",
- },
- );
-
- if (!response.ok) {
- throw new Error(
- (await response.text()) || "Failed to generate Veriff session.",
- );
- }
-
- const { sessionUrl: url } = (await response.json()) as {
- sessionUrl: string;
- };
-
- if (partnerIdRef.current !== requestPartnerId) {
- return;
- }
-
- setSessionUrl(url);
- toast.success("Veriff session generated.");
- } catch (error) {
- if (partnerIdRef.current !== requestPartnerId) {
- return;
- }
-
- toast.error(
- error instanceof Error
- ? error.message
- : "Failed to generate Veriff session.",
- );
- } finally {
- if (partnerIdRef.current === requestPartnerId) {
- setIsLoading(false);
- }
- }
- };
-
- const { setShowConfirmModal, confirmModal } = useConfirmModal({
- title: "Request identity verification",
- description:
- "This will trigger a new Veriff verification session for the partner.",
- confirmText: "Generate session",
- onConfirm: handleGenerateSession,
- });
-
- return (
- <>
- {confirmModal}
- <section className="w-full min-w-0 max-w-full overflow-x-hidden rounded-xl border border-neutral-200 bg-neutral-100 p-4">
- <div className="flex items-center gap-2">
- <ShieldCheck className="size-4 text-neutral-500" />
- <h3 className="text-sm font-semibold text-neutral-900">
- Request identity verification
- </h3>
- </div>
-
- <p className="mt-1 text-xs text-neutral-500">
- This will trigger a new verification process for the partner.
- </p>
-
- {sessionUrl ? (
- <div className="mt-2 flex items-center gap-2 rounded-lg border border-neutral-200 bg-white px-3 py-2">
- <a
- href={sessionUrl}
- target="_blank"
- rel="noopener noreferrer"
- className="min-w-0 flex-1 truncate text-xs text-blue-600 underline-offset-2 hover:underline"
- >
- {sessionUrl}
- </a>
- <CopyButton
- value={sessionUrl}
- variant="neutral"
- className="shrink-0 p-1 [&>*]:h-3 [&>*]:w-3"
- successMessage="Copied verification URL to clipboard!"
- />
- </div>
- ) : (
- <Button
- variant="secondary"
- text="Generate Veriff Session"
- className="mt-2"
- loading={isLoading}
- onClick={() => setShowConfirmModal(true)}
- />
- )}
- </section>
- </>
- );
-}
diff --git a/apps/web/app/(ee)/api/admin/partners/[partnerId]/identity-verification/route.ts b/apps/web/app/(ee)/api/admin/partners/[partnerId]/generate-veriff-session/route.ts
similarity index 97%
rename from apps/web/app/(ee)/api/admin/partners/[partnerId]/identity-verification/route.ts
rename to apps/web/app/(ee)/api/admin/partners/[partnerId]/generate-veriff-session/route.ts
index f5b4918e56..e493bb1bfc 100644
--- a/apps/web/app/(ee)/api/admin/partners/[partnerId]/identity-verification/route.ts
+++ b/apps/web/app/(ee)/api/admin/partners/[partnerId]/generate-veriff-session/route.ts
@@ -8,7 +8,7 @@ import { prisma } from "@dub/prisma";
import { addDays } from "date-fns";
import { NextResponse } from "next/server";
-// POST /api/admin/partners/[partnerId]/identity-verification
+// POST /api/admin/partners/[partnerId]/generate-veriff-session
export const POST = withAdmin(
async ({ params }) => {
const { partnerId } = params;
diff --git a/apps/web/app/(ee)/api/admin/partners/[partnerId]/verify-identity/route.ts b/apps/web/app/(ee)/api/admin/partners/[partnerId]/verify-identity/route.ts
new file mode 100644
index 0000000000..a52233160c
--- /dev/null
+++ b/apps/web/app/(ee)/api/admin/partners/[partnerId]/verify-identity/route.ts
@@ -0,0 +1,47 @@
+import { withAdmin } from "@/lib/auth";
+import { prisma } from "@dub/prisma";
+import { NextResponse } from "next/server";
+
+// POST /api/admin/partners/[partnerId]/verify-identity
+export const POST = withAdmin(
+ async ({ params }) => {
+ const { partnerId } = params;
+
+ const partner = await prisma.partner.findUnique({
+ where: {
+ id: partnerId,
+ },
+ select: {
+ id: true,
+ identityVerifiedAt: true,
+ },
+ });
+
+ if (!partner) {
+ return new Response("Partner not found.", { status: 404 });
+ }
+
+ if (partner.identityVerifiedAt) {
+ return new Response("This partner's identity is already verified.", {
+ status: 400,
+ });
+ }
+
+ await prisma.partner.update({
+ where: {
+ id: partnerId,
+ },
+ data: {
+ identityVerifiedAt: new Date(),
+ identityVerificationStatus: "approved",
+ },
+ });
+
+ return NextResponse.json({
+ success: true,
+ });
+ },
+ {
+ requiredRoles: ["owner"],
+ },
+);
diff --git a/apps/web/app/(ee)/api/stripe/webhook/utils/process-payout-invoice-failure.ts b/apps/web/app/(ee)/api/stripe/webhook/utils/process-payout-invoice-failure.ts
index 36ca6778c4..3d599efea9 100644
--- a/apps/web/app/(ee)/api/stripe/webhook/utils/process-payout-invoice-failure.ts
+++ b/apps/web/app/(ee)/api/stripe/webhook/utils/process-payout-invoice-failure.ts
@@ -7,7 +7,6 @@ import { sendBatchEmail } from "@dub/email";
import PartnerPayoutFailed from "@dub/email/templates/partner-payout-failed";
import { prisma } from "@dub/prisma";
import { Invoice } from "@dub/prisma/client";
-import { log } from "@dub/utils";
import { waitUntil } from "@vercel/functions";
import Stripe from "stripe";
@@ -18,12 +17,6 @@ export async function processPayoutInvoiceFailure({
invoice: Invoice;
charge?: Stripe.Charge;
}) {
- await log({
- message: `Partner payout failed for invoice ${invoice.id}.`,
- type: "errors",
- mention: true,
- });
-
// reset the payouts to their initial state
const { count } = await prisma.payout.updateMany({
where: {