Skip to content

Open source CapCut alternative.

TypeScript

Move self-serve dashboard to /app/settings and add portal config (#7)

David Leebbbf1bad035
diff --git a/site/.env.example b/site/.env.example
index 6a937e9e..bf2370d8 100644
--- a/site/.env.example
+++ b/site/.env.example
@@ -37,3 +37,4 @@ RUNPOD_VISION_ENDPOINT_ID="replace-with-endpoint-id"
STRIPE_SECRET_KEY="replace-with-stripe-secret-key"
STRIPE_WEBHOOK_SECRET="replace-with-stripe-webhook-signing-secret"
STRIPE_VISION_PRICE_ID="replace-with-stripe-price-id"
+STRIPE_PORTAL_CONFIGURATION_ID="replace-with-stripe-portal-configuration-id"
diff --git a/site/src/app/api/billing/checkout/route.ts b/site/src/app/api/billing/checkout/route.ts
index 15cbbff8..345f4cdb 100644
--- a/site/src/app/api/billing/checkout/route.ts
+++ b/site/src/app/api/billing/checkout/route.ts
@@ -44,13 +44,13 @@ export const POST = withDonkeyAuth(async (request) => {
const origin = request.nextUrl.origin;
const checkout = await stripe.checkout.sessions.create({
allow_promotion_codes: true,
- cancel_url: `${origin}/dashboard?checkout=cancelled`,
+ cancel_url: `${origin}/app/settings?checkout=cancelled`,
client_reference_id: session.user.id,
customer: customerId,
line_items: [{ price: visionPriceId(), quantity: 1 }],
mode: "subscription",
subscription_data: { metadata: { userId: session.user.id } },
- success_url: `${origin}/dashboard?checkout=success`,
+ success_url: `${origin}/app/settings?checkout=success`,
});
if (!checkout.url) {
diff --git a/site/src/app/api/billing/portal/route.ts b/site/src/app/api/billing/portal/route.ts
index bee0a18c..c49ee9a7 100644
--- a/site/src/app/api/billing/portal/route.ts
+++ b/site/src/app/api/billing/portal/route.ts
@@ -1,6 +1,6 @@
import { NextResponse } from "next/server";
-import { getStripe } from "@/lib/billing/stripe";
+import { getStripe, visionPortalConfigurationId } from "@/lib/billing/stripe";
import {
donkeySessionUserId,
notFoundResponse,
@@ -26,9 +26,11 @@ export const POST = withDonkeyAuth(async (request) => {
}
const stripe = getStripe();
+ const configuration = visionPortalConfigurationId();
const portal = await stripe.billingPortal.sessions.create({
customer: subscription.stripeCustomerId,
- return_url: `${request.nextUrl.origin}/dashboard`,
+ return_url: `${request.nextUrl.origin}/app/settings`,
+ ...(configuration ? { configuration } : {}),
});
return NextResponse.json({ url: portal.url });
diff --git a/site/src/app/api/billing/usage/route.ts b/site/src/app/api/billing/usage/route.ts
index da79f42a..f9e3fe08 100644
--- a/site/src/app/api/billing/usage/route.ts
+++ b/site/src/app/api/billing/usage/route.ts
@@ -11,7 +11,7 @@ import { prisma } from "@/lib/prisma";
export const dynamic = "force-dynamic";
// Current-period Vision API call usage vs quota, plus recent API calls, for the
-// dashboard. Reads the authoritative per-period counter on the subscription;
+// settings UI. Reads the authoritative per-period counter on the subscription;
// the recent list is independent so it runs in parallel.
export const GET = withDonkeyAuth(async (request) => {
const userId = donkeySessionUserId(request);
diff --git a/site/src/app/dashboard/DashboardShell.tsx b/site/src/app/app/settings/SettingsShell.tsx
similarity index 82%
rename from site/src/app/dashboard/DashboardShell.tsx
rename to site/src/app/app/settings/SettingsShell.tsx
index 4088e0fd..8d804d00 100644
--- a/site/src/app/dashboard/DashboardShell.tsx
+++ b/site/src/app/app/settings/SettingsShell.tsx
@@ -9,13 +9,13 @@ import { cn } from "@/lib/utils";
import { Skeleton } from "@/components/ui/skeleton";
const navItems = [
- { href: "/dashboard", label: "Overview" },
- { href: "/dashboard/api-keys", label: "API keys" },
+ { href: "/app/settings", label: "Overview" },
+ { href: "/app/settings/api-keys", label: "API keys" },
];
-// Dashboards are fully client-rendered. We guard on the client session and, if
-// signed out, send the user to Google sign-in (API routes also enforce auth).
-export function DashboardShell({ children }: { children: ReactNode }) {
+// The settings UI is fully client-rendered. We guard on the client session and,
+// if signed out, send the user to Google sign-in (API routes also enforce auth).
+export function SettingsShell({ children }: { children: ReactNode }) {
const router = useRouter();
const pathname = usePathname();
const { data: session, isPending } = authClient.useSession();
@@ -23,7 +23,7 @@ export function DashboardShell({ children }: { children: ReactNode }) {
useEffect(() => {
if (!isPending && !session) {
void authClient.signIn.social({
- callbackURL: "/dashboard",
+ callbackURL: "/app/settings",
provider: "google",
});
}
@@ -42,7 +42,7 @@ export function DashboardShell({ children }: { children: ReactNode }) {
<div className="min-h-screen bg-background text-foreground">
<header className="border-b">
<div className="mx-auto flex max-w-5xl items-center justify-between px-6 py-4">
- <Link className="text-lg font-semibold" href="/dashboard">
+ <Link className="text-lg font-semibold" href="/app/settings">
Donkey Vision API
</Link>
<nav className="flex items-center gap-1">
diff --git a/site/src/app/dashboard/_components/ApiKeysManager.tsx b/site/src/app/app/settings/_components/ApiKeysManager.tsx
similarity index 100%
rename from site/src/app/dashboard/_components/ApiKeysManager.tsx
rename to site/src/app/app/settings/_components/ApiKeysManager.tsx
diff --git a/site/src/app/dashboard/_components/SubscriptionCard.tsx b/site/src/app/app/settings/_components/SubscriptionCard.tsx
similarity index 100%
rename from site/src/app/dashboard/_components/SubscriptionCard.tsx
rename to site/src/app/app/settings/_components/SubscriptionCard.tsx
diff --git a/site/src/app/dashboard/_components/UsageCard.tsx b/site/src/app/app/settings/_components/UsageCard.tsx
similarity index 100%
rename from site/src/app/dashboard/_components/UsageCard.tsx
rename to site/src/app/app/settings/_components/UsageCard.tsx
diff --git a/site/src/app/dashboard/api-keys/page.tsx b/site/src/app/app/settings/api-keys/page.tsx
similarity index 87%
rename from site/src/app/dashboard/api-keys/page.tsx
rename to site/src/app/app/settings/api-keys/page.tsx
index 3b4c443d..aada6845 100644
--- a/site/src/app/dashboard/api-keys/page.tsx
+++ b/site/src/app/app/settings/api-keys/page.tsx
@@ -1,6 +1,6 @@
"use client";
-import { ApiKeysManager } from "@/app/dashboard/_components/ApiKeysManager";
+import { ApiKeysManager } from "@/app/app/settings/_components/ApiKeysManager";
export default function ApiKeysPage() {
return (
diff --git a/site/src/app/app/settings/layout.tsx b/site/src/app/app/settings/layout.tsx
new file mode 100644
index 00000000..7e315180
--- /dev/null
+++ b/site/src/app/app/settings/layout.tsx
@@ -0,0 +1,15 @@
+import type { Metadata } from "next";
+import type { ReactNode } from "react";
+
+import { SettingsShell } from "@/app/app/settings/SettingsShell";
+
+export const metadata: Metadata = {
+ title: "Settings | Donkey Vision API",
+ description: "Manage your Vision API subscription and API keys.",
+};
+
+// QueryProvider is mounted once at the root layout, so the settings UI just needs
+// its session-guarded shell here.
+export default function SettingsLayout({ children }: { children: ReactNode }) {
+ return <SettingsShell>{children}</SettingsShell>;
+}
diff --git a/site/src/app/dashboard/page.tsx b/site/src/app/app/settings/page.tsx
similarity index 63%
rename from site/src/app/dashboard/page.tsx
rename to site/src/app/app/settings/page.tsx
index b49bc0aa..d7d58f10 100644
--- a/site/src/app/dashboard/page.tsx
+++ b/site/src/app/app/settings/page.tsx
@@ -1,9 +1,9 @@
"use client";
-import { SubscriptionCard } from "@/app/dashboard/_components/SubscriptionCard";
-import { UsageCard } from "@/app/dashboard/_components/UsageCard";
+import { SubscriptionCard } from "@/app/app/settings/_components/SubscriptionCard";
+import { UsageCard } from "@/app/app/settings/_components/UsageCard";
-export default function DashboardOverviewPage() {
+export default function SettingsOverviewPage() {
return (
<div className="space-y-8">
<div>
diff --git a/site/src/app/dashboard/layout.tsx b/site/src/app/dashboard/layout.tsx
deleted file mode 100644
index 388e1ac0..00000000
--- a/site/src/app/dashboard/layout.tsx
+++ /dev/null
@@ -1,15 +0,0 @@
-import type { Metadata } from "next";
-import type { ReactNode } from "react";
-
-import { DashboardShell } from "@/app/dashboard/DashboardShell";
-
-export const metadata: Metadata = {
- title: "Dashboard | Donkey Vision API",
- description: "Manage your Vision API subscription and API keys.",
-};
-
-// QueryProvider is mounted once at the root layout, so the dashboard just needs
-// its session-guarded shell here.
-export default function DashboardLayout({ children }: { children: ReactNode }) {
- return <DashboardShell>{children}</DashboardShell>;
-}
diff --git a/site/src/app/donkeyvision/PricingSection.tsx b/site/src/app/donkeyvision/PricingSection.tsx
index 93ee27ff..b4151d71 100644
--- a/site/src/app/donkeyvision/PricingSection.tsx
+++ b/site/src/app/donkeyvision/PricingSection.tsx
@@ -38,7 +38,7 @@ export function PricingSection() {
</div>
<div className="flex flex-col items-stretch justify-center gap-3 md:items-end">
<Link
- href="/dashboard"
+ href="/app/settings"
className="inline-flex min-h-14 items-center justify-center gap-2 rounded-full bg-[#EC7868] px-7 text-base font-semibold text-[#0F0E0D] transition hover:-translate-y-0.5"
>
Get started <ArrowRight size={18} aria-hidden="true" />
diff --git a/site/src/app/donkeyvision/page.tsx b/site/src/app/donkeyvision/page.tsx
index 69f4ef53..f28143c1 100644
--- a/site/src/app/donkeyvision/page.tsx
+++ b/site/src/app/donkeyvision/page.tsx
@@ -21,7 +21,7 @@ export const metadata: Metadata = {
export default function DonkeyVisionPage() {
return (
<main className="min-h-screen w-full overflow-x-hidden bg-[#F5EFE0] font-[-apple-system,BlinkMacSystemFont,'Segoe_UI',sans-serif] text-[#0F0E0D]">
- <TopNav ctaHref="/dashboard" ctaLabel="Get started" />
+ <TopNav ctaHref="/app/settings" ctaLabel="Get started" />
<HeroSection />
<ProofSection />
<ApiSection />
diff --git a/site/src/lib/billing/stripe.ts b/site/src/lib/billing/stripe.ts
index a2220edc..9901f002 100644
--- a/site/src/lib/billing/stripe.ts
+++ b/site/src/lib/billing/stripe.ts
@@ -40,6 +40,12 @@ export function visionPriceId(): string {
return priceId;
}
+// Optional: a specific billing portal configuration (bpc_...). When unset,
+// Stripe uses the account's default portal configuration.
+export function visionPortalConfigurationId(): string | undefined {
+ return process.env.STRIPE_PORTAL_CONFIGURATION_ID || undefined;
+}
+
export function quotaFromPrice(price: Stripe.Price | null | undefined): number {
const raw = price?.metadata?.monthlyCallQuota;
if (raw) {
diff --git a/site/src/queries/apiClient.ts b/site/src/queries/apiClient.ts
index 4154e0ad..a9a5a626 100644
--- a/site/src/queries/apiClient.ts
+++ b/site/src/queries/apiClient.ts
@@ -1,5 +1,5 @@
// Thin fetch wrapper shared by every query/mutation hook in this folder. All
-// dashboard data access goes through here so it can be audited in one place.
+// settings UI data access goes through here so it can be audited in one place.
export class ApiError extends Error {
public readonly status: number;