TypeScript
refactor(web): share standalone page layout (#12354)
Julius Marmingefa2decfce7fa
diff --git a/apps/web/src/components/auth/AuthSurfaceShell.tsx b/apps/web/src/components/auth/AuthSurfaceShell.tsxindex 1c45c98a9e4..ed27bd482a5 100644--- a/apps/web/src/components/auth/AuthSurfaceShell.tsx+++ b/apps/web/src/components/auth/AuthSurfaceShell.tsx@@ -2,22 +2,18 @@ import type { ReactNode } from "react";import { APP_DISPLAY_NAME, APP_STAGE_LABEL } from "../../branding";import { resolveSidebarStageBackdropVariant, StageBackdropArt } from "../SidebarStageBackdrop";+import { StandalonePage } from "../ui/standalone-page";/**- * Full-screen card for standalone auth pages, mirroring the pairing surface's- * treatment. Used by the CLI-connect authorize and callback surfaces.+ * Branded masthead for the CLI-connect authorize and callback pages.*/export function AuthSurfaceShell({ children }: { readonly children: ReactNode }) {const stageVariant = resolveSidebarStageBackdropVariant(APP_STAGE_LABEL);return (- <div className="relative flex min-h-screen items-center justify-center overflow-hidden bg-background px-4 py-10 text-foreground sm:px-6">- <div className="pointer-events-none absolute inset-0 opacity-80">- <div className="absolute inset-x-0 top-0 h-72 bg-[radial-gradient(48rem_20rem_at_top,color-mix(in_srgb,var(--color-blue-500)_12%,transparent),transparent)]" />- <div className="absolute inset-0 bg-[linear-gradient(145deg,color-mix(in_srgb,var(--background)_94%,var(--color-black))_0%,var(--background)_62%)]" />- </div>-- <section className="relative w-full max-w-xl overflow-hidden rounded-2xl border border-border/80 bg-card/94 shadow-2xl shadow-black/20 backdrop-blur-md">+ <StandalonePage+ tone="brand"+ masthead={<header className="relative h-24 overflow-hidden bg-[linear-gradient(135deg,#1e61de,#17348e)] text-white">{stageVariant ? (<div className="absolute inset-0" aria-hidden>@@ -36,9 +32,9 @@ export function AuthSurfaceShell({ children }: { readonly children: ReactNode })</p></div></header>-- <div className="p-6 sm:p-8">{children}</div>- </section>- </div>+ }+ >+ {children}+ </StandalonePage>);}diff --git a/apps/web/src/components/auth/PairingRouteSurface.tsx b/apps/web/src/components/auth/PairingRouteSurface.tsxindex 59288506569..cad11af57fc 100644--- a/apps/web/src/components/auth/PairingRouteSurface.tsx+++ b/apps/web/src/components/auth/PairingRouteSurface.tsx@@ -12,29 +12,18 @@ import {import { readHostedPairingRequest } from "../../hostedPairing";import { Button } from "../ui/button";import { Input } from "../ui/input";+import { StandalonePage, StandalonePageHeader } from "../ui/standalone-page";import { useAtomCommand } from "../../state/use-atom-command";export function PairingPendingSurface() {return (- <div className="relative flex min-h-screen items-center justify-center overflow-hidden bg-background px-4 py-10 text-foreground sm:px-6">- <div className="pointer-events-none absolute inset-0 opacity-80">- <div className="absolute inset-x-0 top-0 h-44 bg-[radial-gradient(44rem_16rem_at_top,color-mix(in_srgb,var(--color-emerald-500)_14%,transparent),transparent)]" />- <div className="absolute inset-y-0 left-0 w-72 bg-[radial-gradient(28rem_18rem_at_left,color-mix(in_srgb,var(--color-sky-500)_10%,transparent),transparent)]" />- <div className="absolute inset-0 bg-[linear-gradient(145deg,color-mix(in_srgb,var(--background)_90%,var(--color-black))_0%,var(--background)_55%)]" />- </div>-- <section className="relative w-full max-w-xl rounded-2xl border border-border/80 bg-card/90 p-6 shadow-2xl shadow-black/20 backdrop-blur-md sm:p-8">- <p className="text-[11px] font-semibold tracking-[0.18em] text-muted-foreground uppercase">- {APP_DISPLAY_NAME}- </p>- <h1 className="mt-3 text-2xl font-semibold tracking-tight sm:text-3xl">- Pairing with this environment- </h1>- <p className="mt-2 text-sm leading-relaxed text-muted-foreground">- Validating the pairing link and preparing your session.- </p>- </section>- </div>+ <StandalonePage tone="pairing">+ <StandalonePageHeader+ eyebrow={APP_DISPLAY_NAME}+ title="Pairing with this environment"+ description="Validating the pairing link and preparing your session."+ />+ </StandalonePage>);}@@ -97,69 +86,57 @@ export function PairingRouteSurface({}, [submitCredential]);return (- <div className="relative flex min-h-screen items-center justify-center overflow-hidden bg-background px-4 py-10 text-foreground sm:px-6">- <div className="pointer-events-none absolute inset-0 opacity-80">- <div className="absolute inset-x-0 top-0 h-44 bg-[radial-gradient(44rem_16rem_at_top,color-mix(in_srgb,var(--color-emerald-500)_14%,transparent),transparent)]" />- <div className="absolute inset-y-0 left-0 w-72 bg-[radial-gradient(28rem_18rem_at_left,color-mix(in_srgb,var(--color-sky-500)_10%,transparent),transparent)]" />- <div className="absolute inset-0 bg-[linear-gradient(145deg,color-mix(in_srgb,var(--background)_90%,var(--color-black))_0%,var(--background)_55%)]" />- </div>-- <section className="relative w-full max-w-xl rounded-2xl border border-border/80 bg-card/90 p-6 shadow-2xl shadow-black/20 backdrop-blur-md sm:p-8">- <p className="text-[11px] font-semibold tracking-[0.18em] text-muted-foreground uppercase">- {APP_DISPLAY_NAME}- </p>- <h1 className="mt-3 text-2xl font-semibold tracking-tight sm:text-3xl">- Pair with this environment- </h1>- <p className="mt-2 text-sm leading-relaxed text-muted-foreground">- {describeAuthGate(auth.bootstrapMethods)}- </p>-- <form className="mt-6 space-y-4" onSubmit={(event) => void handleSubmit(event)}>- <div className="space-y-2">- <label className="text-sm font-medium" htmlFor="pairing-token">- Pairing token- </label>- <Input- id="pairing-token"- autoCapitalize="none"- autoComplete="off"- autoCorrect="off"- disabled={isSubmitting}- nativeInput- onChange={(event) => setCredential(event.currentTarget.value)}- placeholder="Paste a one-time token or pairing secret"- spellCheck={false}- value={credential}- />- </div>+ <StandalonePage tone="pairing">+ <StandalonePageHeader+ eyebrow={APP_DISPLAY_NAME}+ title="Pair with this environment"+ description={describeAuthGate(auth.bootstrapMethods)}+ />++ <form className="mt-6 space-y-4" onSubmit={(event) => void handleSubmit(event)}>+ <div className="space-y-2">+ <label className="text-sm font-medium" htmlFor="pairing-token">+ Pairing token+ </label>+ <Input+ id="pairing-token"+ autoCapitalize="none"+ autoComplete="off"+ autoCorrect="off"+ disabled={isSubmitting}+ nativeInput+ onChange={(event) => setCredential(event.currentTarget.value)}+ placeholder="Paste a one-time token or pairing secret"+ spellCheck={false}+ value={credential}+ />+ </div>- {errorMessage ? (- <div className="rounded-lg border border-destructive/30 bg-destructive/6 px-3 py-2 text-sm text-destructive">- {errorMessage}- </div>- ) : null}-- <div className="flex flex-wrap gap-2">- <Button disabled={isSubmitting} size="sm" type="submit">- {isSubmitting ? "Pairing..." : "Continue"}- </Button>- <Button- disabled={isSubmitting}- onClick={() => window.location.reload()}- size="sm"- variant="outline"- >- Reload app- </Button>+ {errorMessage ? (+ <div className="rounded-lg border border-destructive/30 bg-destructive/6 px-3 py-2 text-sm text-destructive">+ {errorMessage}</div>- </form>+ ) : null}- <div className="mt-6 rounded-lg border border-border/70 bg-background/55 px-3 py-3 text-xs leading-relaxed text-muted-foreground">- {describeSupportedMethods(auth.bootstrapMethods)}+ <div className="flex flex-wrap gap-2">+ <Button disabled={isSubmitting} size="sm" type="submit">+ {isSubmitting ? "Pairing..." : "Continue"}+ </Button>+ <Button+ disabled={isSubmitting}+ onClick={() => window.location.reload()}+ size="sm"+ variant="outline"+ >+ Reload app+ </Button></div>- </section>- </div>+ </form>++ <div className="mt-6 rounded-lg border border-border/70 bg-background/55 px-3 py-3 text-xs leading-relaxed text-muted-foreground">+ {describeSupportedMethods(auth.bootstrapMethods)}+ </div>+ </StandalonePage>);}@@ -233,57 +210,49 @@ export function HostedPairingRouteSurface() {const request = hostedPairingRequestRef.current;return (- <div className="relative flex min-h-screen items-center justify-center overflow-hidden bg-background px-4 py-10 text-foreground sm:px-6">- <div className="pointer-events-none absolute inset-0 opacity-80">- <div className="absolute inset-x-0 top-0 h-44 bg-[radial-gradient(44rem_16rem_at_top,color-mix(in_srgb,var(--color-emerald-500)_14%,transparent),transparent)]" />- <div className="absolute inset-y-0 left-0 w-72 bg-[radial-gradient(28rem_18rem_at_left,color-mix(in_srgb,var(--color-sky-500)_10%,transparent),transparent)]" />- <div className="absolute inset-0 bg-[linear-gradient(145deg,color-mix(in_srgb,var(--background)_90%,var(--color-black))_0%,var(--background)_55%)]" />- </div>-- <section className="relative w-full max-w-xl rounded-2xl border border-border/80 bg-card/90 p-6 shadow-2xl shadow-black/20 backdrop-blur-md sm:p-8">- <p className="text-[11px] font-semibold tracking-[0.18em] text-muted-foreground uppercase">- {APP_DISPLAY_NAME}- </p>- <h1 className="mt-3 text-2xl font-semibold tracking-tight sm:text-3xl">- {status === "paired"+ <StandalonePage tone="pairing">+ <StandalonePageHeader+ eyebrow={APP_DISPLAY_NAME}+ title={+ status === "paired"? "Backend paired": status === "error"? "Pairing failed"- : "Pairing backend"}- </h1>- <p className="mt-2 text-sm leading-relaxed text-muted-foreground">{message}</p>+ : "Pairing backend"+ }+ description={message}+ />++ {request ? (+ <div className="mt-5 rounded-lg border border-border/70 bg-background/55 px-3 py-3 text-xs leading-relaxed text-muted-foreground">+ Host: <span className="font-mono text-foreground/80">{request.host}</span>+ </div>+ ) : null}- {request ? (- <div className="mt-5 rounded-lg border border-border/70 bg-background/55 px-3 py-3 text-xs leading-relaxed text-muted-foreground">- Host: <span className="font-mono text-foreground/80">{request.host}</span>- </div>+ {status === "error" ? (+ <div className="mt-5 rounded-lg border border-destructive/30 bg-destructive/6 px-3 py-2 text-sm text-destructive">+ Verify the backend is reachable from this browser, supports CORS for hosted clients, and+ is served over HTTPS when opening this page from HTTPS.+ </div>+ ) : null}++ <div className="mt-6 flex flex-wrap gap-2">+ {status === "pairing" ? (+ <Button disabled size="sm">+ Pairing...+ </Button>+ ) : canRetry ? (+ <Button size="sm" onClick={() => void submitHostedPairingRequest()}>+ Try again+ </Button>) : null}-- {status === "error" ? (- <div className="mt-5 rounded-lg border border-destructive/30 bg-destructive/6 px-3 py-2 text-sm text-destructive">- Verify the backend is reachable from this browser, supports CORS for hosted clients, and- is served over HTTPS when opening this page from HTTPS.- </div>+ {status === "paired" ? (+ <Button size="sm" variant="outline" onClick={() => (window.location.href = "/")}>+ Open app+ </Button>) : null}-- <div className="mt-6 flex flex-wrap gap-2">- {status === "pairing" ? (- <Button disabled size="sm">- Pairing...- </Button>- ) : canRetry ? (- <Button size="sm" onClick={() => void submitHostedPairingRequest()}>- Try again- </Button>- ) : null}- {status === "paired" ? (- <Button size="sm" variant="outline" onClick={() => (window.location.href = "/")}>- Open app- </Button>- ) : null}- </div>- </section>- </div>+ </div>+ </StandalonePage>);}diff --git a/apps/web/src/components/ui/standalone-page.tsx b/apps/web/src/components/ui/standalone-page.tsxnew file mode 100644index 00000000000..f44ec18f682--- /dev/null+++ b/apps/web/src/components/ui/standalone-page.tsx@@ -0,0 +1,67 @@+import type { ReactNode } from "react";++const backdropClassNames = {+ pairing:+ "absolute inset-x-0 top-0 h-44 bg-[radial-gradient(44rem_16rem_at_top,color-mix(in_srgb,var(--color-emerald-500)_14%,transparent),transparent)]",+ error:+ "absolute inset-x-0 top-0 h-44 bg-[radial-gradient(44rem_16rem_at_top,color-mix(in_srgb,var(--color-red-500)_16%,transparent),transparent)]",+ brand:+ "absolute inset-x-0 top-0 h-72 bg-[radial-gradient(48rem_20rem_at_top,color-mix(in_srgb,var(--color-blue-500)_12%,transparent),transparent)]",+};++/** Shared page and card geometry for entry points outside the app shell. */+export function StandalonePage({+ tone,+ masthead,+ children,+}: {+ readonly tone: keyof typeof backdropClassNames;+ readonly masthead?: ReactNode;+ readonly children: ReactNode;+}) {+ return (+ <div className="relative flex min-h-screen items-center justify-center overflow-hidden bg-background px-4 py-10 text-foreground sm:px-6">+ <div className="pointer-events-none absolute inset-0 opacity-80" aria-hidden>+ <div className={backdropClassNames[tone]} />+ {tone === "pairing" ? (+ <div className="absolute inset-y-0 left-0 w-72 bg-[radial-gradient(28rem_18rem_at_left,color-mix(in_srgb,var(--color-sky-500)_10%,transparent),transparent)]" />+ ) : null}+ <div+ className={+ tone === "brand"+ ? "absolute inset-0 bg-[linear-gradient(145deg,color-mix(in_srgb,var(--background)_94%,var(--color-black))_0%,var(--background)_62%)]"+ : "absolute inset-0 bg-[linear-gradient(145deg,color-mix(in_srgb,var(--background)_90%,var(--color-black))_0%,var(--background)_55%)]"+ }+ />+ </div>++ <section+ className={`relative w-full max-w-xl rounded-2xl border border-border/80 shadow-2xl shadow-black/20 backdrop-blur-md ${tone === "brand" ? "overflow-hidden bg-card/94" : "bg-card/90"}`}+ >+ {masthead}+ <div className="p-6 sm:p-8">{children}</div>+ </section>+ </div>+ );+}++/** Entry-page headings keep their typography and spacing together. */+export function StandalonePageHeader({+ eyebrow,+ title,+ description,+}: {+ readonly eyebrow: ReactNode;+ readonly title: ReactNode;+ readonly description: ReactNode;+}) {+ return (+ <>+ <p className="text-[11px] font-semibold tracking-[0.18em] text-muted-foreground uppercase">+ {eyebrow}+ </p>+ <h1 className="mt-3 text-2xl font-semibold tracking-tight sm:text-3xl">{title}</h1>+ <p className="mt-2 text-sm leading-relaxed text-muted-foreground">{description}</p>+ </>+ );+}diff --git a/apps/web/src/routes/__root.tsx b/apps/web/src/routes/__root.tsxindex 42e40842a72..eee703ac3f4 100644--- a/apps/web/src/routes/__root.tsx+++ b/apps/web/src/routes/__root.tsx@@ -35,6 +35,7 @@ import { useCopyToClipboard } from "../hooks/useCopyToClipboard";import { useDefaultThemeAdoption } from "../hooks/useDefaultTheme";import { useEnvironmentThemeSync } from "../hooks/useEnvironmentTheme";import { Button } from "../components/ui/button";+import { StandalonePage, StandalonePageHeader } from "../components/ui/standalone-page";import {AnchoredToastProvider,stackedThreadToast,@@ -368,39 +369,30 @@ function RootRouteErrorView({ error }: ErrorComponentProps) {const report = useMemo(() => errorReport(error, pathname), [error, pathname]);return (- <div className="relative flex min-h-screen items-center justify-center overflow-hidden bg-background px-4 py-10 text-foreground sm:px-6">- <div className="pointer-events-none absolute inset-0 opacity-80">- <div className="absolute inset-x-0 top-0 h-44 bg-[radial-gradient(44rem_16rem_at_top,color-mix(in_srgb,var(--color-red-500)_16%,transparent),transparent)]" />- <div className="absolute inset-0 bg-[linear-gradient(145deg,color-mix(in_srgb,var(--background)_90%,var(--color-black))_0%,var(--background)_55%)]" />+ <StandalonePage tone="error">+ <StandalonePageHeader+ eyebrow={APP_DISPLAY_NAME}+ title="Something went wrong."+ description={message}+ />++ <div className="mt-5 flex flex-wrap gap-2">+ <Button size="sm" onClick={() => void router.invalidate()}>+ Try again+ </Button>+ <Button size="sm" variant="outline" onClick={() => window.location.reload()}>+ Reload app+ </Button>+ <CopyErrorButton report={report} /></div>- <section className="relative w-full max-w-xl rounded-2xl border border-border/80 bg-card/90 p-6 shadow-2xl shadow-black/20 backdrop-blur-md sm:p-8">- <p className="text-[11px] font-semibold tracking-[0.18em] text-muted-foreground uppercase">- {APP_DISPLAY_NAME}- </p>- <h1 className="mt-3 text-2xl font-semibold tracking-tight sm:text-3xl">- Something went wrong.- </h1>- <p className="mt-2 text-sm leading-relaxed text-muted-foreground">{message}</p>-- <div className="mt-5 flex flex-wrap gap-2">- <Button size="sm" onClick={() => void router.invalidate()}>- Try again- </Button>- <Button size="sm" variant="outline" onClick={() => window.location.reload()}>- Reload app- </Button>- <CopyErrorButton report={report} />- </div>-- <div className="mt-5 overflow-hidden rounded-lg border border-border/70 bg-background/55">- <p className="px-3 py-1.5 text-xs font-medium text-muted-foreground">Error report</p>- <pre className="max-h-64 overflow-auto border-t border-border/70 bg-background/80 px-3 py-2 text-xs whitespace-pre-wrap text-foreground/85">- {report}- </pre>- </div>- </section>- </div>+ <div className="mt-5 overflow-hidden rounded-lg border border-border/70 bg-background/55">+ <p className="px-3 py-1.5 text-xs font-medium text-muted-foreground">Error report</p>+ <pre className="max-h-64 overflow-auto border-t border-border/70 bg-background/80 px-3 py-2 text-xs whitespace-pre-wrap text-foreground/85">+ {report}+ </pre>+ </div>+ </StandalonePage>);}