Open source CapCut alternative.
TypeScript
feat(site): Cut account menu with in-app billing and usage settings
David Le07cfcd2b23bb
diff --git a/site/src/app/app/settings/_components/UsageHistoryCard.tsx b/site/src/app/app/settings/_components/UsageHistoryCard.tsxindex 0b157340..38c92f22 100644--- a/site/src/app/app/settings/_components/UsageHistoryCard.tsx+++ b/site/src/app/app/settings/_components/UsageHistoryCard.tsx@@ -228,7 +228,16 @@ function CallDetail({ call }: { call: RecentCall }) {);}-export function UsageHistoryCard() {+// showVision=false (Cut's usage page) drops the Vision API tab and shows only+// app calls. plain=true drops the card chrome entirely — the table renders+// directly on the page and stretches to the space its parent gives it.+export function UsageHistoryCard({+ showVision = true,+ plain = false,+}: {+ showVision?: boolean;+ plain?: boolean;+}) {const usage = useUsage();const [tab, setTab] = useState<TabKey>("app");const [page, setPage] = useState(1);@@ -239,6 +248,9 @@ export function UsageHistoryCard() {const rowRefs = useRef<(HTMLTableRowElement | null)[]>([]);if (usage.isLoading) {+ if (plain) {+ return <Skeleton className="h-64 w-full" />;+ }return (<Card><CardHeader>@@ -302,12 +314,13 @@ export function UsageHistoryCard() {}};- return (- <Card>- <CardHeader>- <CardTitle>Usage history</CardTitle>- </CardHeader>- <CardContent className="space-y-4">+ // In a height-constrained flex column (Cut's usage page) the wrapper fills+ // the remaining space, the table body scrolls on its own with the column+ // header row pinned, and the pagination stays visible below. In normal flow+ // (the apex settings) these classes are inert and the card grows as before.+ const body = (+ <>+ {showVision ? (<div className="inline-flex rounded-md border p-0.5">{tabs.map((item) => (<button@@ -325,14 +338,29 @@ export function UsageHistoryCard() {</button>))}</div>+ ) : null}+ {/* The table's own container must stay overflow-visible so the sticky+ header row pins against the real scroll ancestor: this wrapper in+ card mode, the surrounding pane in plain mode. */}+ <div+ className={cn(+ "[&_[data-slot=table-container]]:overflow-visible",+ !plain && "min-h-0 flex-1 overflow-y-auto",+ )}+ >{tabRows.length === 0 ? (<p className="text-sm text-muted-foreground">No {tab === "app" ? "app" : "Vision API"} calls yet.</p>) : (<Table>- <TableHeader>+ <TableHeader+ className={cn(+ "sticky top-0 z-10",+ plain ? "bg-background" : "bg-card",+ )}+ ><TableRow><TableHead>Date</TableHead><TableHead>Kind</TableHead>@@ -430,8 +458,10 @@ export function UsageHistoryCard() {</TableBody></Table>)}+ </div>{totalPages > 1 ? (+ <div className={cn(plain && "sticky bottom-0 z-10 bg-background py-3")}><Pagination><PaginationContent><PaginationItem>@@ -468,7 +498,21 @@ export function UsageHistoryCard() {</PaginationItem></PaginationContent></Pagination>+ </div>) : null}+ </>+ );++ if (plain) {+ return <div className="space-y-4">{body}</div>;+ }+ return (+ <Card className="min-h-0 flex-1">+ <CardHeader>+ <CardTitle>Usage history</CardTitle>+ </CardHeader>+ <CardContent className="flex min-h-0 flex-1 flex-col gap-4">+ {body}</CardContent></Card>);diff --git a/site/src/app/cut/_components/landing/cutPricingPlans.ts b/site/src/app/cut/_components/landing/cutPricingPlans.tsindex b2f879d0..96c13f5c 100644--- a/site/src/app/cut/_components/landing/cutPricingPlans.ts+++ b/site/src/app/cut/_components/landing/cutPricingPlans.ts@@ -25,7 +25,7 @@ export function cutPricingPlans(root: string): PricingPlan[] {},{action: {- href: "/app/settings",+ href: `${root}/app/settings`,kind: "link",label: "Get Pro",},diff --git a/site/src/app/cut/app/(home)/layout.tsx b/site/src/app/cut/app/(home)/layout.tsxindex 2c82b66d..517cc839 100644--- a/site/src/app/cut/app/(home)/layout.tsx+++ b/site/src/app/cut/app/(home)/layout.tsx@@ -2,9 +2,9 @@ import { AppSidebar } from "@/cut/components/AppSidebar";export default function HomeLayout({ children }: { children: React.ReactNode }) {return (- <div className="flex min-h-screen bg-background">+ <div className="flex h-screen bg-background"><AppSidebar />- <main className="min-w-0 flex-1">{children}</main>+ <main className="min-w-0 flex-1 overflow-y-auto">{children}</main></div>);}diff --git a/site/src/app/cut/app/(home)/settings/SettingsHeader.tsx b/site/src/app/cut/app/(home)/settings/SettingsHeader.tsxnew file mode 100644index 00000000..99bfe401--- /dev/null+++ b/site/src/app/cut/app/(home)/settings/SettingsHeader.tsx@@ -0,0 +1,40 @@+"use client";++import { usePathname } from "next/navigation";++import { cn } from "@/lib/utils";++// Ordered so the more specific path wins the suffix match. Billing pins its+// title while the cards scroll; usage lets the title scroll away so the+// table's own pinned column header takes the top of the pane.+const SECTIONS = [+ {+ suffix: "/settings/usage",+ title: "Usage",+ description: "Your AI generation usage this billing period.",+ pinned: false,+ },+ {+ suffix: "/settings",+ title: "Billing",+ description: "Your subscription and credit balance.",+ pinned: true,+ },+];++export function SettingsHeader() {+ const pathname = usePathname();+ const section =+ SECTIONS.find((s) => pathname.endsWith(s.suffix)) ?? SECTIONS[1];+ return (+ <div+ className={cn(+ "mx-auto w-full max-w-6xl shrink-0 px-10 pt-9 pb-5",+ section.pinned && "sticky top-0 z-20 bg-background",+ )}+ >+ <h1 className="text-lg font-semibold tracking-tight">{section.title}</h1>+ <p className="mt-1 text-sm text-muted-foreground">{section.description}</p>+ </div>+ );+}diff --git a/site/src/app/cut/app/(home)/settings/layout.tsx b/site/src/app/cut/app/(home)/settings/layout.tsxnew file mode 100644index 00000000..6cb69611--- /dev/null+++ b/site/src/app/cut/app/(home)/settings/layout.tsx@@ -0,0 +1,33 @@+import type { Metadata } from "next";+import type { ReactNode } from "react";++import { SettingsHeader } from "@/app/cut/app/(home)/settings/SettingsHeader";+import { SettingsGuard } from "@/cut/components/SettingsGuard";++export const metadata: Metadata = {+ title: "Settings | Donkey Cut",+ description: "Manage your Donkey Cut subscription, credits, and usage.",+};++// Billing and Usage render inside the Cut app shell (the home layout's+// sidebar); the account menu in the sidebar footer is how users get here.+// The whole pane is the scroll container, so the scrollbar spans it top to+// bottom; the title stays pinned by being sticky inside it. Pages still pick+// their behavior: billing overflows and scrolls the pane, usage fills the+// remaining height exactly (flex-1 + h-full chain) and scrolls only its table+// body. p-px gives the cards' outside ring a pixel of room so the scroll+// container can't clip their top border.+export default function CutSettingsLayout({ children }: { children: ReactNode }) {+ return (+ <SettingsGuard>+ <div className="flex h-full flex-col overflow-y-auto">+ <SettingsHeader />+ <div className="min-h-0 flex-1">+ <div className="mx-auto h-full w-full max-w-6xl px-10">+ <div className="h-full p-px">{children}</div>+ </div>+ </div>+ </div>+ </SettingsGuard>+ );+}diff --git a/site/src/app/cut/app/(home)/settings/page.tsx b/site/src/app/cut/app/(home)/settings/page.tsxnew file mode 100644index 00000000..01a34c51--- /dev/null+++ b/site/src/app/cut/app/(home)/settings/page.tsx@@ -0,0 +1,18 @@+"use client";++import { CreditsCard } from "@/app/app/settings/_components/CreditsCard";+import { ProCard } from "@/app/app/settings/_components/ProCard";+import { SuperuserCreditsCard } from "@/app/app/settings/_components/SuperuserCreditsCard";++// Cut's billing page: the Pro subscription that carries the monthly AI+// credits, plus the credit balance and top-ups. The Vision API plan is a+// Donkey-only surface and stays on the apex settings.+export default function CutBillingPage() {+ return (+ <div className="max-w-2xl space-y-6 pb-9">+ <ProCard />+ <CreditsCard />+ <SuperuserCreditsCard />+ </div>+ );+}diff --git a/site/src/app/cut/app/(home)/settings/usage/page.tsx b/site/src/app/cut/app/(home)/settings/usage/page.tsxnew file mode 100644index 00000000..b4a03f02--- /dev/null+++ b/site/src/app/cut/app/(home)/settings/usage/page.tsx@@ -0,0 +1,7 @@+"use client";++import { UsageHistoryCard } from "@/app/app/settings/_components/UsageHistoryCard";++export default function CutUsagePage() {+ return <UsageHistoryCard showVision={false} plain />;+}diff --git a/site/src/cut/components/AppSidebar.tsx b/site/src/cut/components/AppSidebar.tsxindex 93855125..3de8968a 100644--- a/site/src/cut/components/AppSidebar.tsx+++ b/site/src/cut/components/AppSidebar.tsx@@ -14,6 +14,7 @@ import {} from "@/components/ui/dialog";import { Input } from "@/components/ui/input";import { apiFetch } from "@/cut/lib/api";+import { NavUser } from "@/cut/components/NavUser";import { homeHref, projectHref, tabForPath, useCutBase, type CutTab } from "@/cut/lib/nav";import type { ProjectSummary } from "@/cut/lib/types";import { cn } from "@/lib/utils";@@ -90,6 +91,7 @@ export function AppSidebar() {);})}</nav>+ <NavUser /><Dialog open={createOpen} onOpenChange={setCreateOpen}><DialogContent className="sm:max-w-sm"><DialogHeader>diff --git a/site/src/cut/components/NavUser.tsx b/site/src/cut/components/NavUser.tsxnew file mode 100644index 00000000..bf19aaf1--- /dev/null+++ b/site/src/cut/components/NavUser.tsx@@ -0,0 +1,89 @@+"use client";++import { useRouter } from "next/navigation";+import { ChartColumn, CreditCard, EllipsisVertical, LogOut } from "lucide-react";+import {+ DropdownMenu,+ DropdownMenuContent,+ DropdownMenuGroup,+ DropdownMenuItem,+ DropdownMenuLabel,+ DropdownMenuSeparator,+ DropdownMenuTrigger,+} from "@/components/ui/dropdown-menu";+import { useCutBase } from "@/cut/lib/nav";+import { authClient } from "@/lib/auth-client";++function Avatar({ name, image }: { name: string; image: string | null | undefined }) {+ if (image) {+ return <img src={image} alt="" className="size-8 shrink-0 rounded-lg object-cover" />;+ }+ return (+ <span className="grid size-8 shrink-0 place-items-center rounded-lg bg-muted text-sm font-semibold text-muted-foreground">+ {(name.trim()[0] ?? "?").toUpperCase()}+ </span>+ );+}++// Signed-in user row pinned to the sidebar bottom; the whole row opens the+// account menu. Hidden while signed out — the editor itself needs no account,+// so the row only surfaces once a session exists.+export function NavUser() {+ const router = useRouter();+ const base = useCutBase();+ const { data: session } = authClient.useSession();+ if (!session) return null;++ const { name, email, image } = session.user;++ const signOut = () => {+ // Sign out everywhere: revoke every session for this user (so the Mac app+ // signs out too), then clear this browser's session and land on the Cut+ // landing page. signOut + redirect always run, even if the revoke fails,+ // so the user is never stranded signed-in locally.+ void (async () => {+ try {+ await authClient.revokeSessions();+ } finally {+ await authClient.signOut();+ router.push(base.replace(/\/app$/, "") || "/");+ }+ })();+ };++ return (+ <DropdownMenu>+ <DropdownMenuTrigger className="mt-auto flex w-full items-center gap-2.5 rounded-lg px-2 py-1.5 text-left transition-colors hover:bg-muted data-[popup-open]:bg-muted">+ <Avatar name={name} image={image} />+ <span className="min-w-0 flex-1 leading-tight">+ <span className="block truncate text-sm font-medium">{name}</span>+ <span className="block truncate text-xs text-muted-foreground">{email}</span>+ </span>+ <EllipsisVertical className="size-4 shrink-0 text-muted-foreground" />+ </DropdownMenuTrigger>+ <DropdownMenuContent side="top" align="start" className="w-56">+ {/* GroupLabel must live inside a Group in this menu kit. */}+ <DropdownMenuGroup>+ <DropdownMenuLabel className="flex items-center gap-2.5 font-normal">+ <Avatar name={name} image={image} />+ <span className="min-w-0 flex-1 leading-tight">+ <span className="block truncate text-sm font-medium">{name}</span>+ <span className="block truncate text-xs text-muted-foreground">{email}</span>+ </span>+ </DropdownMenuLabel>+ </DropdownMenuGroup>+ <DropdownMenuSeparator />+ <DropdownMenuItem onClick={() => router.push(`${base}/settings`)}>+ <CreditCard /> Billing+ </DropdownMenuItem>+ <DropdownMenuItem onClick={() => router.push(`${base}/settings/usage`)}>+ <ChartColumn /> Usage+ </DropdownMenuItem>+ <DropdownMenuSeparator />+ <DropdownMenuItem onClick={signOut}>+ <LogOut /> Log out+ </DropdownMenuItem>+ </DropdownMenuContent>+ </DropdownMenu>+ );+}diff --git a/site/src/cut/components/SettingsGuard.tsx b/site/src/cut/components/SettingsGuard.tsxnew file mode 100644index 00000000..b026674f--- /dev/null+++ b/site/src/cut/components/SettingsGuard.tsx@@ -0,0 +1,33 @@+"use client";++import { useEffect, type ReactNode } from "react";++import { Skeleton } from "@/components/ui/skeleton";+import { signInUrl } from "@/cut/lib/generate";+import { authClient } from "@/lib/auth-client";++// Session guard for Cut's billing and usage pages. Signed-out visitors go+// through the same host-aware sign-in flow as the editor's generation+// surfaces (signInUrl): the apex sign-in page on donkeyuse.com hosts (Google's+// redirect_uri is pinned there), the /cut-auth one-time-token handoff on+// donkeycut.com. Reading window.location is safe from hydration mismatch: the+// redirect runs only after the client session resolves.+export function SettingsGuard({ children }: { children: ReactNode }) {+ const { data: session, isPending } = authClient.useSession();++ useEffect(() => {+ if (isPending || session) return;+ window.location.assign(signInUrl());+ }, [isPending, session]);++ if (isPending || !session) {+ return (+ <div className="mx-auto max-w-3xl px-8 py-10">+ <Skeleton className="h-8 w-48" />+ <Skeleton className="mt-6 h-40 w-full" />+ </div>+ );+ }++ return <>{children}</>;+}diff --git a/site/src/cut/lib/generate.ts b/site/src/cut/lib/generate.tsindex e48fac37..2fe0290a 100644--- a/site/src/cut/lib/generate.ts+++ b/site/src/cut/lib/generate.ts@@ -7,7 +7,7 @@ import type { AssetRef } from "./assetRef";import { bytesFromBase64 } from "./bytes";import { composeGenPrompt, foldTextRefs } from "./composeGen";import { stockAssetInDoc } from "./genvideo/docWriter";-import { DONKEY_APEX_ORIGIN, isDonkeycutHost } from "./hosts";+import { DONKEY_APEX_ORIGIN, cutAppBase, isDonkeycutHost } from "./hosts";import { hostedPost } from "./hosted";import { enrichAsset, importFileToProject } from "./media";import { refsToInlineImages, videoSafeInline, visualRefs, type InlineImage } from "./refMedia";@@ -198,15 +198,12 @@ export function signInUrl(): string {* credits link, so keep it and those call sites in sync. */export const NO_CREDITS_MESSAGE = "No credits left";-/** The Donkey settings page where credits are bought (cut.* → apex). Linked- * from any generation error caused by an empty balance. */+/** Cut's billing page, where credits are bought — same-host on every host via+ * the app link base. Linked from any generation error caused by an empty+ * balance. */export function creditsUrl(): string {- if (typeof window === "undefined") return "/app/settings";- const { protocol, host } = window.location;- // On donkeycut.com the settings routes are served same-host (see src/proxy.ts).- if (isDonkeycutHost(host)) return "/app/settings";- const apex = `${protocol}//${host.replace(/^cut\./, "")}`;- return `${apex}/app/settings`;+ if (typeof window === "undefined") return "/cut/app/settings";+ return `${cutAppBase(window.location.host)}/settings`;}/** Creation-time ownership for generated media, in one place so the rule can't