Skip to content

Open source alternative to Semrush and Ahrefs

Add the OpenSEO EmptyState, ErrorState, StatTile, PageHeader and CopyButton composites (EVE-293) (#733)

Carter Smith62aa205e0c72
diff --git a/src/client/components/CopyButton.tsx b/src/client/components/CopyButton.tsx
new file mode 100644
index 00000000..c8121eab
--- /dev/null
+++ b/src/client/components/CopyButton.tsx
@@ -0,0 +1,54 @@
+import type { ComponentProps } from "react";
+import { Check, Copy } from "lucide-react";
+import { Button } from "@/client/components/ui/button";
+import { useCopy } from "@/client/hooks/useCopy";
+
+type ButtonProps = ComponentProps<typeof Button>;
+
+/**
+ * A Button that copies `value`. An `icon*` size shows only the icon and uses
+ * `label` as the accessible name.
+ */
+export function CopyButton({
+ value,
+ successMessage,
+ label = "Copy",
+ onCopy,
+ variant = "outline",
+ size = "xs",
+ className,
+}: {
+ value: string;
+ successMessage: string;
+ label?: string;
+ onCopy?: () => void;
+ variant?: ButtonProps["variant"];
+ size?: ButtonProps["size"];
+ className?: string;
+}) {
+ const { copied, copy } = useCopy();
+ const iconOnly = size?.startsWith("icon") ?? false;
+ const Icon = copied ? Check : Copy;
+
+ return (
+ <Button
+ type="button"
+ variant={variant}
+ size={size}
+ className={className}
+ aria-label={iconOnly ? label : undefined}
+ onClick={() => {
+ void copy(value, successMessage).then((ok) => {
+ if (ok) onCopy?.();
+ });
+ }}
+ >
+ <Icon
+ data-icon={iconOnly ? undefined : "inline-start"}
+ className={copied && variant !== "default" ? "text-success" : undefined}
+ aria-hidden
+ />
+ {iconOnly ? null : copied ? "Copied" : label}
+ </Button>
+ );
+}
diff --git a/src/client/components/EmptyState.tsx b/src/client/components/EmptyState.tsx
new file mode 100644
index 00000000..7fbc167a
--- /dev/null
+++ b/src/client/components/EmptyState.tsx
@@ -0,0 +1,73 @@
+import type { ReactNode } from "react";
+import { CircleAlert, Inbox, SearchX, type LucideIcon } from "lucide-react";
+import {
+ Empty,
+ EmptyContent,
+ EmptyDescription,
+ EmptyHeader,
+ EmptyMedia,
+ EmptyTitle,
+} from "@/client/components/ui/empty";
+
+const KIND_ICONS: Record<EmptyStateKind, LucideIcon> = {
+ "no-data": Inbox,
+ filtered: SearchX,
+ error: CircleAlert,
+};
+
+type EmptyStateKind = "no-data" | "filtered" | "error";
+
+/**
+ * The one empty state: an icon, a title, a body and an action.
+ *
+ * `kind` picks the default icon. Say why the region is empty: "no-data" when
+ * nothing exists yet, "filtered" when filters hide every row, "error" when the
+ * data failed to load. Name only filters and buttons that exist on the page.
+ */
+export function EmptyState({
+ kind = "no-data",
+ icon: Icon = KIND_ICONS[kind],
+ title,
+ description,
+ action,
+ variant = "dashed",
+ size,
+}: {
+ kind?: EmptyStateKind;
+ /** Pass `null` for a text-only empty state. */
+ icon?: LucideIcon | null;
+ title: ReactNode;
+ description?: ReactNode;
+ action?: ReactNode;
+ /** `dashed` for sections and lists, `card` for a whole panel, `plain` inside a card or table. */
+ variant?: "dashed" | "card" | "plain";
+ size?: "sm" | "default" | "lg";
+}) {
+ return (
+ <Empty
+ variant={variant}
+ size={size}
+ role={kind === "error" ? "alert" : undefined}
+ >
+ <EmptyHeader>
+ {Icon ? (
+ <EmptyMedia
+ variant="icon"
+ className={
+ kind === "error"
+ ? "bg-destructive/10 text-destructive"
+ : undefined
+ }
+ >
+ <Icon aria-hidden />
+ </EmptyMedia>
+ ) : null}
+ <EmptyTitle>{title}</EmptyTitle>
+ {description ? (
+ <EmptyDescription>{description}</EmptyDescription>
+ ) : null}
+ </EmptyHeader>
+ {action ? <EmptyContent>{action}</EmptyContent> : null}
+ </Empty>
+ );
+}
diff --git a/src/client/components/ErrorState.tsx b/src/client/components/ErrorState.tsx
new file mode 100644
index 00000000..1d06ddca
--- /dev/null
+++ b/src/client/components/ErrorState.tsx
@@ -0,0 +1,81 @@
+import type { ReactNode } from "react";
+import { CircleAlert } from "lucide-react";
+import { EmptyState } from "@/client/components/EmptyState";
+import {
+ Alert,
+ AlertDescription,
+ AlertTitle,
+} from "@/client/components/ui/alert";
+import { Button } from "@/client/components/ui/button";
+
+/**
+ * A failure message with an optional retry.
+ *
+ * - `inline`: red text and a small button, inside a card or a table.
+ * - `card`: a destructive Alert, above or in place of a section.
+ * - `page`: a centered block that replaces the whole page content.
+ */
+export function ErrorState({
+ title,
+ message,
+ onRetry,
+ isRetrying = false,
+ action,
+ variant = "card",
+}: {
+ title?: string;
+ message: string;
+ onRetry?: () => void;
+ /** Shows the retry button as pending, for example while `isFetching`. */
+ isRetrying?: boolean;
+ /** Replaces the retry button, for errors a retry cannot fix. */
+ action?: ReactNode;
+ variant?: "inline" | "card" | "page";
+}) {
+ const button =
+ action ??
+ (onRetry ? (
+ <Button
+ variant="outline"
+ size={variant === "page" ? "default" : "sm"}
+ pending={isRetrying}
+ onClick={onRetry}
+ >
+ Try again
+ </Button>
+ ) : null);
+
+ if (variant === "page") {
+ return (
+ <EmptyState
+ kind="error"
+ variant="plain"
+ size="lg"
+ title={title ?? "Something went wrong"}
+ description={message}
+ action={button}
+ />
+ );
+ }
+
+ if (variant === "inline") {
+ return (
+ <div
+ role="alert"
+ className="flex flex-wrap items-center gap-x-3 gap-y-2 text-sm text-destructive"
+ >
+ <span>{message}</span>
+ {button}
+ </div>
+ );
+ }
+
+ return (
+ <Alert variant="destructive">
+ <CircleAlert aria-hidden />
+ <AlertTitle>{title ?? message}</AlertTitle>
+ {title ? <AlertDescription>{message}</AlertDescription> : null}
+ {button ? <div className="col-start-2 mt-2">{button}</div> : null}
+ </Alert>
+ );
+}
diff --git a/src/client/components/FormActions.tsx b/src/client/components/FormActions.tsx
new file mode 100644
index 00000000..3cb72249
--- /dev/null
+++ b/src/client/components/FormActions.tsx
@@ -0,0 +1,31 @@
+import { Button } from "@/client/components/ui/button";
+
+/** The Cancel and submit buttons at the end of a form. */
+export function FormActions({
+ pending,
+ disabled = false,
+ onCancel,
+ size = "default",
+}: {
+ pending: boolean;
+ disabled?: boolean;
+ onCancel: () => void;
+ size?: "xs" | "sm" | "default";
+}) {
+ return (
+ <div className="flex justify-end gap-2">
+ <Button
+ type="button"
+ variant="ghost"
+ size={size}
+ onClick={onCancel}
+ disabled={pending}
+ >
+ Cancel
+ </Button>
+ <Button type="submit" size={size} disabled={disabled} pending={pending}>
+ Save
+ </Button>
+ </div>
+ );
+}
diff --git a/src/client/components/PageHeader.tsx b/src/client/components/PageHeader.tsx
new file mode 100644
index 00000000..c39d5c16
--- /dev/null
+++ b/src/client/components/PageHeader.tsx
@@ -0,0 +1,75 @@
+import type { ComponentProps, ReactNode } from "react";
+import { createLink } from "@tanstack/react-router";
+import { ChevronLeft } from "lucide-react";
+import { cn } from "cn";
+
+/** The page title, with an optional subtitle and actions on the right. */
+export function PageHeader({
+ title,
+ description,
+ actions,
+}: {
+ title: ReactNode;
+ /** A subtitle, or metadata such as a `<dl>`. */
+ description?: ReactNode;
+ actions?: ReactNode;
+}) {
+ return (
+ <div className="flex flex-wrap items-start justify-between gap-3">
+ <div className="min-w-0 flex-1 space-y-1">
+ <h1 className="text-2xl font-semibold tracking-tight">{title}</h1>
+ {description ? (
+ <div className="text-sm text-muted-foreground">{description}</div>
+ ) : null}
+ </div>
+ {actions ? (
+ <div className="flex shrink-0 flex-wrap items-center gap-2">
+ {actions}
+ </div>
+ ) : null}
+ </div>
+ );
+}
+
+/** The heading of one section on a page, with an optional hint and action. */
+export function SectionHeader({
+ title,
+ hint,
+ action,
+}: {
+ title: string;
+ hint?: string;
+ action?: ReactNode;
+}) {
+ return (
+ <div className="flex items-start justify-between gap-3">
+ <div className="space-y-0.5">
+ <h2 className="text-sm font-medium text-muted-foreground">{title}</h2>
+ {hint ? <p className="text-xs text-muted-foreground">{hint}</p> : null}
+ </div>
+ {action}
+ </div>
+ );
+}
+
+function BackLinkAnchor({
+ className,
+ children,
+ ...props
+}: ComponentProps<"a">) {
+ return (
+ <a
+ {...props}
+ className={cn(
+ "inline-flex items-center gap-1 text-sm text-muted-foreground transition-colors hover:text-foreground",
+ className,
+ )}
+ >
+ <ChevronLeft className="size-4" aria-hidden />
+ {children}
+ </a>
+ );
+}
+
+/** A router link back to the parent page, with a chevron before its label. */
+export const BackLink = createLink(BackLinkAnchor);
diff --git a/src/client/components/PermissionHint.tsx b/src/client/components/PermissionHint.tsx
index 59fd65c0..2b841572 100644
--- a/src/client/components/PermissionHint.tsx
+++ b/src/client/components/PermissionHint.tsx
@@ -1,3 +1,5 @@
+import { cn } from "cn";
+
/** Shown where a missing permission would otherwise leave a card or step empty. */
export function PermissionHint({
action,
@@ -7,7 +9,7 @@ export function PermissionHint({
className?: string;
}) {
return (
- <p className={`text-sm text-base-content/60 ${className ?? ""}`}>
+ <p className={cn("text-sm text-muted-foreground", className)}>
Ask an organization owner or admin to {action}.
</p>
);
diff --git a/src/client/components/QueryState.tsx b/src/client/components/QueryState.tsx
index bdf6d608..80dc2643 100644
--- a/src/client/components/QueryState.tsx
+++ b/src/client/components/QueryState.tsx
@@ -6,6 +6,8 @@ import {
getStandardErrorMessage,
} from "@/client/lib/error-messages";
import { BILLING_ROUTE } from "@/shared/billing";
+import { ErrorState } from "@/client/components/ErrorState";
+import { Button } from "@/client/components/ui/button";
import { PageLoading } from "./Spinner";
/**
@@ -19,6 +21,8 @@ export function QueryError({
fallback,
onRetry,
isRetrying = false,
+ variant,
+ title,
}: {
/** Omit to always show `fallback`, for errors the page words itself. */
error?: unknown;
@@ -28,27 +32,29 @@ export function QueryError({
fallback: string;
onRetry?: () => void;
isRetrying?: boolean;
+ variant?: "inline" | "card" | "page";
+ title?: string;
}) {
return (
- <div role="alert" className="alert alert-error">
- <span className="text-sm">
- {getStandardErrorMessage(error, fallback)}
- </span>
- {getErrorCode(error ?? cause) === "INSUFFICIENT_CREDITS" ? (
- <Link to={BILLING_ROUTE} className="btn btn-sm">
- Go to Billing
- </Link>
- ) : onRetry ? (
- <button
- type="button"
- className="btn btn-sm"
- onClick={onRetry}
- disabled={isRetrying}
- >
- {isRetrying ? "Retrying…" : "Try again"}
- </button>
- ) : null}
- </div>
+ <ErrorState
+ variant={variant}
+ title={title}
+ message={getStandardErrorMessage(error, fallback)}
+ onRetry={onRetry}
+ isRetrying={isRetrying}
+ action={
+ getErrorCode(error ?? cause) === "INSUFFICIENT_CREDITS" ? (
+ <Button
+ variant="outline"
+ size="sm"
+ nativeButton={false}
+ render={<Link to={BILLING_ROUTE} />}
+ >
+ Go to Billing
+ </Button>
+ ) : undefined
+ }
+ />
);
}
diff --git a/src/client/components/StatTile.tsx b/src/client/components/StatTile.tsx
new file mode 100644
index 00000000..42da0e07
--- /dev/null
+++ b/src/client/components/StatTile.tsx
@@ -0,0 +1,70 @@
+import { cn } from "cn";
+
+/**
+ * One metric: a muted uppercase label over a big tabular number.
+ *
+ * `delta` compares the value with the previous period and shows the percent
+ * change. It shows nothing when either side is missing or the previous value
+ * is zero. `card` draws the tile as its own bordered box; without it the tile
+ * sits bare inside another card.
+ */
+export function StatTile({
+ label,
+ value,
+ tone,
+ delta,
+ hint,
+ card = false,
+}: {
+ label: string;
+ value: string;
+ /** Colors the value, for counts that are good or bad news on their own. */
+ tone?: "success" | "destructive";
+ delta?: { current: number | null; previous: number | null };
+ hint?: string;
+ card?: boolean;
+}) {
+ const percent = delta ? percentChange(delta.current, delta.previous) : null;
+ return (
+ <div
+ className={cn(
+ "flex min-w-0 flex-col gap-1",
+ card && "rounded-xl border border-border bg-card p-4 shadow-sm",
+ )}
+ >
+ <p className="text-xs font-medium tracking-wide text-muted-foreground uppercase">
+ {label}
+ </p>
+ <p
+ className={cn(
+ "text-2xl leading-tight font-semibold tabular-nums",
+ tone === "success" && "text-success",
+ tone === "destructive" && "text-destructive",
+ )}
+ >
+ {value}
+ </p>
+ {percent === null ? null : (
+ <p
+ className={cn(
+ "text-xs tabular-nums",
+ percent > 0 && "text-success",
+ percent < 0 && "text-destructive",
+ )}
+ >
+ {percent > 0 ? "▲ " : percent < 0 ? "▼ " : ""}
+ {Math.abs(percent)}%
+ </p>
+ )}
+ {hint ? <p className="text-xs text-muted-foreground">{hint}</p> : null}
+ </div>
+ );
+}
+
+function percentChange(
+ current: number | null,
+ previous: number | null,
+): number | null {
+ if (current === null || previous === null || previous <= 0) return null;
+ return Math.round(((current - previous) / previous) * 100);
+}
diff --git a/src/client/components/ui/empty.tsx b/src/client/components/ui/empty.tsx
index 65dee517..6e2ee438 100644
--- a/src/client/components/ui/empty.tsx
+++ b/src/client/components/ui/empty.tsx
@@ -1,14 +1,39 @@
import { cva, type VariantProps } from "class-variance-authority";
import { cn } from "cn";
-function Empty({ className, ...props }: React.ComponentProps<"div">) {
+const emptyVariants = cva(
+ "group/empty flex w-full min-w-0 flex-1 flex-col items-center justify-center gap-4 rounded-xl border-dashed p-6 text-center text-balance",
+ {
+ variants: {
+ variant: {
+ plain: "",
+ dashed: "border border-dashed border-border",
+ card: "border border-solid border-border bg-card text-card-foreground shadow-sm",
+ },
+ size: {
+ default: "",
+ sm: "gap-3 rounded-lg p-4",
+ lg: "p-10",
+ },
+ },
+ defaultVariants: {
+ variant: "plain",
+ size: "default",
+ },
+ },
+);
+
+function Empty({
+ className,
+ variant,
+ size,
+ ...props
+}: React.ComponentProps<"div"> & VariantProps<typeof emptyVariants>) {
return (
<div
data-slot="empty"
- className={cn(
- "flex w-full min-w-0 flex-1 flex-col items-center justify-center gap-4 rounded-xl border-dashed p-6 text-center text-balance",
- className,
- )}
+ data-size={size ?? "default"}
+ className={cn(emptyVariants({ variant, size }), className)}
{...props}
/>
);
@@ -25,12 +50,12 @@ function EmptyHeader({ className, ...props }: React.ComponentProps<"div">) {
}
const emptyMediaVariants = cva(
- "mb-2 flex shrink-0 items-center justify-center [&_svg]:pointer-events-none [&_svg]:shrink-0",
+ "mb-2 flex shrink-0 group-data-[size=sm]/empty:mb-0 items-center justify-center [&_svg]:pointer-events-none [&_svg]:shrink-0",
{
variants: {
variant: {
default: "bg-transparent",
- icon: "flex size-8 shrink-0 items-center justify-center rounded-lg bg-muted text-foreground [&_svg:not([class*='size-'])]:size-4",
+ icon: "flex size-10 shrink-0 items-center justify-center rounded-lg bg-foreground/5 text-muted-foreground [&_svg:not([class*='size-'])]:size-5",
},
},
defaultVariants: {
@@ -58,13 +83,16 @@ function EmptyTitle({ className, ...props }: React.ComponentProps<"div">) {
return (
<div
data-slot="empty-title"
- className={cn("text-sm font-medium tracking-tight", className)}
+ className={cn("text-sm font-semibold tracking-tight", className)}
{...props}
/>
);
}
-function EmptyDescription({ className, ...props }: React.ComponentProps<"p">) {
+function EmptyDescription({
+ className,
+ ...props
+}: React.ComponentProps<"div">) {
return (
<div
data-slot="empty-description"
diff --git a/src/client/features/ai-mcp/AgentSetupPanel.tsx b/src/client/features/ai-mcp/AgentSetupPanel.tsx
index c06616cf..2f1ba5c2 100644
--- a/src/client/features/ai-mcp/AgentSetupPanel.tsx
+++ b/src/client/features/ai-mcp/AgentSetupPanel.tsx
@@ -1,5 +1,5 @@
import { Package } from "lucide-react";
-import { CopyButton } from "./SetupControls";
+import { CopyButton } from "@/client/components/CopyButton";
export const AGENT_SETUP_DESCRIPTION =
"Paste this prompt into your agent to automatically configure OpenSEO for you.";
@@ -25,15 +25,15 @@ export function AgentSetupPanel({
</p>
</div>
</div>
- <div className="[&>button]:h-11 [&>button]:w-full [&>button]:gap-2 [&>button]:text-sm">
- <CopyButton
- primary
- value={prompt}
- label="Copy setup prompt"
- successMessage="Setup prompt copied"
- onCopy={onCopy}
- />
- </div>
+ <CopyButton
+ variant="default"
+ size="lg"
+ className="h-11 w-full gap-2"
+ value={prompt}
+ label="Copy setup prompt"
+ successMessage="Setup prompt copied"
+ onCopy={onCopy}
+ />
</div>
<div className="mt-4 text-center">
<a
diff --git a/src/client/features/ai-mcp/SetupControls.tsx b/src/client/features/ai-mcp/SetupControls.tsx
deleted file mode 100644
index 490a1187..00000000
--- a/src/client/features/ai-mcp/SetupControls.tsx
+++ /dev/null
@@ -1,73 +0,0 @@
-import { Check, Copy } from "lucide-react";
-import { useState } from "react";
-import { toast } from "sonner";
-
-export function CopyButton({
- value,
- successMessage,
- label = "Copy",
- iconOnly = false,
- primary = false,
- onCopy,
-}: {
- value: string;
- successMessage: string;
- label?: string;
- iconOnly?: boolean;
- primary?: boolean;
- onCopy?: () => void;
-}) {
- const [copied, setCopied] = useState(false);
-
- const handleCopy = async () => {
- if (typeof navigator === "undefined" || !navigator.clipboard?.writeText) {
- toast.error("Clipboard not available");
- return;
- }
- try {
- await navigator.clipboard.writeText(value);
- toast.success(successMessage);
- setCopied(true);
- setTimeout(() => setCopied(false), 2000);
- onCopy?.();
- } catch {
- toast.error("Could not copy to clipboard");
- }
- };
-
- if (iconOnly) {
- return (
- <button
- type="button"
- onClick={handleCopy}
- aria-label={label}
- className="flex size-7 items-center justify-center rounded-md text-base-content/60 transition-colors hover:bg-base-200 hover:text-base-content"
- >
- {copied ? (
- <Check className="size-3.5 text-success" />
- ) : (
- <Copy className="size-3.5" />
- )}
- </button>
- );
- }
-
- return (
- <button
- type="button"
- onClick={handleCopy}
- className={
- primary
- ? "btn btn-primary"
- : "inline-flex items-center gap-1.5 rounded-md border border-base-300 bg-base-100 px-2 py-1 text-xs font-medium text-base-content/70 transition-colors hover:bg-base-300/50 hover:text-base-content"
- }
- >
- {copied ? (
- <Check className="size-3 text-success" />
- ) : (
- <Copy className="size-3" />
- )}
- {copied ? "Copied" : label}
- </button>
- );
-}
diff --git a/src/client/features/dashboard/DashboardCards.tsx b/src/client/features/dashboard/DashboardCards.tsx
index 4326526d..a6d54f2e 100644
--- a/src/client/features/dashboard/DashboardCards.tsx
+++ b/src/client/features/dashboard/DashboardCards.tsx
@@ -17,9 +17,8 @@ import {
formatDay,
moreDetailsClass,
newLost,
- PercentDelta,
- Stat,
} from "@/client/features/dashboard/cardParts";
+import { StatTile } from "@/client/components/StatTile";
import type {
DashboardAuditSummary,
DashboardBacklinkSummary,
@@ -85,28 +84,24 @@ export function GscCard({
</div>
) : (
<div className="grid grid-cols-2 gap-3">
- <Stat
+ <StatTile
label="Clicks"
value={formatCount(report.totals.clicks)}
- sub={
- <PercentDelta
- current={report.totals.clicks}
- previous={report.prevTotals.clicks}
- />
- }
+ delta={{
+ current: report.totals.clicks,
+ previous: report.prevTotals.clicks,
+ }}
/>
- <Stat
+ <StatTile
label="Impressions"
value={formatCount(report.totals.impressions)}
- sub={
- <PercentDelta
- current={report.totals.impressions}
- previous={report.prevTotals.impressions}
- />
- }
+ delta={{
+ current: report.totals.impressions,
+ previous: report.prevTotals.impressions,
+ }}
/>
- <Stat label="CTR" value={formatCtr(report.totals.ctr)} />
- <Stat
+ <StatTile label="CTR" value={formatCtr(report.totals.ctr)} />
+ <StatTile
label="Avg position"
value={formatPosition(report.totals.position)}
/>
@@ -271,7 +266,7 @@ export function BacklinkPulseCard({
}
>
<div className="grid grid-cols-2 gap-3">
- <Stat
+ <StatTile
label="Ref. domains"
value={
backlinks.referringDomains === null
@@ -279,7 +274,7 @@ export function BacklinkPulseCard({
: backlinks.referringDomains.toLocaleString()
}
/>
- <Stat
+ <StatTile
label="Backlinks"
value={
backlinks.backlinks === null
@@ -287,7 +282,7 @@ export function BacklinkPulseCard({
: backlinks.backlinks.toLocaleString()
}
/>
- <Stat
+ <StatTile
label="New links"
value={`▲ ${newLost(backlinks.newBacklinks)}`}
tone={
@@ -296,12 +291,12 @@ export function BacklinkPulseCard({
: undefined
}
/>
- <Stat
+ <StatTile
label="Lost links"
value={`▼ ${newLost(backlinks.lostBacklinks)}`}
tone={
backlinks.lostBacklinks && backlinks.lostBacklinks > 0
- ? "error"
+ ? "destructive"
: undefined
}
/>
diff --git a/src/client/features/dashboard/DashboardSetupAction.tsx b/src/client/features/dashboard/DashboardSetupAction.tsx
index 3f73565b..02a569eb 100644
--- a/src/client/features/dashboard/DashboardSetupAction.tsx
+++ b/src/client/features/dashboard/DashboardSetupAction.tsx
@@ -7,7 +7,7 @@ import {
AgentSetupPanel,
AGENT_SETUP_DESCRIPTION,
} from "@/client/features/ai-mcp/AgentSetupPanel";
-import { CopyButton } from "@/client/features/ai-mcp/SetupControls";
+import { CopyButton } from "@/client/components/CopyButton";
import { CreateProjectModal } from "@/client/features/projects/CreateProjectModal";
import { InviteTeammateModal } from "@/client/features/team/InviteTeammateModal";
import { PermissionHint } from "@/client/components/PermissionHint";
diff --git a/src/client/features/dashboard/Ga4Card.tsx b/src/client/features/dashboard/Ga4Card.tsx
index 4a0a5b86..6f879800 100644
--- a/src/client/features/dashboard/Ga4Card.tsx
+++ b/src/client/features/dashboard/Ga4Card.tsx
@@ -2,11 +2,8 @@ import { CardShell } from "@/client/components/CardShell";
import { Link } from "@tanstack/react-router";
import { useQuery } from "@tanstack/react-query";
import { Area, AreaChart, XAxis, YAxis } from "recharts";
-import {
- moreDetailsClass,
- PercentDelta,
- Stat,
-} from "@/client/features/dashboard/cardParts";
+import { moreDetailsClass } from "@/client/features/dashboard/cardParts";
+import { StatTile } from "@/client/components/StatTile";
import { Ga4ConnectCard } from "@/client/features/dashboard/Ga4ConnectCard";
import {
formatCount,
@@ -42,12 +39,6 @@ function statValue(
return value === null ? "—" : format(value);
}
-function statDelta(current: number | null, previous: number | null) {
- return current !== null && previous !== null ? (
- <PercentDelta current={current} previous={previous} />
- ) : undefined;
-}
-
export function Ga4Card({
projectId,
connected,
@@ -105,33 +96,33 @@ export function Ga4Card({
) : (
<div className="space-y-4">
<div className="grid grid-cols-2 gap-3">
- <Stat
+ <StatTile
label="Sessions"
value={statValue(report.totals.sessions, formatCount)}
- sub={statDelta(
- report.totals.sessions,
- report.prevTotals.sessions,
- )}
+ delta={{
+ current: report.totals.sessions,
+ previous: report.prevTotals.sessions,
+ }}
/>
- <Stat
+ <StatTile
label="Active users"
value={statValue(report.totals.activeUsers, formatCount)}
- sub={statDelta(
- report.totals.activeUsers,
- report.prevTotals.activeUsers,
- )}
+ delta={{
+ current: report.totals.activeUsers,
+ previous: report.prevTotals.activeUsers,
+ }}
/>
- <Stat
+ <StatTile
label="Engagement rate"
value={statValue(report.totals.engagementRate, formatCtr)}
/>
- <Stat
+ <StatTile
label="Key events"
value={statValue(report.totals.keyEvents, formatCount)}
- sub={statDelta(
- report.totals.keyEvents,
- report.prevTotals.keyEvents,
- )}
+ delta={{
+ current: report.totals.keyEvents,
+ previous: report.prevTotals.keyEvents,
+ }}
/>
</div>
<ChartContainer config={sessionsChartConfig} className="h-24">
diff --git a/src/client/features/dashboard/cardParts.tsx b/src/client/features/dashboard/cardParts.tsx
index ee6a9751..b08d8199 100644
--- a/src/client/features/dashboard/cardParts.tsx
+++ b/src/client/features/dashboard/cardParts.tsx
@@ -14,51 +14,6 @@ export function EmptyCardBody({
);
}
-export function Stat({
- label,
- value,
- tone,
- sub,
-}: {
- label: string;
- value: string;
- tone?: "success" | "error";
- sub?: React.ReactNode;
-}) {
- const toneClass =
- tone === "success" ? "text-success" : tone === "error" ? "text-error" : "";
- return (
- <div>
- <p className="text-xs uppercase tracking-wide text-base-content/60">
- {label}
- </p>
- <p className={`text-2xl font-semibold tabular-nums ${toneClass}`}>
- {value}
- </p>
- {sub}
- </div>
- );
-}
-
-export function PercentDelta({
- current,
- previous,
-}: {
- current: number;
- previous: number;
-}) {
- if (previous <= 0) return null;
- const pct = ((current - previous) / previous) * 100;
- if (!Number.isFinite(pct)) return null;
- const rounded = Math.round(pct);
- const tone = rounded > 0 ? "text-success" : rounded < 0 ? "text-error" : "";
- return (
- <p className={`text-xs tabular-nums ${tone}`}>
- {rounded > 0 ? "▲" : rounded < 0 ? "▼" : ""} {Math.abs(rounded)}%
- </p>
- );
-}
-
export const moreDetailsClass = "btn btn-ghost btn-xs";
export function newLost(value: number | null): string {
diff --git a/src/client/features/domain/DomainOverviewPage.tsx b/src/client/features/domain/DomainOverviewPage.tsx
index 47279ab5..970dca79 100644
--- a/src/client/features/domain/DomainOverviewPage.tsx
+++ b/src/client/features/domain/DomainOverviewPage.tsx
@@ -26,7 +26,7 @@ import { QueryError } from "@/client/components/QueryState";
import { DomainSearchCard } from "@/client/features/domain/components/DomainSearchCard";
import { KeywordsTab } from "@/client/features/domain/components/KeywordsTab";
import { PagesTab } from "@/client/features/domain/components/PagesTab";
-import { StatCard } from "@/client/features/domain/components/StatCard";
+import { StatTile } from "@/client/components/StatTile";
import { SearchTabStrip } from "@/client/features/search-tabs/SearchTabStrip";
import type { SearchTabInput } from "@/client/features/search-tabs/types";
import { useSearchTabNavigation } from "@/client/features/search-tabs/useSearchTabNavigation";
@@ -611,7 +611,8 @@ export function DomainOverviewPage({
</span>
</div>
<div className="grid grid-cols-1 md:grid-cols-2 gap-3">
- <StatCard
+ <StatTile
+ card
label="Estimated Organic Traffic"
value={formatMetric(
state.overview.organicTraffic,
@@ -619,7 +620,8 @@ export function DomainOverviewPage({
)}
hint={overviewMetricsHint}
/>
- <StatCard
+ <StatTile
+ card
label="Organic Keywords"
value={formatMetric(
state.overview.organicKeywords,
diff --git a/src/client/features/domain/components/StatCard.tsx b/src/client/features/domain/components/StatCard.tsx
deleted file mode 100644
index 09ca7c5b..00000000
--- a/src/client/features/domain/components/StatCard.tsx
+++ /dev/null
@@ -1,21 +0,0 @@
-export function StatCard({
- label,
- value,
- hint,
-}: {
- label: string;
- value: string;
- hint?: string;
-}) {
- return (
- <div className="card bg-base-100 border border-base-300">
- <div className="card-body p-4">
- <p className="text-xs uppercase tracking-wide text-base-content/60">
- {label}
- </p>
- <p className="text-2xl font-semibold">{value}</p>
- {hint ? <p className="text-xs text-base-content/50">{hint}</p> : null}
- </div>
- </div>
- );
-}
diff --git a/src/client/features/projects/ProjectGeneralSettings.tsx b/src/client/features/projects/ProjectGeneralSettings.tsx
index 9e71b139..142b2e85 100644
--- a/src/client/features/projects/ProjectGeneralSettings.tsx
+++ b/src/client/features/projects/ProjectGeneralSettings.tsx
@@ -6,6 +6,7 @@ import { toast } from "sonner";
import { z } from "zod";
import { revalidateLogic } from "@tanstack/react-form";
import { useAppForm } from "@/client/components/form/useAppForm";
+import { SectionHeader } from "@/client/components/PageHeader";
import { QueryError, QueryState } from "@/client/components/QueryState";
import { ProjectMarketFields } from "@/client/features/projects/ProjectMarketFields";
import {
@@ -89,7 +90,7 @@ function GeneralSection({ project }: { project: ProjectSummary }) {
return (
<section className="space-y-3">
- <h2 className="text-sm font-medium text-base-content/50">General</h2>
+ <SectionHeader title="General" />
<form.AppForm>
<form.Form className="flex flex-col gap-4">
<form.AppField name="name">
@@ -171,9 +172,7 @@ function DangerSection({
return (
<section className="space-y-3 border-t border-base-300 pt-8">
- <h2 className="text-sm font-medium text-base-content/50">
- Archive project
- </h2>
+ <SectionHeader title="Archive project" />
{confirming ? (
<div className="space-y-3">
diff --git a/src/client/features/projects/project-context/CompetitorsSection.tsx b/src/client/features/projects/project-context/CompetitorsSection.tsx
index f60a6d0e..044f15e0 100644
--- a/src/client/features/projects/project-context/CompetitorsSection.tsx
+++ b/src/client/features/projects/project-context/CompetitorsSection.tsx
@@ -3,15 +3,15 @@ import { InlineConfirm } from "@/client/components/InlineConfirm";
import { Pencil, Plus } from "lucide-react";
import type { ProjectContextUpdate } from "@/types/schemas/projectContext";
import {
- EmptyState,
- FormActions,
listClass,
Provenance,
RowActions,
- SectionHeader,
useContextUpdate,
type ContextCompetitor,
} from "./shared";
+import { EmptyState } from "@/client/components/EmptyState";
+import { FormActions } from "@/client/components/FormActions";
+import { SectionHeader } from "@/client/components/PageHeader";
export function CompetitorsSection({
projectId,
@@ -80,10 +80,12 @@ export function CompetitorsSection({
{competitors.length === 0 ? (
adding ? null : (
- <EmptyState>
- No competitors yet. Add the sites you compete with, or ask SAM to
- find them from your rankings and save them here.
- </EmptyState>
+ <EmptyState
+ size="sm"
+ icon={null}
+ title="No competitors yet"
+ description="Add the sites you compete with, or ask SAM to find them from your rankings and save them here."
+ />
)
) : (
<ul className={listClass}>
@@ -215,6 +217,7 @@ function CompetitorForm({
pending={pending}
disabled={!draft.domain.trim()}
onCancel={onCancel}
+ size="xs"
/>
</form>
);
diff --git a/src/client/features/projects/project-context/KeyPagesSection.tsx b/src/client/features/projects/project-context/KeyPagesSection.tsx
index 74d364a4..1832b4dc 100644
--- a/src/client/features/projects/project-context/KeyPagesSection.tsx
+++ b/src/client/features/projects/project-context/KeyPagesSection.tsx
@@ -7,15 +7,15 @@ import {
type ProjectContextUpdate,
} from "@/types/schemas/projectContext";
import {
- EmptyState,
- FormActions,
listClass,
Provenance,
RowActions,
- SectionHeader,
useContextUpdate,
type ContextKeyPage,
} from "./shared";
+import { EmptyState } from "@/client/components/EmptyState";
+import { FormActions } from "@/client/components/FormActions";
+import { SectionHeader } from "@/client/components/PageHeader";
const ROLE_LABELS: Record<KeyPageRole, string> = {
hub: "Hub page",
@@ -92,10 +92,12 @@ export function KeyPagesSection({
{keyPages.length === 0 ? (
adding ? null : (
- <EmptyState>
- No key pages yet. Add the handful that has to rank, or let an agent
- propose them from your last site audit.
- </EmptyState>
+ <EmptyState
+ size="sm"
+ icon={null}
+ title="No key pages yet"
+ description="Add the handful that has to rank, or let an agent propose them from your last site audit."
+ />
)
) : (
<ul className={listClass}>
@@ -248,6 +250,7 @@ function KeyPageForm({
pending={pending}
disabled={!draft.url.trim()}
onCancel={onCancel}
+ size="xs"
/>
</form>
);
diff --git a/src/client/features/projects/project-context/ProjectContextPage.tsx b/src/client/features/projects/project-context/ProjectContextPage.tsx
index 8f1dfa0e..1271c945 100644
--- a/src/client/features/projects/project-context/ProjectContextPage.tsx
+++ b/src/client/features/projects/project-context/ProjectContextPage.tsx
@@ -13,16 +13,16 @@ import {
import { CompetitorsSection } from "./CompetitorsSection";
import { KeyPagesSection } from "./KeyPagesSection";
import {
- EmptyState,
- FormActions,
listClass,
Provenance,
RowActions,
- SectionHeader,
projectContextQueryKey,
useContextUpdate,
type ProjectContextData,
} from "./shared";
+import { EmptyState } from "@/client/components/EmptyState";
+import { FormActions } from "@/client/components/FormActions";
+import { SectionHeader } from "@/client/components/PageHeader";
const SECTION_HINTS: Record<ProjectContextSectionKey, string> = {
business_overview: "What you sell, who buys it, and where.",
@@ -148,10 +148,12 @@ function ProseSections({
return (
<form onSubmit={handleSubmit} className="space-y-5">
{missingSections.length === PROJECT_CONTEXT_SECTION_KEYS.length ? (
- <EmptyState>
- Nothing written down yet. Fill in what you can — or ask SAM to draft
- it from your site and confirm what it got right.
- </EmptyState>
+ <EmptyState
+ size="sm"
+ icon={null}
+ title="Nothing written down yet"
+ description="Fill in what you can — or ask SAM to draft it from your site and confirm what it got right."
+ />
) : null}
{PROJECT_CONTEXT_SECTION_KEYS.map((key) => {
@@ -228,10 +230,12 @@ function CustomSections({
/>
{customSections.length === 0 ? (
- <EmptyState>
- Nothing here yet. Agents add a section when they learn something
- important that has nowhere else to live.
- </EmptyState>
+ <EmptyState
+ size="sm"
+ icon={null}
+ title="Nothing here yet"
+ description="Agents add a section when they learn something important that has nowhere else to live."
+ />
) : (
<div className="space-y-3">
{customSections.map((custom) =>
@@ -334,6 +338,7 @@ function CustomSectionForm({
pending={pending}
disabled={!content.trim()}
onCancel={onCancel}
+ size="xs"
/>
</form>
);
@@ -356,9 +361,12 @@ function ResearchLog({
/>
{researchLog.length === 0 ? (
- <EmptyState>
- Nothing logged yet. Agents record paid research here as they run it.
- </EmptyState>
+ <EmptyState
+ size="sm"
+ icon={null}
+ title="Nothing logged yet"
+ description="Agents record paid research here as they run it."
+ />
) : (
<ul className={listClass}>
{researchLog.map((entry) => (
diff --git a/src/client/features/projects/project-context/shared.tsx b/src/client/features/projects/project-context/shared.tsx
index 8ac70c6c..cbfecd0d 100644
--- a/src/client/features/projects/project-context/shared.tsx
+++ b/src/client/features/projects/project-context/shared.tsx
@@ -60,35 +60,6 @@ export function Provenance({ by, at }: { by: ContextAuthor; at?: string }) {
);
}
-export function SectionHeader({
- title,
- hint,
- action,
-}: {
- title: string;
- hint?: string;
- action?: ReactNode;
-}) {
- return (
- <div className="flex items-start justify-between gap-3">
- <div className="space-y-0.5">
- <h2 className="text-sm font-medium text-base-content/50">{title}</h2>
- {hint ? <p className="text-xs text-base-content/50">{hint}</p> : null}
- </div>
- {action}
- </div>
- );
-}
-
-/** Muted panel used when a list has nothing in it yet. */
-export function EmptyState({ children }: { children: ReactNode }) {
- return (
- <p className="rounded-lg border border-dashed border-base-300 px-4 py-3 text-sm text-base-content/60">
- {children}
- </p>
- );
-}
-
export const listClass =
"divide-y divide-base-300 overflow-hidden rounded-lg border border-base-300";
@@ -96,33 +67,3 @@ export const listClass =
export function RowActions({ children }: { children: ReactNode }) {
return <div className="flex shrink-0 items-center gap-1">{children}</div>;
}
-
-export function FormActions({
- pending,
- disabled,
- onCancel,
-}: {
- pending: boolean;
- disabled: boolean;
- onCancel: () => void;
-}) {
- return (
- <div className="flex justify-end gap-2">
- <button
- type="button"
- className="btn btn-ghost btn-xs"
- onClick={onCancel}
- disabled={pending}
- >
- Cancel
- </button>
- <button
- type="submit"
- className="btn btn-primary btn-xs"
- disabled={disabled || pending}
- >
- Save
- </button>
- </div>
- );
-}
diff --git a/src/client/features/reports/ReportTemplatesList.tsx b/src/client/features/reports/ReportTemplatesList.tsx
index ddc32e69..60eca457 100644
--- a/src/client/features/reports/ReportTemplatesList.tsx
+++ b/src/client/features/reports/ReportTemplatesList.tsx
@@ -1,4 +1,5 @@
-import { Pencil, Trash2 } from "lucide-react";
+import { LayoutTemplate, Pencil, Trash2 } from "lucide-react";
+import { EmptyState } from "@/client/components/EmptyState";
import { RowActionsMenu } from "@/client/components/RowActionsMenu";
import { DropdownMenuItem } from "@/client/components/ui/dropdown-menu";
import { formatRelativeTime } from "@/client/lib/relative-time";
@@ -15,10 +16,11 @@ export function ReportTemplatesList({
}) {
if (templates.length === 0) {
return (
- <p className="rounded-lg border border-dashed border-base-300 px-4 py-6 text-sm text-base-content/60">
- No templates yet. A template is a reusable brief for a kind of report:
- who it is for, which sections it has, how it sounds.
- </p>
+ <EmptyState
+ icon={LayoutTemplate}
+ title="No templates yet"
+ description="A template is a reusable brief for a kind of report: who it is for, which sections it has, how it sounds."
+ />
);
}
diff --git a/src/client/features/reports/ReportsList.tsx b/src/client/features/reports/ReportsList.tsx
index aee29270..e957339e 100644
--- a/src/client/features/reports/ReportsList.tsx
+++ b/src/client/features/reports/ReportsList.tsx
@@ -1,5 +1,6 @@
import { Link } from "@tanstack/react-router";
-import { Trash2 } from "lucide-react";
+import { FileText, Trash2 } from "lucide-react";
+import { EmptyState } from "@/client/components/EmptyState";
import { PortalMenu } from "@/client/components/PortalMenu";
import { formatCreatedBy } from "@/client/features/reports/shared";
import { formatRelativeTime } from "@/client/lib/relative-time";
@@ -17,10 +18,11 @@ export function ReportsList({
}) {
if (reports.length === 0) {
return (
- <p className="rounded-lg border border-dashed border-base-300 px-4 py-6 text-sm text-base-content/60">
- No reports yet. Run an OpenSEO skill such as seo-audit from Claude Code
- or Codex and the report will appear here.
- </p>
+ <EmptyState
+ icon={FileText}
+ title="No reports yet"
+ description="Run an OpenSEO skill such as seo-audit from Claude Code or Codex and the report will appear here."
+ />
);
}
diff --git a/src/client/features/settings/ApiKeySettings.tsx b/src/client/features/settings/ApiKeySettings.tsx
index 90541798..442087c5 100644
--- a/src/client/features/settings/ApiKeySettings.tsx
+++ b/src/client/features/settings/ApiKeySettings.tsx
@@ -15,7 +15,7 @@ import {
} from "@/client/components/ui/dialog";
import { RowActionsMenu } from "@/client/components/RowActionsMenu";
import { DropdownMenuItem } from "@/client/components/ui/dropdown-menu";
-import { CopyButton } from "@/client/features/ai-mcp/SetupControls";
+import { CopyButton } from "@/client/components/CopyButton";
import { captureClientEvent } from "@/client/lib/posthog";
import { authClient } from "@/lib/auth-client";
@@ -232,7 +232,9 @@ export function ApiKeySettings() {
<CopyButton
value={createdKey}
successMessage="API key copied"
- iconOnly
+ label="Copy API key"
+ variant="ghost"
+ size="icon-sm"
/>
</div>
<DialogFooter>
diff --git a/src/client/hooks/useCopy.ts b/src/client/hooks/useCopy.ts
new file mode 100644
index 00000000..345872b4
--- /dev/null
+++ b/src/client/hooks/useCopy.ts
@@ -0,0 +1,28 @@
+import { useRef, useState } from "react";
+import { toast } from "sonner";
+
+/**
+ * Copies text to the clipboard with a toast. `copied` stays true for two
+ * seconds after a copy, for a check mark on the button.
+ */
+export function useCopy() {
+ const [copied, setCopied] = useState(false);
+ const resetTimer = useRef<ReturnType<typeof setTimeout>>(undefined);
+
+ const copy = async (value: string, successMessage: string) => {
+ try {
+ await navigator.clipboard.writeText(value);
+ } catch {
+ toast.error("Could not copy to clipboard");
+ return false;
+ }
+ toast.success(successMessage);
+ setCopied(true);
+ // A second copy restarts the two seconds.
+ clearTimeout(resetTimer.current);
+ resetTimer.current = setTimeout(() => setCopied(false), 2000);
+ return true;
+ };
+
+ return { copied, copy };
+}
diff --git a/src/routes/_app/ai.tsx b/src/routes/_app/ai.tsx
index 945be7c1..4a23b208 100644
--- a/src/routes/_app/ai.tsx
+++ b/src/routes/_app/ai.tsx
@@ -12,7 +12,7 @@ import {
agentUpdatePrompt,
getAgentSetupPrompt,
} from "@/client/features/ai-mcp/agentSetupPrompt";
-import { CopyButton } from "@/client/features/ai-mcp/SetupControls";
+import { CopyButton } from "@/client/components/CopyButton";
import { AgentList } from "@/client/features/ai-mcp/AgentList";
const DOCS_URL = "https://openseo.so/docs/agent-setup";
@@ -72,9 +72,11 @@ function AiPage() {
steps.
</p>
<AgentList />
- <div className="mt-5 flex flex-wrap items-center gap-x-5 gap-y-3 [&>button]:h-11 [&>button]:gap-2 [&>button]:text-sm">
+ <div className="mt-5 flex flex-wrap items-center gap-x-5 gap-y-3">
<CopyButton
- primary
+ variant="default"
+ size="lg"
+ className="h-11 gap-2 px-4"
value={prompt}
label="Copy setup prompt"
successMessage="Setup prompt copied"
@@ -111,9 +113,11 @@ function AiPage() {
get the latest OpenSEO skills while preserving your connection
settings and personal edits.
</p>
- <div className="mt-5 flex flex-wrap items-center gap-x-5 gap-y-3 [&>button]:h-11 [&>button]:gap-2 [&>button]:text-sm">
+ <div className="mt-5 flex flex-wrap items-center gap-x-5 gap-y-3">
<CopyButton
- primary
+ variant="default"
+ size="lg"
+ className="h-11 gap-2 px-4"
value={agentUpdatePrompt}
label="Copy update prompt"
successMessage="Update prompt copied"
diff --git a/src/routes/_app/p/$projectId/context.tsx b/src/routes/_app/p/$projectId/context.tsx
index e40ecd33..f2519fb3 100644
--- a/src/routes/_app/p/$projectId/context.tsx
+++ b/src/routes/_app/p/$projectId/context.tsx
@@ -1,6 +1,7 @@
import { createFileRoute } from "@tanstack/react-router";
import { projectsQueryOptions } from "@/client/features/projects/projectQueries";
import { useQuery } from "@tanstack/react-query";
+import { PageHeader } from "@/client/components/PageHeader";
import { ProjectContextPage } from "@/client/features/projects/project-context/ProjectContextPage";
export const Route = createFileRoute("/_app/p/$projectId/context")({
@@ -15,10 +16,7 @@ function ProjectContextRoute() {
return (
<div className="h-full overflow-auto bg-base-100">
<div className="mx-auto w-full max-w-2xl space-y-8 p-4 py-8 pb-24 sm:p-6 md:py-12 md:pb-12">
- <div>
- <h1 className="text-2xl font-bold tracking-tight">Context</h1>
- <p className="text-sm text-base-content/60">{project?.name ?? " "}</p>
- </div>
+ <PageHeader title="Context" description={project?.name ?? " "} />
<ProjectContextPage projectId={projectId} />
</div>
diff --git a/src/routes/_app/p/$projectId/reports/$reportId.tsx b/src/routes/_app/p/$projectId/reports/$reportId.tsx
index 046cf5ed..4775bf9e 100644
--- a/src/routes/_app/p/$projectId/reports/$reportId.tsx
+++ b/src/routes/_app/p/$projectId/reports/$reportId.tsx
@@ -1,8 +1,7 @@
-import { createFileRoute, Link, useNavigate } from "@tanstack/react-router";
+import { createFileRoute, useNavigate } from "@tanstack/react-router";
import { useQuery } from "@tanstack/react-query";
import { useCallback, useEffect, useRef, useState } from "react";
import {
- ChevronLeft,
ExternalLink,
FileDown,
Globe,
@@ -13,6 +12,7 @@ import {
Trash2,
} from "lucide-react";
import { z } from "zod";
+import { BackLink, PageHeader } from "@/client/components/PageHeader";
import { PortalMenu } from "@/client/components/PortalMenu";
import { QueryError } from "@/client/components/QueryState";
import { PageLoading } from "@/client/components/Spinner";
@@ -89,14 +89,12 @@ function ReportDetailPage() {
return <PageLoading />;
}
- const loadError = (
- <QueryError
- error={reportQuery.error}
- fallback="Failed to load the report"
- onRetry={() => void reportQuery.refetch()}
- isRetrying={reportQuery.isFetching}
- />
- );
+ const loadError = {
+ error: reportQuery.error,
+ fallback: "Failed to load the report",
+ onRetry: () => void reportQuery.refetch(),
+ isRetrying: reportQuery.isFetching,
+ };
// A failed refetch keeps the loaded report on screen, unless the report is
// gone: then the not-found answer replaces it.
@@ -106,21 +104,25 @@ function ReportDetailPage() {
return (
<div className="px-4 py-6 md:px-6">
<div className="mx-auto max-w-3xl space-y-4">
+ <BackLink to="/p/$projectId/reports" params={{ projectId }}>
+ Reports
+ </BackLink>
{/* A deleted report and another project's report are the same
answer on purpose, so ids cannot be probed. Retrying either
cannot help. */}
{notFound ? (
- <QueryError fallback="This report does not exist or you do not have access to it." />
+ <QueryError
+ variant="page"
+ title="Report not found"
+ fallback="This report does not exist or you do not have access to it."
+ />
) : (
- loadError
+ <QueryError
+ variant="page"
+ title="Couldn't load the report"
+ {...loadError}
+ />
)}
- <Link
- to="/p/$projectId/reports"
- params={{ projectId }}
- className="btn btn-ghost btn-sm"
- >
- &larr; Back to reports
- </Link>
</div>
</div>
);
@@ -150,20 +152,15 @@ function ReportDetailPage() {
return (
<div className="flex h-full min-h-0 flex-col gap-3 px-4 py-4 md:px-6 md:py-6">
- {reportQuery.isError ? loadError : null}
+ {reportQuery.isError ? <QueryError {...loadError} /> : null}
<div className="space-y-3">
- <Link
- to="/p/$projectId/reports"
- params={{ projectId }}
- className="inline-flex items-center gap-1 text-sm text-base-content/60 transition-colors hover:text-base-content"
- >
- <ChevronLeft className="size-4" />
+ <BackLink to="/p/$projectId/reports" params={{ projectId }}>
Reports
- </Link>
- <div className="flex flex-wrap items-start justify-between gap-3">
- <div className="min-w-0">
- <h1 className="text-2xl font-semibold">{report.title}</h1>
- <dl className="mt-1.5 flex flex-wrap items-baseline gap-x-6 gap-y-1 text-sm">
+ </BackLink>
+ <PageHeader
+ title={report.title}
+ description={
+ <dl className="flex flex-wrap items-baseline gap-x-6 gap-y-1 text-foreground">
<div className="flex items-baseline gap-1.5">
<dt className="text-base-content/50">Created by</dt>
<dd>{formatCreatedBy(report)}</dd>
@@ -181,80 +178,82 @@ function ReportDetailPage() {
</dd>
</div>
</dl>
- </div>
- <div className="flex shrink-0 items-center gap-2">
- {/* Share links are hosted-only (see shareAccess.ts), so a
+ }
+ actions={
+ <>
+ {/* Share links are hosted-only (see shareAccess.ts), so a
self-hosted deployment keeps Export as its primary action
rather than offering a button the server would refuse. The
icon carries the state: a globe once a public link is live, a
lock while only members can open it. */}
- {hosted ? (
- <button
- type="button"
- className="btn btn-primary btn-sm gap-1.5"
- onClick={() => setShowShare(true)}
+ {hosted ? (
+ <button
+ type="button"
+ className="btn btn-primary btn-sm gap-1.5"
+ onClick={() => setShowShare(true)}
+ >
+ {report.shareToken ? (
+ <Globe className="size-4" />
+ ) : (
+ <Lock className="size-4" />
+ )}
+ Share
+ </button>
+ ) : (
+ <button
+ type="button"
+ className="btn btn-primary btn-sm gap-1.5"
+ onClick={exportPdf}
+ >
+ <FileDown className="size-4" />
+ Export
+ </button>
+ )}
+ <PortalMenu
+ ariaLabel="Report actions"
+ triggerClassName="btn btn-ghost btn-sm btn-square"
+ triggerContent={<MoreHorizontal className="size-4" />}
+ menuClassName="w-52"
>
- {report.shareToken ? (
- <Globe className="size-4" />
- ) : (
- <Lock className="size-4" />
+ {(close) => (
+ <>
+ {hosted ? (
+ <>
+ <li>
+ <button
+ onClick={() => {
+ close();
+ exportPdf();
+ }}
+ >
+ <FileDown className="size-4" />
+ Export
+ </button>
+ </li>
+ <li
+ role="separator"
+ className="mx-1 my-1 h-px bg-base-300"
+ />
+ </>
+ ) : null}
+ <li>
+ <button
+ className="text-error"
+ onClick={() => {
+ close();
+ setShowDelete(true);
+ }}
+ >
+ <Trash2 className="size-4" />
+ Delete
+ </button>
+ </li>
+ </>
)}
- Share
- </button>
- ) : (
- <button
- type="button"
- className="btn btn-primary btn-sm gap-1.5"
- onClick={exportPdf}
- >
- <FileDown className="size-4" />
- Export
- </button>
- )}
- <PortalMenu
- ariaLabel="Report actions"
- triggerClassName="btn btn-ghost btn-sm btn-square"
- triggerContent={<MoreHorizontal className="size-4" />}
- menuClassName="w-52"
- >
- {(close) => (
- <>
- {hosted ? (
- <>
- <li>
- <button
- onClick={() => {
- close();
- exportPdf();
- }}
- >
- <FileDown className="size-4" />
- Export
- </button>
- </li>
- <li
- role="separator"
- className="mx-1 my-1 h-px bg-base-300"
- />
- </>
- ) : null}
- <li>
- <button
- className="text-error"
- onClick={() => {
- close();
- setShowDelete(true);
- }}
- >
- <Trash2 className="size-4" />
- Delete
- </button>
- </li>
- </>
- )}
- </PortalMenu>
- </div>
- </div>
+ </PortalMenu>
+ </>
+ }
+ />
</div>
<div className="relative min-h-0 flex-1">
diff --git a/src/routes/_app/p/$projectId/reports/index.tsx b/src/routes/_app/p/$projectId/reports/index.tsx
index 81196ce3..fcbfc096 100644
--- a/src/routes/_app/p/$projectId/reports/index.tsx
+++ b/src/routes/_app/p/$projectId/reports/index.tsx
@@ -1,4 +1,6 @@
import { createFileRoute, Link } from "@tanstack/react-router";
+import { PageHeader } from "@/client/components/PageHeader";
+import { Button } from "@/client/components/ui/button";
import { useQuery } from "@tanstack/react-query";
import { useState } from "react";
import { ReportsList } from "@/client/features/reports/ReportsList";
@@ -37,21 +39,24 @@ function ReportsPage() {
return (
<div className="overflow-auto px-4 py-4 pb-24 md:px-6 md:py-6 md:pb-8">
<div className="mx-auto max-w-5xl space-y-4">
- <div className="flex flex-wrap items-start justify-between gap-3">
- <div>
- <h1 className="text-2xl font-semibold">Reports</h1>
- <p className="text-sm text-base-content/70">
- HTML reports your agents saved to this project.
- </p>
- </div>
- <Link
- to="/p/$projectId/reports/templates"
- params={{ projectId }}
- className="btn btn-ghost btn-sm"
- >
- Templates
- </Link>
- </div>
+ <PageHeader
+ title="Reports"
+ description="HTML reports your agents saved to this project."
+ actions={
+ <Button
+ variant="ghost"
+ nativeButton={false}
+ render={
+ <Link
+ to="/p/$projectId/reports/templates"
+ params={{ projectId }}
+ />
+ }
+ >
+ Templates
+ </Button>
+ }
+ />
<QueryState query={reportsQuery} errorFallback="Failed to load reports">
{(data) => (
diff --git a/src/routes/_app/p/$projectId/reports/templates.tsx b/src/routes/_app/p/$projectId/reports/templates.tsx
index 98f5554a..dcd37280 100644
--- a/src/routes/_app/p/$projectId/reports/templates.tsx
+++ b/src/routes/_app/p/$projectId/reports/templates.tsx
@@ -1,10 +1,12 @@
-import { createFileRoute, Link } from "@tanstack/react-router";
+import { createFileRoute } from "@tanstack/react-router";
import { useMutation, useQuery, useQueryClient } from "@tanstack/react-query";
import { useState } from "react";
-import { ChevronLeft, Plus } from "lucide-react";
+import { Plus } from "lucide-react";
import { toast } from "sonner";
import { ConfirmDialog } from "@/client/components/ConfirmDialog";
+import { BackLink, PageHeader } from "@/client/components/PageHeader";
import { QueryState } from "@/client/components/QueryState";
+import { Button } from "@/client/components/ui/button";
import { ReportTemplateForm } from "@/client/features/reports/ReportTemplateForm";
import { ReportTemplatesList } from "@/client/features/reports/ReportTemplatesList";
import {
@@ -64,32 +66,20 @@ function ReportTemplatesPage() {
return (
<div className="overflow-auto px-4 py-4 pb-24 md:px-6 md:py-6 md:pb-8">
<div className="mx-auto max-w-5xl space-y-4">
- <Link
- to="/p/$projectId/reports"
- params={{ projectId }}
- className="inline-flex items-center gap-1 text-sm text-base-content/60 transition-colors hover:text-base-content"
- >
- <ChevronLeft className="size-4" />
+ <BackLink to="/p/$projectId/reports" params={{ projectId }}>
Reports
- </Link>
+ </BackLink>
- <div className="flex flex-wrap items-start justify-between gap-3">
- <div>
- <h1 className="text-2xl font-semibold">Report templates</h1>
- <p className="text-sm text-base-content/70">
- Reusable briefs your agents follow when they write a report: who
- it is for, which sections it has, and how it should sound.
- </p>
- </div>
- <button
- type="button"
- className="btn btn-primary btn-sm gap-1.5"
- onClick={() => setForm({})}
- >
- <Plus className="size-4" />
- New template
- </button>
- </div>
+ <PageHeader
+ title="Report templates"
+ description="Reusable briefs your agents follow when they write a report: who it is for, which sections it has, and how it should sound."
+ actions={
+ <Button onClick={() => setForm({})}>
+ <Plus data-icon="inline-start" />
+ New template
+ </Button>
+ }
+ />
<QueryState
query={templatesQuery}
diff --git a/src/routes/_app/p/$projectId/settings.tsx b/src/routes/_app/p/$projectId/settings.tsx
index 1aba97ab..63821895 100644
--- a/src/routes/_app/p/$projectId/settings.tsx
+++ b/src/routes/_app/p/$projectId/settings.tsx
@@ -1,8 +1,8 @@
-import { createFileRoute, Link, Outlet } from "@tanstack/react-router";
+import { createFileRoute, Outlet } from "@tanstack/react-router";
import { NavTab, NavTabs } from "@/client/components/NavTabs";
import { projectsQueryOptions } from "@/client/features/projects/projectQueries";
import { useQuery } from "@tanstack/react-query";
-import { ChevronLeft } from "lucide-react";
+import { BackLink, PageHeader } from "@/client/components/PageHeader";
export const Route = createFileRoute("/_app/p/$projectId/settings")({
component: ProjectSettingsLayout,
@@ -22,21 +22,11 @@ function ProjectSettingsLayout() {
<div className="h-full overflow-auto bg-base-100">
<div className="mx-auto w-full max-w-2xl space-y-8 p-4 py-8 pb-24 sm:p-6 md:py-12 md:pb-12">
<div className="space-y-4">
- <Link
- to="/projects"
- className="inline-flex items-center gap-1 text-sm text-base-content/60 transition-colors hover:text-base-content"
- >
- <ChevronLeft className="size-4" />
- Projects
- </Link>
- <div>
- <h1 className="text-2xl font-bold tracking-tight">
- Project settings
- </h1>
- <p className="text-sm text-base-content/60">
- {project?.name ?? " "}
- </p>
- </div>
+ <BackLink to="/projects">Projects</BackLink>
+ <PageHeader
+ title="Project settings"
+ description={project?.name ?? " "}
+ />
<NavTabs label="Project settings sections">
{tabs.map((tab) => (
<NavTab