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.

update admin portal

Steven Teye269606dbdcb
diff --git a/apps/web/app/(ee)/admin.dub.co/(dashboard)/components/delete-stripe-express.tsx b/apps/web/app/(ee)/admin.dub.co/(dashboard)/components/delete-stripe-express.tsx
new file mode 100644
index 0000000000..e20c00835c
--- /dev/null
+++ b/apps/web/app/(ee)/admin.dub.co/(dashboard)/components/delete-stripe-express.tsx
@@ -0,0 +1,68 @@
+"use client";
+
+import { LoadingSpinner } from "@dub/ui";
+import { cn } from "@dub/utils";
+import { useFormStatus } from "react-dom";
+import { toast } from "sonner";
+
+export default function DeleteStripeExpress() {
+ return (
+ <div className="flex flex-col space-y-5">
+ <form
+ action={async (formData) => {
+ await fetch("/api/admin/delete-stripe-express", {
+ method: "POST",
+ body: JSON.stringify({
+ email: formData.get("email"),
+ }),
+ }).then(async (res) => {
+ if (res.ok) {
+ toast.success("Stripe express account deleted!");
+ } else {
+ const error = await res.text();
+ toast.error(error);
+ }
+ });
+ }}
+ >
+ <Form />
+ </form>
+ </div>
+ );
+}
+
+const Form = () => {
+ const { pending } = useFormStatus();
+
+ return (
+ <div className="relative flex w-full rounded-md shadow-sm">
+ <input
+ name="email"
+ id="email"
+ type="email"
+ required
+ disabled={pending}
+ autoComplete="off"
+ className={cn(
+ "block w-full rounded-md border-neutral-300 text-neutral-900 placeholder-neutral-400 focus:border-neutral-500 focus:outline-none focus:ring-neutral-500 sm:text-sm",
+ pending && "bg-neutral-100",
+ )}
+ onPaste={(e: React.ClipboardEvent<HTMLInputElement>) => {
+ // remove mailto: on paste
+ e.preventDefault();
+ const text = e.clipboardData.getData("text/plain");
+ if (text.startsWith("mailto:")) {
+ e.currentTarget.value = text.replace("mailto:", "");
+ } else {
+ e.currentTarget.value = text;
+ }
+ }}
+ placeholder="[email protected]"
+ aria-invalid="true"
+ />
+ {pending && (
+ <LoadingSpinner className="absolute inset-y-0 right-2 my-auto h-full w-5 text-neutral-400" />
+ )}
+ </div>
+ );
+};
diff --git a/apps/web/app/(ee)/admin.dub.co/(dashboard)/components/impersonate-user.tsx b/apps/web/app/(ee)/admin.dub.co/(dashboard)/components/impersonate-user.tsx
index 491b2cd16b..ce3cbf0643 100644
--- a/apps/web/app/(ee)/admin.dub.co/(dashboard)/components/impersonate-user.tsx
+++ b/apps/web/app/(ee)/admin.dub.co/(dashboard)/components/impersonate-user.tsx
@@ -92,7 +92,7 @@ const Form = () => {
e.currentTarget.value = text;
}
}}
- placeholder="[email protected]"
+ placeholder="[email protected]"
aria-invalid="true"
/>
{pending && (
diff --git a/apps/web/app/(ee)/admin.dub.co/(dashboard)/page.tsx b/apps/web/app/(ee)/admin.dub.co/(dashboard)/page.tsx
index fc3f0413f8..5ff81f9f4e 100644
--- a/apps/web/app/(ee)/admin.dub.co/(dashboard)/page.tsx
+++ b/apps/web/app/(ee)/admin.dub.co/(dashboard)/page.tsx
@@ -1,5 +1,6 @@
import { constructMetadata } from "@dub/utils";
import BanLink from "./components/ban-link";
+import DeleteStripeExpress from "./components/delete-stripe-express";
import ImpersonateUser from "./components/impersonate-user";
import ImpersonateWorkspace from "./components/impersonate-workspace";
import RefreshDomain from "./components/refresh-domain";
@@ -24,6 +25,18 @@ export default function AdminPage() {
</p>
<ImpersonateWorkspace />
</div>
+ <div className="flex flex-col space-y-4 px-5 py-10">
+ <h2 className="text-xl font-semibold">Ban Link</h2>
+ <p className="text-sm text-neutral-500">Ban a dub.sh link</p>
+ <BanLink />
+ </div>
+ <div className="flex flex-col space-y-4 px-5 py-10">
+ <h2 className="text-xl font-semibold">Delete Stripe Express</h2>
+ <p className="text-sm text-neutral-500">
+ Delete a partner's Stripe express account
+ </p>
+ <DeleteStripeExpress />
+ </div>
<div className="flex flex-col space-y-4 px-5 py-10">
<h2 className="text-xl font-semibold">Refresh Domain</h2>
<p className="text-sm text-neutral-500">
@@ -31,11 +44,6 @@ export default function AdminPage() {
</p>
<RefreshDomain />
</div>
- <div className="flex flex-col space-y-4 px-5 py-10">
- <h2 className="text-xl font-semibold">Ban Link</h2>
- <p className="text-sm text-neutral-500">Ban a dub.sh link</p>
- <BanLink />
- </div>
</div>
);
}
diff --git a/apps/web/app/(ee)/api/admin/delete-stripe-express/route.ts b/apps/web/app/(ee)/api/admin/delete-stripe-express/route.ts
new file mode 100644
index 0000000000..db6dbc97f6
--- /dev/null
+++ b/apps/web/app/(ee)/api/admin/delete-stripe-express/route.ts
@@ -0,0 +1,39 @@
+import { withAdmin } from "@/lib/auth";
+import { stripe } from "@/lib/stripe";
+import { prisma } from "@dub/prisma";
+import { NextResponse } from "next/server";
+
+// POST /api/admin/refresh-domain
+export const POST = withAdmin(async ({ req }) => {
+ const { email } = await req.json();
+
+ const partner = await prisma.partner.findUniqueOrThrow({
+ where: {
+ email,
+ },
+ });
+
+ if (!partner.stripeConnectId) {
+ return new Response("Partner has no Stripe express account", {
+ status: 400,
+ });
+ }
+
+ const response = await stripe.accounts.del(partner.stripeConnectId);
+ if (!response.deleted) {
+ return new Response("Failed to delete Stripe express account", {
+ status: 500,
+ });
+ }
+
+ await prisma.partner.update({
+ where: { id: partner.id },
+ data: {
+ stripeConnectId: null,
+ payoutsEnabledAt: null,
+ payoutMethodHash: null,
+ },
+ });
+
+ return NextResponse.json({ success: true });
+});
diff --git a/apps/web/lib/actions/partners/update-partner-profile.ts b/apps/web/lib/actions/partners/update-partner-profile.ts
index f391355534..694bdeb72a 100644
--- a/apps/web/lib/actions/partners/update-partner-profile.ts
+++ b/apps/web/lib/actions/partners/update-partner-profile.ts
@@ -305,6 +305,7 @@ const deleteStripeAccountIfRequired = async ({
data: {
stripeConnectId: null,
payoutsEnabledAt: null,
+ payoutMethodHash: null,
},
});
}