Skip to content

Open source CapCut alternative.

TypeScript

refactor(site): the super-user root opens the rail's first surface

David Le63809c7b937e
diff --git a/site/src/app/cut/app/su/SuHeader.tsx b/site/src/app/cut/app/su/SuHeader.tsx
index f0b5cebb..07401b04 100644
--- a/site/src/app/cut/app/su/SuHeader.tsx
+++ b/site/src/app/cut/app/su/SuHeader.tsx
@@ -5,19 +5,14 @@ import type { ComponentType } from "react";
import { RunAnalyticsButton } from "@/app/cut/app/su/analytics/RunAnalyticsButton";
-// Ordered so the more specific path wins the suffix match; Users is the
-// section root, so it's also the fallback title.
+// Every surface owns a path, so the match is exact; the rail's order is the
+// order here, and its first entry is what the section root opens.
const SECTIONS: {
suffix: string;
title: string;
description: string;
Action?: ComponentType;
}[] = [
- {
- suffix: "/su/credits",
- title: "Credits",
- description: "Grant credits to a user.",
- },
{
suffix: "/su/analytics",
title: "Analytics",
@@ -25,16 +20,21 @@ const SECTIONS: {
Action: RunAnalyticsButton,
},
{
- suffix: "/su",
+ suffix: "/su/users",
title: "Users",
description: "Account actions.",
},
+ {
+ suffix: "/su/credits",
+ title: "Credits",
+ description: "Grant credits to a user.",
+ },
];
export function SuHeader() {
const pathname = usePathname();
const section =
- SECTIONS.find((s) => pathname.endsWith(s.suffix)) ?? SECTIONS.at(-1)!;
+ SECTIONS.find((s) => pathname.endsWith(s.suffix)) ?? SECTIONS[0];
return (
<div className="sticky top-0 z-20 mx-auto flex w-full max-w-6xl shrink-0 items-start justify-between gap-4 bg-background px-10 pt-9 pb-5">
<div>
diff --git a/site/src/app/cut/app/su/SuSidebar.tsx b/site/src/app/cut/app/su/SuSidebar.tsx
index c9c66aa4..0708311c 100644
--- a/site/src/app/cut/app/su/SuSidebar.tsx
+++ b/site/src/app/cut/app/su/SuSidebar.tsx
@@ -2,17 +2,12 @@
import Link from "next/link";
import { usePathname } from "next/navigation";
-import { ArrowLeft, ChartColumn, CreditCard, UserRound } from "lucide-react";
+import { ArrowLeft } from "lucide-react";
+import { SU_NAV } from "@/app/cut/app/su/nav";
import { useCutBase } from "@/cut/lib/nav";
import { cn } from "@/lib/utils";
-const NAV: { suffix: string; label: string; icon: typeof UserRound }[] = [
- { suffix: "/analytics", label: "Analytics", icon: ChartColumn },
- { suffix: "", label: "Users", icon: UserRound },
- { suffix: "/credits", label: "Credits", icon: CreditCard },
-];
-
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";
@@ -38,7 +33,7 @@ export function SuSidebar() {
</div>
<nav className="flex flex-col gap-0.5">
- {NAV.map(({ suffix, label, icon: Icon }) => {
+ {SU_NAV.map(({ suffix, label, icon: Icon }) => {
const href = `${base}/su${suffix}`;
const active = pathname === href;
return (
diff --git a/site/src/app/cut/app/su/nav.ts b/site/src/app/cut/app/su/nav.ts
new file mode 100644
index 00000000..dc610e89
--- /dev/null
+++ b/site/src/app/cut/app/su/nav.ts
@@ -0,0 +1,9 @@
+import { ChartColumn, CreditCard, UserRound } from "lucide-react";
+
+// The super-user surfaces in rail order. The section root lands on the first
+// one, so reordering this list moves where /app/su opens.
+export const SU_NAV: { suffix: string; label: string; icon: typeof UserRound }[] = [
+ { suffix: "/analytics", label: "Analytics", icon: ChartColumn },
+ { suffix: "/users", label: "Users", icon: UserRound },
+ { suffix: "/credits", label: "Credits", icon: CreditCard },
+];
diff --git a/site/src/app/cut/app/su/page.tsx b/site/src/app/cut/app/su/page.tsx
index 1db706db..340a0c81 100644
--- a/site/src/app/cut/app/su/page.tsx
+++ b/site/src/app/cut/app/su/page.tsx
@@ -1,227 +1,9 @@
-"use client";
+import { redirect } from "next/navigation";
-import { useState } from "react";
-import { useQueryClient } from "@tanstack/react-query";
+import { CUT_APP_BASE } from "@/cut/lib/appBase";
+import { SU_NAV } from "./nav";
-import { Button } from "@/components/ui/button";
-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 { cn } from "@/lib/utils";
-import {
- recentJobsQueryKey,
- useRecentJobs,
- useStartJob,
- type AsyncJobListItem,
-} from "@/queries/jobs";
-
-// The list shows each job's stored payload and result as-is, so it stays
-// 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 "";
- return Object.entries(value)
- .filter(([, v]) => ["string", "number", "boolean"].includes(typeof v))
- .map(([k, v]) => `${k}: ${String(v)}`)
- .join(" · ");
-}
-
-// A finished delete-user job reads as one sentence; other kinds (and
-// unfinished jobs) keep the flattened raw fields.
-function doneSummary(item: AsyncJobListItem): string | null {
- if (item.kind !== "delete-user" || item.state !== "done") return null;
- const payload = item.payload as { email?: unknown } | null;
- const email = typeof payload?.email === "string" ? payload.email : "";
- const result = item.result;
- return (
- `Deleted ${email} — ${String(result?.projects ?? 0)} project(s), ` +
- `${String(result?.libraryAssets ?? 0)} library asset(s), ` +
- `${String(result?.r2Objects ?? 0)} stored object(s).`
- );
-}
-
-function formatWhen(iso: string): string {
- const then = new Date(iso);
- const mins = Math.floor((Date.now() - then.getTime()) / 60000);
- if (mins < 1) return "just now";
- if (mins < 60) return `${mins}m ago`;
- if (mins < 60 * 24) return `${Math.floor(mins / 60)}h ago`;
- return then.toLocaleDateString(undefined, { month: "short", day: "numeric" });
-}
-
-const stateDot: Record<AsyncJobListItem["state"], string> = {
- queued: "bg-muted-foreground/40",
- running: "bg-blue-500 animate-pulse",
- done: "bg-emerald-500",
- error: "bg-destructive",
-};
-
-// 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("");
-
- const target = email.trim();
- const confirmed = target !== "" && confirmEmail.trim() === target;
-
- const openConfirm = () => {
- setConfirmEmail("");
- setConfirmOpen(true);
- };
-
- const submit = () => {
- if (!confirmed) return;
- start.mutate(
- { kind: "delete-user", payload: { email: target } },
- {
- onSuccess: () => {
- setEmail("");
- setConfirmOpen(false);
- queryClient.invalidateQueries({ queryKey: recentJobsQueryKey });
- },
- },
- );
- };
-
- return (
- <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&apos;t start the delete — check the email and try again.
- </p>
- ) : null}
- </div>
- </div>
-
- <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">
- {recent.data.jobs.map((item) => (
- <li key={item.id} className="flex items-start gap-2.5">
- <span
- className={cn(
- "mt-1.5 size-2 shrink-0 rounded-full",
- stateDot[item.state],
- )}
- />
- <div className="min-w-0 text-sm">
- <div className="flex flex-wrap items-baseline gap-x-2">
- <span className="font-medium">{item.kind}</span>
- <span className="text-muted-foreground">{item.state}</span>
- <span className="text-muted-foreground">
- {formatWhen(item.createdAt)}
- </span>
- </div>
- {doneSummary(item) ? (
- <p className="text-muted-foreground">{doneSummary(item)}</p>
- ) : (
- <>
- {describeFields(item.payload) ? (
- <p className="truncate text-muted-foreground">
- {describeFields(item.payload)}
- </p>
- ) : null}
- {item.state === "done" && describeFields(item.result) ? (
- <p className="truncate text-muted-foreground">
- {describeFields(item.result)}
- </p>
- ) : null}
- </>
- )}
- {item.state === "error" && item.error ? (
- <p className="text-destructive">{item.error}</p>
- ) : null}
- </div>
- </li>
- ))}
- </ul>
- ) : (
- <p className="mt-3 text-sm text-muted-foreground">
- {recent.isPending ? "Loading…" : "No jobs yet."}
- </p>
- )}
- </div>
-
- <Dialog onOpenChange={setConfirmOpen} open={confirmOpen}>
- <DialogContent>
- <DialogHeader>
- <DialogTitle>Delete {target}?</DialogTitle>
- <DialogDescription>
- This permanently deletes the account and all of its data. Type
- to confirm.
- </DialogDescription>
- </DialogHeader>
- <div className="space-y-2">
- <Label htmlFor="delete-user-confirm">Email</Label>
- <Input
- autoComplete="off"
- id="delete-user-confirm"
- onChange={(event) => setConfirmEmail(event.target.value)}
- placeholder={target}
- type="email"
- value={confirmEmail}
- />
- </div>
- <DialogFooter>
- <DialogClose render={<Button variant="outline" />}>
- Cancel
- </DialogClose>
- <Button
- disabled={!confirmed || start.isPending}
- onClick={submit}
- variant="destructive"
- >
- {start.isPending ? "Starting…" : "Delete everything"}
- </Button>
- </DialogFooter>
- </DialogContent>
- </Dialog>
- </div>
- );
+// The section root has no surface of its own; it opens the rail's first one.
+export default function SuPage() {
+ redirect(`${CUT_APP_BASE}/su${SU_NAV[0].suffix}`);
}
diff --git a/site/src/app/cut/app/su/users/page.tsx b/site/src/app/cut/app/su/users/page.tsx
new file mode 100644
index 00000000..1db706db
--- /dev/null
+++ b/site/src/app/cut/app/su/users/page.tsx
@@ -0,0 +1,227 @@
+"use client";
+
+import { useState } from "react";
+import { useQueryClient } from "@tanstack/react-query";
+
+import { Button } from "@/components/ui/button";
+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 { cn } from "@/lib/utils";
+import {
+ recentJobsQueryKey,
+ useRecentJobs,
+ useStartJob,
+ type AsyncJobListItem,
+} from "@/queries/jobs";
+
+// The list shows each job's stored payload and result as-is, so it stays
+// 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 "";
+ return Object.entries(value)
+ .filter(([, v]) => ["string", "number", "boolean"].includes(typeof v))
+ .map(([k, v]) => `${k}: ${String(v)}`)
+ .join(" · ");
+}
+
+// A finished delete-user job reads as one sentence; other kinds (and
+// unfinished jobs) keep the flattened raw fields.
+function doneSummary(item: AsyncJobListItem): string | null {
+ if (item.kind !== "delete-user" || item.state !== "done") return null;
+ const payload = item.payload as { email?: unknown } | null;
+ const email = typeof payload?.email === "string" ? payload.email : "";
+ const result = item.result;
+ return (
+ `Deleted ${email} — ${String(result?.projects ?? 0)} project(s), ` +
+ `${String(result?.libraryAssets ?? 0)} library asset(s), ` +
+ `${String(result?.r2Objects ?? 0)} stored object(s).`
+ );
+}
+
+function formatWhen(iso: string): string {
+ const then = new Date(iso);
+ const mins = Math.floor((Date.now() - then.getTime()) / 60000);
+ if (mins < 1) return "just now";
+ if (mins < 60) return `${mins}m ago`;
+ if (mins < 60 * 24) return `${Math.floor(mins / 60)}h ago`;
+ return then.toLocaleDateString(undefined, { month: "short", day: "numeric" });
+}
+
+const stateDot: Record<AsyncJobListItem["state"], string> = {
+ queued: "bg-muted-foreground/40",
+ running: "bg-blue-500 animate-pulse",
+ done: "bg-emerald-500",
+ error: "bg-destructive",
+};
+
+// 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("");
+
+ const target = email.trim();
+ const confirmed = target !== "" && confirmEmail.trim() === target;
+
+ const openConfirm = () => {
+ setConfirmEmail("");
+ setConfirmOpen(true);
+ };
+
+ const submit = () => {
+ if (!confirmed) return;
+ start.mutate(
+ { kind: "delete-user", payload: { email: target } },
+ {
+ onSuccess: () => {
+ setEmail("");
+ setConfirmOpen(false);
+ queryClient.invalidateQueries({ queryKey: recentJobsQueryKey });
+ },
+ },
+ );
+ };
+
+ return (
+ <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&apos;t start the delete — check the email and try again.
+ </p>
+ ) : null}
+ </div>
+ </div>
+
+ <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">
+ {recent.data.jobs.map((item) => (
+ <li key={item.id} className="flex items-start gap-2.5">
+ <span
+ className={cn(
+ "mt-1.5 size-2 shrink-0 rounded-full",
+ stateDot[item.state],
+ )}
+ />
+ <div className="min-w-0 text-sm">
+ <div className="flex flex-wrap items-baseline gap-x-2">
+ <span className="font-medium">{item.kind}</span>
+ <span className="text-muted-foreground">{item.state}</span>
+ <span className="text-muted-foreground">
+ {formatWhen(item.createdAt)}
+ </span>
+ </div>
+ {doneSummary(item) ? (
+ <p className="text-muted-foreground">{doneSummary(item)}</p>
+ ) : (
+ <>
+ {describeFields(item.payload) ? (
+ <p className="truncate text-muted-foreground">
+ {describeFields(item.payload)}
+ </p>
+ ) : null}
+ {item.state === "done" && describeFields(item.result) ? (
+ <p className="truncate text-muted-foreground">
+ {describeFields(item.result)}
+ </p>
+ ) : null}
+ </>
+ )}
+ {item.state === "error" && item.error ? (
+ <p className="text-destructive">{item.error}</p>
+ ) : null}
+ </div>
+ </li>
+ ))}
+ </ul>
+ ) : (
+ <p className="mt-3 text-sm text-muted-foreground">
+ {recent.isPending ? "Loading…" : "No jobs yet."}
+ </p>
+ )}
+ </div>
+
+ <Dialog onOpenChange={setConfirmOpen} open={confirmOpen}>
+ <DialogContent>
+ <DialogHeader>
+ <DialogTitle>Delete {target}?</DialogTitle>
+ <DialogDescription>
+ This permanently deletes the account and all of its data. Type
+ to confirm.
+ </DialogDescription>
+ </DialogHeader>
+ <div className="space-y-2">
+ <Label htmlFor="delete-user-confirm">Email</Label>
+ <Input
+ autoComplete="off"
+ id="delete-user-confirm"
+ onChange={(event) => setConfirmEmail(event.target.value)}
+ placeholder={target}
+ type="email"
+ value={confirmEmail}
+ />
+ </div>
+ <DialogFooter>
+ <DialogClose render={<Button variant="outline" />}>
+ Cancel
+ </DialogClose>
+ <Button
+ disabled={!confirmed || start.isPending}
+ onClick={submit}
+ variant="destructive"
+ >
+ {start.isPending ? "Starting…" : "Delete everything"}
+ </Button>
+ </DialogFooter>
+ </DialogContent>
+ </Dialog>
+ </div>
+ );
+}
diff --git a/site/src/cut/lib/appBase.ts b/site/src/cut/lib/appBase.ts
new file mode 100644
index 00000000..bfec968c
--- /dev/null
+++ b/site/src/cut/lib/appBase.ts
@@ -0,0 +1,4 @@
+// The Cut app's routes live under /cut/app/*; the proxy rewrite (src/proxy.ts)
+// serves them at "/app/…" on every host, so that is the base every in-app href
+// is built on. It sits in its own module so server components can read it too.
+export const CUT_APP_BASE = "/app";
diff --git a/site/src/cut/lib/nav.tsx b/site/src/cut/lib/nav.tsx
index 3691afb6..e85ee357 100644
--- a/site/src/cut/lib/nav.tsx
+++ b/site/src/cut/lib/nav.tsx
@@ -1,9 +1,8 @@
"use client";
-// The Cut app's routes live under /cut/app/*; the proxy rewrite (src/proxy.ts)
-// serves them at "/app/…" on every host, so that is the base every in-app
-// href is built on.
-export const CUT_APP_BASE = "/app";
+import { CUT_APP_BASE } from "./appBase";
+
+export { CUT_APP_BASE };
export function useCutBase(): string {
return CUT_APP_BASE;