Open source CapCut alternative.
TypeScript
feat(site): move super-user tools to a URL-only /app/su section
David Le94946824f163
diff --git a/site/src/app/cut/app/(home)/settings/_components/SuperuserCreditsCard.tsx b/site/src/app/cut/app/(home)/settings/_components/SuperuserCreditsCard.tsxdeleted file mode 100644index f43122e0..00000000--- a/site/src/app/cut/app/(home)/settings/_components/SuperuserCreditsCard.tsx+++ /dev/null@@ -1,179 +0,0 @@-"use client";--import { useState } from "react";--import { Button } from "@/components/ui/button";-import {- Card,- CardContent,- CardDescription,- CardHeader,- CardTitle,-} from "@/components/ui/card";-import {- Dialog,- DialogClose,- DialogContent,- DialogDescription,- DialogFooter,- DialogHeader,- DialogTitle,-} from "@/components/ui/dialog";-import { Input } from "@/components/ui/input";-import { Label } from "@/components/ui/label";-import {- creditTopUpDefaultDollars,- creditTopUpPresetsDollars,- maxCreditGrantDollars,-} from "@/lib/credits/top-up";-import { useAccount, useGrantCredits } from "@/queries/credits";--// Quick-pick amounts mirror the pay-as-you-go presets; super users can also type-// a custom dollar value. The grant route caps a single grant at-// maxCreditGrantDollars to guard against typos.-const presetDollars = creditTopUpPresetsDollars;--export function SuperuserCreditsCard() {- const account = useAccount();- const grant = useGrantCredits();- // null means "use the current user's email as the default recipient"; once the- // super user edits the field we track their override here.- const [emailOverride, setEmailOverride] = useState<string | null>(null);- const [amount, setAmount] = useState(String(creditTopUpDefaultDollars));- const [confirmOpen, setConfirmOpen] = useState(false);- const [lastResult, setLastResult] = useState<string | null>(null);-- // Render nothing for non-super users (and while we don't yet know).- if (!account.data?.superUser) {- return null;- }-- // The field shows the user's own email by default; only treat it as a target- // when the super user actually overrides it. An unedited (or cleared) field- // grants to self by the authoritative userId, not by re-resolving the email.- const email = emailOverride ?? account.data.email ?? "";- const overrideEmail = emailOverride?.trim() ?? "";- const grantingToSelf = overrideEmail === "";- const recipientLabel = grantingToSelf ? "your account" : overrideEmail;-- const amountDollars = Number(amount);- const amountValid =- Number.isInteger(amountDollars) &&- amountDollars > 0 &&- amountDollars <= maxCreditGrantDollars;-- const submit = () => {- if (!amountValid) {- return;- }- setLastResult(null);- grant.mutate(- {- amountDollars,- ...(grantingToSelf- ? { userId: account.data.userId }- : { email: overrideEmail }),- },- {- onSuccess: (result) => {- setLastResult(- `Added $${amountDollars} to ${result.targetUser.email} — new balance $${result.balance.balance}.`,- );- // Reset back to the default recipient (the current user).- setEmailOverride(null);- setConfirmOpen(false);- },- },- );- };-- return (- <Card>- <CardHeader>- <CardTitle className="flex items-center gap-2">- Super user · Credits- </CardTitle>- <CardDescription>- Defaults to your account — change the recipient to grant to another- user. Visible to super users only.- </CardDescription>- </CardHeader>- <CardContent className="space-y-5">- <div className="space-y-2">- <Label htmlFor="grant-email">Recipient</Label>- <Input- className="max-w-xs"- id="grant-email"- onChange={(event) => setEmailOverride(event.target.value)}- placeholder="[email protected]"- type="email"- value={email}- />- </div>-- <div className="space-y-2">- <Label htmlFor="grant-amount">Amount (USD)</Label>- <div className="flex flex-wrap items-center gap-2">- {presetDollars.map((preset) => (- <Button- key={preset}- onClick={() => setAmount(String(preset))}- type="button"- variant={amount === String(preset) ? "default" : "outline"}- >- ${preset}- </Button>- ))}- <Input- className="max-w-[7rem]"- id="grant-amount"- max={maxCreditGrantDollars}- min={1}- onChange={(event) => setAmount(event.target.value)}- placeholder="Custom"- type="number"- value={amount}- />- </div>- </div>-- <Button- disabled={grant.isPending || !amountValid}- onClick={() => setConfirmOpen(true)}- >- {grant.isPending ? "Granting…" : `Grant $${amountDollars}`}- </Button>-- <Dialog onOpenChange={setConfirmOpen} open={confirmOpen}>- <DialogContent>- <DialogHeader>- <DialogTitle>Confirm credit grant</DialogTitle>- <DialogDescription>- Grant <span className="font-medium">${amountDollars}</span> in- credits to{" "}- <span className="font-medium">{recipientLabel}</span>?- </DialogDescription>- </DialogHeader>- <DialogFooter>- <DialogClose render={<Button variant="outline" />}>- Cancel- </DialogClose>- <Button disabled={grant.isPending} onClick={submit}>- {grant.isPending ? "Granting…" : `Grant $${amountDollars}`}- </Button>- </DialogFooter>- </DialogContent>- </Dialog>-- {lastResult ? (- <p className="text-sm text-muted-foreground">{lastResult}</p>- ) : null}- {grant.isError ? (- <p className="text-sm text-destructive">- Grant failed. Check the email and amount, then try again.- </p>- ) : null}- </CardContent>- </Card>- );-}diff --git a/site/src/app/cut/app/(home)/settings/page.tsx b/site/src/app/cut/app/(home)/settings/page.tsxindex f6c20c39..66e0c5a4 100644--- a/site/src/app/cut/app/(home)/settings/page.tsx+++ b/site/src/app/cut/app/(home)/settings/page.tsx@@ -2,7 +2,6 @@import { CreditsCard } from "@/app/cut/app/(home)/settings/_components/CreditsCard";import { ProCard } from "@/app/cut/app/(home)/settings/_components/ProCard";-import { SuperuserCreditsCard } from "@/app/cut/app/(home)/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@@ -12,7 +11,6 @@ export default function CutBillingPage() {<div className="max-w-2xl space-y-6 pb-9"><ProCard /><CreditsCard />- <SuperuserCreditsCard /></div>);}diff --git a/site/src/app/cut/app/(home)/settings/profile/page.tsx b/site/src/app/cut/app/(home)/settings/profile/page.tsxindex 4a1f3e35..84c08377 100644--- a/site/src/app/cut/app/(home)/settings/profile/page.tsx+++ b/site/src/app/cut/app/(home)/settings/profile/page.tsx@@ -6,7 +6,6 @@ import { Pencil } from "lucide-react";import { AvatarDialog } from "@/app/cut/app/(home)/settings/profile/AvatarDialog";import { EmailSection } from "@/app/cut/app/(home)/settings/profile/EmailSection";import { FeatureFlagsSection } from "@/app/cut/app/(home)/settings/profile/FeatureFlagsSection";-import { SuperuserSection } from "@/app/cut/app/(home)/settings/profile/SuperuserSection";import { Button } from "@/components/ui/button";import { Input } from "@/components/ui/input";import { Label } from "@/components/ui/label";@@ -127,8 +126,6 @@ export default function CutProfilePage() {<FeatureFlagsSection />- <SuperuserSection />-<AvatarDialogopen={editingAvatar}onOpenChange={setEditingAvatar}diff --git a/site/src/app/cut/app/su/SuHeader.tsx b/site/src/app/cut/app/su/SuHeader.tsxnew file mode 100644index 00000000..79996826--- /dev/null+++ b/site/src/app/cut/app/su/SuHeader.tsx@@ -0,0 +1,35 @@+"use client";++import { usePathname } from "next/navigation";++// Ordered so the more specific path wins the suffix match; Users is the+// section root, so it's also the fallback title.+const SECTIONS = [+ {+ suffix: "/su/credits",+ title: "Credits",+ description: "Grant credits to a user.",+ },+ {+ suffix: "/su/analytics",+ title: "Analytics",+ description: "Product analytics.",+ },+ {+ suffix: "/su",+ title: "Users",+ description: "Account actions.",+ },+];++export function SuHeader() {+ const pathname = usePathname();+ const section =+ SECTIONS.find((s) => pathname.endsWith(s.suffix)) ?? SECTIONS.at(-1)!;+ return (+ <div className="sticky top-0 z-20 mx-auto w-full max-w-6xl shrink-0 bg-background px-10 pt-9 pb-5">+ <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/su/SuSidebar.tsx b/site/src/app/cut/app/su/SuSidebar.tsxnew file mode 100644index 00000000..1b8501c3--- /dev/null+++ b/site/src/app/cut/app/su/SuSidebar.tsx@@ -0,0 +1,65 @@+"use client";++import Link from "next/link";+import { usePathname } from "next/navigation";+import { ArrowLeft, ChartColumn, CreditCard, UserRound } from "lucide-react";++import { useCutBase } from "@/cut/lib/nav";+import { cn } from "@/lib/utils";++const NAV: { suffix: string; label: string; icon: typeof UserRound }[] = [+ { suffix: "", label: "Users", icon: UserRound },+ { suffix: "/credits", label: "Credits", icon: CreditCard },+ { suffix: "/analytics", label: "Analytics", icon: ChartColumn },+];++const itemClass =+ "flex items-center gap-2.5 rounded-lg px-2.5 py-2 text-sm font-medium text-muted-foreground transition-colors hover:bg-muted hover:text-foreground";++// The super-user section's left rail: same shell as the app sidebar, with the+// admin surfaces as tabs and a way back to the app pinned to the bottom.+export function SuSidebar() {+ const pathname = usePathname();+ const base = useCutBase();++ return (+ <aside className="flex w-60 shrink-0 flex-col border-r border-border bg-card px-3 py-4">+ <div className="mb-5 flex items-center gap-2.5 px-2">+ <span className="grid size-9 shrink-0 place-items-center p-0.5">+ <img+ src="/donkey-logo.svg"+ alt="Donkey Cut"+ width={36}+ height={36}+ className="block h-full w-full object-contain"+ />+ </span>+ <span className="text-[17px] font-semibold tracking-tight">Super user</span>+ </div>++ <nav className="flex flex-col gap-0.5">+ {NAV.map(({ suffix, label, icon: Icon }) => {+ const href = `${base}/su${suffix}`;+ const active = pathname === href;+ return (+ <Link+ key={label}+ href={href}+ className={cn(itemClass, active && "bg-muted text-foreground")}+ >+ <Icon className="size-4" />+ {label}+ </Link>+ );+ })}+ </nav>++ <div className="mt-auto flex flex-col">+ <Link href={base} className={itemClass}>+ <ArrowLeft className="size-4" />+ Back to app+ </Link>+ </div>+ </aside>+ );+}diff --git a/site/src/app/cut/app/su/analytics/page.tsx b/site/src/app/cut/app/su/analytics/page.tsxnew file mode 100644index 00000000..6f3989cf--- /dev/null+++ b/site/src/app/cut/app/su/analytics/page.tsx@@ -0,0 +1,12 @@+"use client";++// Placeholder while the analytics surface is built out.+export default function SuAnalyticsPage() {+ return (+ <div className="max-w-2xl space-y-6 pb-9">+ <div className="rounded-xl border bg-card p-5">+ <p className="text-sm text-muted-foreground">Nothing here yet.</p>+ </div>+ </div>+ );+}diff --git a/site/src/app/cut/app/su/credits/page.tsx b/site/src/app/cut/app/su/credits/page.tsxnew file mode 100644index 00000000..e0a81781--- /dev/null+++ b/site/src/app/cut/app/su/credits/page.tsx@@ -0,0 +1,180 @@+"use client";++import { useState } from "react";++import { Button } from "@/components/ui/button";+import {+ Card,+ CardContent,+ CardDescription,+ CardHeader,+ CardTitle,+} from "@/components/ui/card";+import {+ Dialog,+ DialogClose,+ DialogContent,+ DialogDescription,+ DialogFooter,+ DialogHeader,+ DialogTitle,+} from "@/components/ui/dialog";+import { Input } from "@/components/ui/input";+import { Label } from "@/components/ui/label";+import {+ creditTopUpDefaultDollars,+ creditTopUpPresetsDollars,+ maxCreditGrantDollars,+} from "@/lib/credits/top-up";+import { useAccount, useGrantCredits } from "@/queries/credits";++// Quick-pick amounts mirror the pay-as-you-go presets; super users can also type+// a custom dollar value. The grant route caps a single grant at+// maxCreditGrantDollars to guard against typos.+const presetDollars = creditTopUpPresetsDollars;++export default function SuCreditsPage() {+ const account = useAccount();+ const grant = useGrantCredits();+ // null means "use the current user's email as the default recipient"; once the+ // super user edits the field we track their override here.+ const [emailOverride, setEmailOverride] = useState<string | null>(null);+ const [amount, setAmount] = useState(String(creditTopUpDefaultDollars));+ const [confirmOpen, setConfirmOpen] = useState(false);+ const [lastResult, setLastResult] = useState<string | null>(null);++ // The layout gates this route to super users; this only bridges the beat+ // before the cached account data lands.+ if (!account.data) {+ return null;+ }++ // The field shows the user's own email by default; only treat it as a target+ // when the super user actually overrides it. An unedited (or cleared) field+ // grants to self by the authoritative userId, not by re-resolving the email.+ const email = emailOverride ?? account.data.email ?? "";+ const overrideEmail = emailOverride?.trim() ?? "";+ const grantingToSelf = overrideEmail === "";+ const recipientLabel = grantingToSelf ? "your account" : overrideEmail;++ const amountDollars = Number(amount);+ const amountValid =+ Number.isInteger(amountDollars) &&+ amountDollars > 0 &&+ amountDollars <= maxCreditGrantDollars;++ const submit = () => {+ if (!amountValid) {+ return;+ }+ setLastResult(null);+ grant.mutate(+ {+ amountDollars,+ ...(grantingToSelf+ ? { userId: account.data.userId }+ : { email: overrideEmail }),+ },+ {+ onSuccess: (result) => {+ setLastResult(+ `Added $${amountDollars} to ${result.targetUser.email} — new balance $${result.balance.balance}.`,+ );+ // Reset back to the default recipient (the current user).+ setEmailOverride(null);+ setConfirmOpen(false);+ },+ },+ );+ };++ return (+ <div className="max-w-2xl space-y-6 pb-9">+ <Card>+ <CardHeader>+ <CardTitle>Grant credits</CardTitle>+ <CardDescription>+ Defaults to your account — change the recipient to grant to another+ user.+ </CardDescription>+ </CardHeader>+ <CardContent className="space-y-5">+ <div className="space-y-2">+ <Label htmlFor="grant-email">Recipient</Label>+ <Input+ className="max-w-xs"+ id="grant-email"+ onChange={(event) => setEmailOverride(event.target.value)}+ placeholder="[email protected]"+ type="email"+ value={email}+ />+ </div>++ <div className="space-y-2">+ <Label htmlFor="grant-amount">Amount (USD)</Label>+ <div className="flex flex-wrap items-center gap-2">+ {presetDollars.map((preset) => (+ <Button+ key={preset}+ onClick={() => setAmount(String(preset))}+ type="button"+ variant={amount === String(preset) ? "default" : "outline"}+ >+ ${preset}+ </Button>+ ))}+ <Input+ className="max-w-[7rem]"+ id="grant-amount"+ max={maxCreditGrantDollars}+ min={1}+ onChange={(event) => setAmount(event.target.value)}+ placeholder="Custom"+ type="number"+ value={amount}+ />+ </div>+ </div>++ <Button+ disabled={grant.isPending || !amountValid}+ onClick={() => setConfirmOpen(true)}+ >+ {grant.isPending ? "Granting…" : `Grant $${amountDollars}`}+ </Button>++ <Dialog onOpenChange={setConfirmOpen} open={confirmOpen}>+ <DialogContent>+ <DialogHeader>+ <DialogTitle>Confirm credit grant</DialogTitle>+ <DialogDescription>+ Grant <span className="font-medium">${amountDollars}</span> in+ credits to{" "}+ <span className="font-medium">{recipientLabel}</span>?+ </DialogDescription>+ </DialogHeader>+ <DialogFooter>+ <DialogClose render={<Button variant="outline" />}>+ Cancel+ </DialogClose>+ <Button disabled={grant.isPending} onClick={submit}>+ {grant.isPending ? "Granting…" : `Grant $${amountDollars}`}+ </Button>+ </DialogFooter>+ </DialogContent>+ </Dialog>++ {lastResult ? (+ <p className="text-sm text-muted-foreground">{lastResult}</p>+ ) : null}+ {grant.isError ? (+ <p className="text-sm text-destructive">+ Grant failed. Check the email and amount, then try again.+ </p>+ ) : null}+ </CardContent>+ </Card>+ </div>+ );+}diff --git a/site/src/app/cut/app/su/layout.tsx b/site/src/app/cut/app/su/layout.tsxnew file mode 100644index 00000000..ba66918e--- /dev/null+++ b/site/src/app/cut/app/su/layout.tsx@@ -0,0 +1,49 @@+"use client";++import { useEffect, type ReactNode } from "react";+import { useRouter } from "next/navigation";++import { SuHeader } from "@/app/cut/app/su/SuHeader";+import { SuSidebar } from "@/app/cut/app/su/SuSidebar";+import { Skeleton } from "@/components/ui/skeleton";+import { useCutBase } from "@/cut/lib/nav";+import { useAccount } from "@/queries/credits";++// The super-user section: its own left rail with the admin surfaces as tabs,+// page details on the right. Everyone else is sent back to the app root — the+// client gate is for UX; the routes these pages call are withSuperUser and+// enforce the role server-side.+export default function SuLayout({ children }: { children: ReactNode }) {+ const router = useRouter();+ const base = useCutBase();+ const account = useAccount();+ const superUser = account.data?.superUser === true;++ useEffect(() => {+ if (account.isPending || superUser) return;+ router.replace(base);+ }, [account.isPending, superUser, router, base]);++ if (!superUser) {+ 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 (+ <div className="flex h-full bg-background">+ <SuSidebar />+ <main className="flex min-w-0 flex-1 flex-col overflow-y-auto">+ <SuHeader />+ <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>+ </main>+ </div>+ );+}diff --git a/site/src/app/cut/app/(home)/settings/profile/SuperuserSection.tsx b/site/src/app/cut/app/su/page.tsxsimilarity index 74%rename from site/src/app/cut/app/(home)/settings/profile/SuperuserSection.tsxrename to site/src/app/cut/app/su/page.tsxindex 815fa10c..1db706db 100644--- a/site/src/app/cut/app/(home)/settings/profile/SuperuserSection.tsx+++ b/site/src/app/cut/app/su/page.tsx@@ -16,7 +16,6 @@ import {import { Input } from "@/components/ui/input";import { Label } from "@/components/ui/label";import { cn } from "@/lib/utils";-import { useAccount } from "@/queries/credits";import {recentJobsQueryKey,useRecentJobs,@@ -25,7 +24,7 @@ import {} from "@/queries/jobs";// The list shows each job's stored payload and result as-is, so it stays-// honest for job kinds this card doesn't know about: flatten the primitive+// honest for job kinds this page doesn't know about: flatten the primitive// fields into "email: [email protected] · projects: 3".function describeFields(value: unknown): string {if (typeof value !== "object" || value === null) return "";@@ -65,28 +64,19 @@ const stateDot: Record<AsyncJobListItem["state"], string> = {error: "bg-destructive",};-// Super-user tooling on the profile page. Today: delete a user and everything-// they own, for cleaning production test accounts out of the data. The delete-// runs as a background job on the hosted API; this card starts it, and the-// recent-jobs list below tracks it to completion. The confirm dialog makes-// the super user retype the email so a paste-slip can't take out the wrong-// account.-export function SuperuserSection() {- const account = useAccount();+// User actions. Today: delete a user and everything they own, for cleaning+// production test accounts out of the data. The delete runs as a background+// job on the hosted API; this page starts it, and the recent-jobs list below+// tracks it to completion. The confirm dialog makes the super user retype the+// email so a paste-slip can't take out the wrong account. The layout gates+// this route to super users, so the job hooks run unconditionally here.+export default function SuUsersPage() {const queryClient = useQueryClient();const start = useStartJob();+ const recent = useRecentJobs(true);const [email, setEmail] = useState("");const [confirmOpen, setConfirmOpen] = useState(false);const [confirmEmail, setConfirmEmail] = useState("");- // The jobs hook is gated so a non-super user's browser never calls the- // job APIs at all.- const superUser = account.data?.superUser === true;- const recent = useRecentJobs(superUser);-- // Render nothing for non-super users (and while we don't yet know).- if (!superUser) {- return null;- }const target = email.trim();const confirmed = target !== "" && confirmEmail.trim() === target;@@ -111,43 +101,44 @@ export function SuperuserSection() {};return (- <div className="rounded-xl border bg-card p-5">- <div className="text-sm font-medium">Super user</div>- <div className="mt-4 space-y-3 border-t pt-4">- <div>- <div className="text-sm font-medium">Delete user</div>- <p className="mt-0.5 text-sm text-muted-foreground">- Permanently deletes the account and everything it owns — projects,- media, credits, and billing.- </p>- </div>- <div className="flex items-center gap-2">- <Input- aria-label="User email"- className="max-w-xs"- id="delete-user-email"- onChange={(event) => setEmail(event.target.value)}- placeholder="[email protected]"- type="email"- value={email}- />- <Button- disabled={target === "" || start.isPending}- onClick={openConfirm}- variant="destructive"- >- Delete User- </Button>- </div>+ <div className="max-w-2xl space-y-6 pb-9">+ <div className="rounded-xl border bg-card p-5">+ <div className="space-y-3">+ <div>+ <div className="text-sm font-medium">Delete user</div>+ <p className="mt-0.5 text-sm text-muted-foreground">+ Permanently deletes the account and everything it owns — projects,+ media, credits, and billing.+ </p>+ </div>+ <div className="flex items-center gap-2">+ <Input+ aria-label="User email"+ className="max-w-xs"+ id="delete-user-email"+ onChange={(event) => setEmail(event.target.value)}+ placeholder="[email protected]"+ type="email"+ value={email}+ />+ <Button+ disabled={target === "" || start.isPending}+ onClick={openConfirm}+ variant="destructive"+ >+ Delete User+ </Button>+ </div>- {start.isError ? (- <p className="text-sm text-destructive">- Couldn't start the delete — check the email and try again.- </p>- ) : null}+ {start.isError ? (+ <p className="text-sm text-destructive">+ Couldn't start the delete — check the email and try again.+ </p>+ ) : null}+ </div></div>- <div className="mt-4 border-t pt-4">+ <div className="rounded-xl border bg-card p-5"><div className="text-sm font-medium">Recent jobs</div>{recent.data?.jobs.length ? (<ul className="mt-3 space-y-3">