Skip to content

Open-source agentic AI Search Execution Platform. Track AI visibility, find opportunities, and let agents turn signals into prioritized actions and drafted fixes across ChatGPT, Claude, Gemini, Google AI Overviews, Google AI Mode, Perplexity, Grok, and Microsoft Copilot.

feat(billing): show the AI usage meter on the detail pages too (AI usage display, part 4) (#1434)

Cihan1a5dc0e695ac
diff --git a/web/src/app/[locale]/(dashboard)/dashboard/audit/[id]/page.tsx b/web/src/app/[locale]/(dashboard)/dashboard/audit/[id]/page.tsx
index 5a536c634..3166ede56 100644
--- a/web/src/app/[locale]/(dashboard)/dashboard/audit/[id]/page.tsx
+++ b/web/src/app/[locale]/(dashboard)/dashboard/audit/[id]/page.tsx
@@ -20,6 +20,7 @@ import {
} from '@/components/ui/dialog';
import { getAudit, runAudit, deleteAudit, type AuditResult } from '@/lib/actions/audits';
import { AuditReport } from '@/components/audit/audit-report';
+import { HeaderWithAiUsage } from '@/components/ai-usage/ai-usage-meter';
export default function AuditDetailPage() {
const params = useParams();
@@ -137,58 +138,60 @@ export default function AuditDetailPage() {
return (
<div className="space-y-6">
- <div className="flex items-center justify-between">
- <Link
- href="/dashboard/audit"
- className="inline-flex items-center gap-1 text-sm text-muted-foreground hover:text-foreground"
- >
- <ArrowLeft className="h-4 w-4" /> {t('title')}
- </Link>
- {audit && (audit.status !== 'running' || timedOut) && (
- <div className="flex items-center gap-1">
- <Button
- variant="ghost"
- size="icon"
- className="h-8 w-8 text-muted-foreground hover:text-foreground"
- disabled={rerunning}
- onClick={handleRefresh}
- aria-label={t('reaudit')}
- >
- {rerunning ? (
- <Loader2 className="h-3.5 w-3.5 animate-spin" />
- ) : (
- <RefreshCw className="h-3.5 w-3.5" />
- )}
- </Button>
- <Dialog>
- <DialogTrigger
- render={
- <Button
- variant="ghost"
- size="icon"
- className="h-8 w-8 text-muted-foreground hover:text-destructive"
- aria-label={t('deleteAudit')}
- />
- }
+ <HeaderWithAiUsage>
+ <div className="flex items-center justify-between">
+ <Link
+ href="/dashboard/audit"
+ className="inline-flex items-center gap-1 text-sm text-muted-foreground hover:text-foreground"
+ >
+ <ArrowLeft className="h-4 w-4" /> {t('title')}
+ </Link>
+ {audit && (audit.status !== 'running' || timedOut) && (
+ <div className="flex items-center gap-1">
+ <Button
+ variant="ghost"
+ size="icon"
+ className="h-8 w-8 text-muted-foreground hover:text-foreground"
+ disabled={rerunning}
+ onClick={handleRefresh}
+ aria-label={t('reaudit')}
>
- <Trash2 className="h-3.5 w-3.5" />
- </DialogTrigger>
- <DialogContent className="sm:max-w-sm">
- <DialogHeader>
- <DialogTitle>{t('deleteAudit')}</DialogTitle>
- <DialogDescription>{t('deleteConfirm')}</DialogDescription>
- </DialogHeader>
- <DialogFooter>
- <DialogClose render={<Button variant="outline" />}>{t('cancel')}</DialogClose>
- <DialogClose render={<Button variant="destructive" onClick={handleDelete} />}>
- {t('deleteAudit')}
- </DialogClose>
- </DialogFooter>
- </DialogContent>
- </Dialog>
- </div>
- )}
- </div>
+ {rerunning ? (
+ <Loader2 className="h-3.5 w-3.5 animate-spin" />
+ ) : (
+ <RefreshCw className="h-3.5 w-3.5" />
+ )}
+ </Button>
+ <Dialog>
+ <DialogTrigger
+ render={
+ <Button
+ variant="ghost"
+ size="icon"
+ className="h-8 w-8 text-muted-foreground hover:text-destructive"
+ aria-label={t('deleteAudit')}
+ />
+ }
+ >
+ <Trash2 className="h-3.5 w-3.5" />
+ </DialogTrigger>
+ <DialogContent className="sm:max-w-sm">
+ <DialogHeader>
+ <DialogTitle>{t('deleteAudit')}</DialogTitle>
+ <DialogDescription>{t('deleteConfirm')}</DialogDescription>
+ </DialogHeader>
+ <DialogFooter>
+ <DialogClose render={<Button variant="outline" />}>{t('cancel')}</DialogClose>
+ <DialogClose render={<Button variant="destructive" onClick={handleDelete} />}>
+ {t('deleteAudit')}
+ </DialogClose>
+ </DialogFooter>
+ </DialogContent>
+ </Dialog>
+ </div>
+ )}
+ </div>
+ </HeaderWithAiUsage>
{loading ? (
<Card>
diff --git a/web/src/app/[locale]/(dashboard)/dashboard/brands/[id]/layout.tsx b/web/src/app/[locale]/(dashboard)/dashboard/brands/[id]/layout.tsx
index 233fdfad1..1770fbe54 100644
--- a/web/src/app/[locale]/(dashboard)/dashboard/brands/[id]/layout.tsx
+++ b/web/src/app/[locale]/(dashboard)/dashboard/brands/[id]/layout.tsx
@@ -19,6 +19,7 @@ import {
import { brandPagePath } from '@/lib/brand-path';
import { cn } from '@/lib/utils';
import { ArrowLeft, ChevronsUpDown, MessageSquareText, Settings, Tag } from 'lucide-react';
+import { HeaderWithAiUsage } from '@/components/ai-usage/ai-usage-meter';
const SUB_NAV = [
{ href: 'topics', label: 'Topics', icon: Tag },
@@ -51,53 +52,55 @@ export default function BrandDetailLayout({
return (
<div className="space-y-6">
{/* Brand header + back; Workspace Settings wraps below it on a phone. */}
- <div className="flex flex-wrap items-center gap-4">
- <Link href="/dashboard/brands">
- <Button variant="ghost" size="icon" aria-label="Back to brands list">
- <ArrowLeft className="h-4 w-4" />
- </Button>
- </Link>
- {brand && (
- <div className="flex items-center gap-3">
- <BrandAvatar
- logoUrl={brand.logoUrl}
- name={brand.name}
- domains={brand.domains}
- className="h-9 w-9 rounded-lg bg-zinc-50 dark:bg-zinc-100"
- fallbackClassName="rounded-lg bg-primary text-primary-foreground text-sm font-semibold"
- imageClassName="object-contain p-1"
- />
- <div>
- <div className="flex items-center gap-1">
- <h1 className="text-xl font-bold tracking-tight">{brand.name}</h1>
- <DropdownMenu>
- <DropdownMenuTrigger
- aria-label={t('switchBrand')}
- className="inline-flex h-7 w-7 items-center justify-center rounded-md text-muted-foreground transition-colors hover:bg-muted hover:text-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring/50"
- >
- <ChevronsUpDown className="h-4 w-4" />
- </DropdownMenuTrigger>
- <DropdownMenuContent className="w-56" align="start">
- <DropdownMenuGroup>
- <DropdownMenuLabel className="text-xs text-muted-foreground">
- {t('switchBrand')}
- </DropdownMenuLabel>
- </DropdownMenuGroup>
- <DropdownMenuSeparator />
- <BrandSwitchItems brands={brands} currentId={id} onSelect={switchTo} />
- </DropdownMenuContent>
- </DropdownMenu>
+ <HeaderWithAiUsage>
+ <div className="flex flex-wrap items-center gap-4">
+ <Link href="/dashboard/brands">
+ <Button variant="ghost" size="icon" aria-label="Back to brands list">
+ <ArrowLeft className="h-4 w-4" />
+ </Button>
+ </Link>
+ {brand && (
+ <div className="flex items-center gap-3">
+ <BrandAvatar
+ logoUrl={brand.logoUrl}
+ name={brand.name}
+ domains={brand.domains}
+ className="h-9 w-9 rounded-lg bg-zinc-50 dark:bg-zinc-100"
+ fallbackClassName="rounded-lg bg-primary text-primary-foreground text-sm font-semibold"
+ imageClassName="object-contain p-1"
+ />
+ <div>
+ <div className="flex items-center gap-1">
+ <h1 className="text-xl font-bold tracking-tight">{brand.name}</h1>
+ <DropdownMenu>
+ <DropdownMenuTrigger
+ aria-label={t('switchBrand')}
+ className="inline-flex h-7 w-7 items-center justify-center rounded-md text-muted-foreground transition-colors hover:bg-muted hover:text-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring/50"
+ >
+ <ChevronsUpDown className="h-4 w-4" />
+ </DropdownMenuTrigger>
+ <DropdownMenuContent className="w-56" align="start">
+ <DropdownMenuGroup>
+ <DropdownMenuLabel className="text-xs text-muted-foreground">
+ {t('switchBrand')}
+ </DropdownMenuLabel>
+ </DropdownMenuGroup>
+ <DropdownMenuSeparator />
+ <BrandSwitchItems brands={brands} currentId={id} onSelect={switchTo} />
+ </DropdownMenuContent>
+ </DropdownMenu>
+ </div>
+ <p className="text-xs text-muted-foreground">
+ {brand.domains.find((d) => d.isPrimary)?.domain ?? ''}
+ </p>
</div>
- <p className="text-xs text-muted-foreground">
- {brand.domains.find((d) => d.isPrimary)?.domain ?? ''}
- </p>
</div>
+ )}
+ <div className="ml-auto">
+ <WorkspaceSettingsMenu />
</div>
- )}
- <div className="ml-auto">
- <WorkspaceSettingsMenu />
</div>
- </div>
+ </HeaderWithAiUsage>
{/* Sub-nav */}
<nav className="flex gap-1 border-b">
diff --git a/web/src/app/[locale]/(dashboard)/dashboard/citations/url/page.tsx b/web/src/app/[locale]/(dashboard)/dashboard/citations/url/page.tsx
index 843b969f7..f0436ac3c 100644
--- a/web/src/app/[locale]/(dashboard)/dashboard/citations/url/page.tsx
+++ b/web/src/app/[locale]/(dashboard)/dashboard/citations/url/page.tsx
@@ -55,6 +55,7 @@ import {
} from 'lucide-react';
import { formatDate } from '@/lib/format';
import { cn } from '@/lib/utils';
+import { HeaderWithAiUsage } from '@/components/ai-usage/ai-usage-meter';
const CITED_IN_PAGE_SIZE = 10;
const DATE_PRESET_VALUES: CitationsDatePreset[] = ['24h', '7d', '30d', '90d', 'all', 'custom'];
@@ -203,54 +204,56 @@ export default function CitationUrlDetailPage() {
return (
<div className="space-y-6">
- <div>
- <BackLink />
- {/* Header */}
- <div className="mt-2 flex flex-wrap items-start justify-between gap-3">
- <div className="flex items-start gap-3 min-w-0">
- <div className="pt-1">
- <DomainFavicon domain={data?.domain || extractDisplayHost(targetUrl)} />
+ <HeaderWithAiUsage>
+ <div>
+ <BackLink />
+ {/* Header */}
+ <div className="mt-2 flex flex-wrap items-start justify-between gap-3">
+ <div className="flex items-start gap-3 min-w-0">
+ <div className="pt-1">
+ <DomainFavicon domain={data?.domain || extractDisplayHost(targetUrl)} />
+ </div>
+ <div className="min-w-0">
+ <h1 className="text-xl font-bold tracking-tight leading-tight break-all">
+ {data?.title || targetUrl}
+ </h1>
+ <div className="mt-1 flex flex-wrap items-center gap-2">
+ <a
+ href={targetUrl}
+ target="_blank"
+ rel="noreferrer noopener"
+ className="inline-flex max-w-[560px] items-center gap-1 text-xs text-muted-foreground hover:text-foreground hover:underline"
+ >
+ <span className="truncate">{targetUrl}</span>
+ <ExternalLink className="h-3 w-3 shrink-0" />
+ </a>
+ {data && <CategoryBadge category={data.category} />}
+ {data?.articleType && (
+ <Badge variant="outline" className="text-[10px] font-medium">
+ {data.articleType}
+ </Badge>
+ )}
+ </div>
+ </div>
</div>
- <div className="min-w-0">
- <h1 className="text-xl font-bold tracking-tight leading-tight break-all">
- {data?.title || targetUrl}
- </h1>
- <div className="mt-1 flex flex-wrap items-center gap-2">
- <a
- href={targetUrl}
- target="_blank"
- rel="noreferrer noopener"
- className="inline-flex max-w-[560px] items-center gap-1 text-xs text-muted-foreground hover:text-foreground hover:underline"
- >
- <span className="truncate">{targetUrl}</span>
- <ExternalLink className="h-3 w-3 shrink-0" />
- </a>
- {data && <CategoryBadge category={data.category} />}
- {data?.articleType && (
- <Badge variant="outline" className="text-[10px] font-medium">
- {data.articleType}
+ <div className="shrink-0">
+ {data &&
+ (data.category === 'you' ? (
+ <Badge className="border border-primary/30 bg-primary/10 text-foreground">
+ Owned
</Badge>
- )}
- </div>
+ ) : (
+ <AddCompetitorButton
+ brandId={brand.id}
+ domain={data.domain}
+ onAdded={loadData}
+ appearance="button"
+ />
+ ))}
</div>
</div>
- <div className="shrink-0">
- {data &&
- (data.category === 'you' ? (
- <Badge className="border border-primary/30 bg-primary/10 text-foreground">
- Owned
- </Badge>
- ) : (
- <AddCompetitorButton
- brandId={brand.id}
- domain={data.domain}
- onAdded={loadData}
- appearance="button"
- />
- ))}
- </div>
</div>
- </div>
+ </HeaderWithAiUsage>
{/* Filters */}
<CitationsFilterBar
diff --git a/web/src/app/[locale]/(dashboard)/dashboard/insights/[id]/page.tsx b/web/src/app/[locale]/(dashboard)/dashboard/insights/[id]/page.tsx
index f18c06d8f..b0a0febff 100644
--- a/web/src/app/[locale]/(dashboard)/dashboard/insights/[id]/page.tsx
+++ b/web/src/app/[locale]/(dashboard)/dashboard/insights/[id]/page.tsx
@@ -23,6 +23,7 @@ import { cn } from '@/lib/utils';
import { PLATFORM_LABELS } from '@/config/platform-labels';
import { ResponseDetail } from '@/components/results/response-detail';
import { formatRegionDisplay } from '@/lib/region';
+import { HeaderWithAiUsage } from '@/components/ai-usage/ai-usage-meter';
function SentimentBadge({ sentiment }: { sentiment: 'positive' | 'neutral' | 'negative' }) {
const t = useTranslations('insights');
@@ -136,37 +137,41 @@ export default function ResultDetailPage() {
return (
<div className="space-y-6 p-2 sm:p-6 max-w-5xl mx-auto">
- {/* Back button */}
- <Button
- variant="ghost"
- size="sm"
- className="gap-2 -ml-2 text-muted-foreground hover:text-foreground"
- onClick={goBack}
- >
- <ArrowLeft className="h-4 w-4" />
- {common('back')}
- </Button>
+ <HeaderWithAiUsage>
+ <div className="space-y-6">
+ {/* Back button */}
+ <Button
+ variant="ghost"
+ size="sm"
+ className="gap-2 -ml-2 text-muted-foreground hover:text-foreground"
+ onClick={goBack}
+ >
+ <ArrowLeft className="h-4 w-4" />
+ {common('back')}
+ </Button>
- {/* Header */}
- <div className="space-y-3">
- <h1 className="text-xl font-semibold leading-snug">{result.promptText}</h1>
+ {/* Header */}
+ <div className="space-y-3">
+ <h1 className="text-xl font-semibold leading-snug">{result.promptText}</h1>
- <div className="flex flex-wrap items-center gap-2">
- <Badge variant="secondary" className="text-xs">
- {PLATFORM_LABELS[result.platform] ?? result.platform}
- </Badge>
- <SentimentBadge sentiment={result.sentiment} />
- <Badge variant="outline" className="text-xs gap-1">
- <Eye className="h-3 w-3" />
- {result.visibilityScore}/100
- </Badge>
- {result.region && (
- <Badge variant="outline" className="text-xs">
- {formatRegionDisplay(result.region)}
- </Badge>
- )}
+ <div className="flex flex-wrap items-center gap-2">
+ <Badge variant="secondary" className="text-xs">
+ {PLATFORM_LABELS[result.platform] ?? result.platform}
+ </Badge>
+ <SentimentBadge sentiment={result.sentiment} />
+ <Badge variant="outline" className="text-xs gap-1">
+ <Eye className="h-3 w-3" />
+ {result.visibilityScore}/100
+ </Badge>
+ {result.region && (
+ <Badge variant="outline" className="text-xs">
+ {formatRegionDisplay(result.region)}
+ </Badge>
+ )}
+ </div>
+ </div>
</div>
- </div>
+ </HeaderWithAiUsage>
{/* Stats */}
<div className="grid grid-cols-3 gap-4">
diff --git a/web/src/app/[locale]/(dashboard)/dashboard/prompts/[id]/page.tsx b/web/src/app/[locale]/(dashboard)/dashboard/prompts/[id]/page.tsx
index 01a499758..c9311ef8a 100644
--- a/web/src/app/[locale]/(dashboard)/dashboard/prompts/[id]/page.tsx
+++ b/web/src/app/[locale]/(dashboard)/dashboard/prompts/[id]/page.tsx
@@ -74,6 +74,7 @@ import { TablePager, usePagination } from '@/components/table-pager';
import { MODEL_PROVIDER_LABELS, PLATFORM_LABELS } from '@/config/platform-labels';
import { groupByPlatform, type PlatformGroup } from './grouping';
import { dayRangeBounds, viewerTimeZone } from '@/lib/time-zone';
+import { HeaderWithAiUsage } from '@/components/ai-usage/ai-usage-meter';
// ─── Date range (kept in sync with the insights page filter bar) ─────────────
@@ -868,47 +869,51 @@ export default function PromptDetailPage() {
return (
<div className="mx-auto max-w-5xl space-y-6 p-2 sm:p-6">
- <Button
- variant="ghost"
- size="sm"
- className="-ml-2 gap-2 text-muted-foreground hover:text-foreground"
- onClick={() => router.back()}
- >
- <ArrowLeft className="h-4 w-4" />
- Back
- </Button>
-
- <div className="space-y-3">
- <h1 className="text-xl font-semibold leading-snug">{data.prompt.text}</h1>
- <div className="flex flex-wrap items-center gap-2">
- {data.prompt.topicName && (
- <Badge variant="secondary" className="text-xs">
- {data.prompt.topicName}
- </Badge>
- )}
- <Badge
- variant="outline"
- className={cn(
- 'text-xs',
- data.prompt.isActive
- ? 'border-emerald-500/30 bg-emerald-500/10 text-emerald-600 dark:text-emerald-400'
- : 'border-muted-foreground/20 text-muted-foreground',
- )}
+ <HeaderWithAiUsage>
+ <div className="space-y-6">
+ <Button
+ variant="ghost"
+ size="sm"
+ className="-ml-2 gap-2 text-muted-foreground hover:text-foreground"
+ onClick={() => router.back()}
>
- {data.prompt.isActive ? 'Active' : 'Paused'}
- </Badge>
- {data.summary.lastCheckedAt && (
- <Badge variant="outline" className="gap-1 text-xs">
- <Clock className="h-3 w-3" />
- Last run: {formatTimestamp(data.summary.lastCheckedAt)}
- </Badge>
- )}
- <WorkStatusBadge
- status={workStatus}
- onChange={canManage ? handleStatusChange : undefined}
- />
+ <ArrowLeft className="h-4 w-4" />
+ Back
+ </Button>
+
+ <div className="space-y-3">
+ <h1 className="text-xl font-semibold leading-snug">{data.prompt.text}</h1>
+ <div className="flex flex-wrap items-center gap-2">
+ {data.prompt.topicName && (
+ <Badge variant="secondary" className="text-xs">
+ {data.prompt.topicName}
+ </Badge>
+ )}
+ <Badge
+ variant="outline"
+ className={cn(
+ 'text-xs',
+ data.prompt.isActive
+ ? 'border-emerald-500/30 bg-emerald-500/10 text-emerald-600 dark:text-emerald-400'
+ : 'border-muted-foreground/20 text-muted-foreground',
+ )}
+ >
+ {data.prompt.isActive ? 'Active' : 'Paused'}
+ </Badge>
+ {data.summary.lastCheckedAt && (
+ <Badge variant="outline" className="gap-1 text-xs">
+ <Clock className="h-3 w-3" />
+ Last run: {formatTimestamp(data.summary.lastCheckedAt)}
+ </Badge>
+ )}
+ <WorkStatusBadge
+ status={workStatus}
+ onChange={canManage ? handleStatusChange : undefined}
+ />
+ </div>
+ </div>
</div>
- </div>
+ </HeaderWithAiUsage>
<DateRangeBar
preset={datePreset}
diff --git a/web/src/app/[locale]/(dashboard)/dashboard/prompts/similar-topics/page.tsx b/web/src/app/[locale]/(dashboard)/dashboard/prompts/similar-topics/page.tsx
index eddccc621..09b13211a 100644
--- a/web/src/app/[locale]/(dashboard)/dashboard/prompts/similar-topics/page.tsx
+++ b/web/src/app/[locale]/(dashboard)/dashboard/prompts/similar-topics/page.tsx
@@ -28,6 +28,7 @@ import {
EstimateRange,
createEstimateNoteHandle,
} from '@/components/prompts/volume-estimate';
+import { HeaderWithAiUsage } from '@/components/ai-usage/ai-usage-meter';
export default function SimilarTopicsPage() {
const t = useTranslations('prompts.similarTopics');
@@ -87,25 +88,27 @@ export default function SimilarTopicsPage() {
return (
<div className="mx-auto max-w-6xl space-y-6 p-2 sm:p-6">
- <div className="space-y-2">
- <Link
- href="/dashboard/prompts?tab=insights"
- className={buttonVariants({
- variant: 'ghost',
- size: 'sm',
- className: 'gap-2 px-0',
- })}
- >
- <ArrowLeft className="h-4 w-4" />
- Back to Prompt Insights
- </Link>
- <div>
- <h1 className="text-2xl font-semibold tracking-tight">Similar Topics</h1>
- <p className="mt-1 text-sm text-muted-foreground">
- Keyword clusters aggregated across analyzed prompts.
- </p>
+ <HeaderWithAiUsage>
+ <div className="space-y-2">
+ <Link
+ href="/dashboard/prompts?tab=insights"
+ className={buttonVariants({
+ variant: 'ghost',
+ size: 'sm',
+ className: 'gap-2 px-0',
+ })}
+ >
+ <ArrowLeft className="h-4 w-4" />
+ Back to Prompt Insights
+ </Link>
+ <div>
+ <h1 className="text-2xl font-semibold tracking-tight">Similar Topics</h1>
+ <p className="mt-1 text-sm text-muted-foreground">
+ Keyword clusters aggregated across analyzed prompts.
+ </p>
+ </div>
</div>
- </div>
+ </HeaderWithAiUsage>
<div className="grid gap-4 sm:grid-cols-3">
<Card>
diff --git a/web/src/app/[locale]/(dashboard)/dashboard/prompts/topics/[id]/page.tsx b/web/src/app/[locale]/(dashboard)/dashboard/prompts/topics/[id]/page.tsx
index e0dc931fe..3c1d0c8f7 100644
--- a/web/src/app/[locale]/(dashboard)/dashboard/prompts/topics/[id]/page.tsx
+++ b/web/src/app/[locale]/(dashboard)/dashboard/prompts/topics/[id]/page.tsx
@@ -32,6 +32,7 @@ import {
import { ShareOfVoicePlatformChart } from '../../../insights/_charts';
import { cn } from '@/lib/utils';
import dynamic from 'next/dynamic';
+import { HeaderWithAiUsage } from '@/components/ai-usage/ai-usage-meter';
const DynamicVisibilityTrendChart = dynamic(
() => import('./topic_charts').then((m) => m.VisibilityTrendChartView),
{
@@ -249,26 +250,28 @@ export default function TopicDetailPage({ params }: { params: Promise<{ id: stri
return (
<div className="space-y-6">
{/* Header */}
- <div>
- <Button
- variant="ghost"
- size="sm"
- onClick={() => router.push('/dashboard/prompts/topics')}
- className="mb-2 -ml-2 text-muted-foreground"
- >
- <ArrowLeft className="h-4 w-4 mr-1" />
- Topics
- </Button>
- {loading && !topic ? (
- <Skeleton className="h-8 w-64" />
- ) : topic ? (
- <div>
- <h1 className="text-2xl font-bold tracking-tight">{topic.name}</h1>
- </div>
- ) : (
- <h1 className="text-2xl font-bold">Topic not found</h1>
- )}
- </div>
+ <HeaderWithAiUsage>
+ <div>
+ <Button
+ variant="ghost"
+ size="sm"
+ onClick={() => router.push('/dashboard/prompts/topics')}
+ className="mb-2 -ml-2 text-muted-foreground"
+ >
+ <ArrowLeft className="h-4 w-4 mr-1" />
+ Topics
+ </Button>
+ {loading && !topic ? (
+ <Skeleton className="h-8 w-64" />
+ ) : topic ? (
+ <div>
+ <h1 className="text-2xl font-bold tracking-tight">{topic.name}</h1>
+ </div>
+ ) : (
+ <h1 className="text-2xl font-bold">Topic not found</h1>
+ )}
+ </div>
+ </HeaderWithAiUsage>
{/* KPI strip */}
{loading ? (
diff --git a/web/src/components/ai-usage/ai-usage-meter.test.tsx b/web/src/components/ai-usage/ai-usage-meter.test.tsx
index 08eaf8c6a..a14266c93 100644
--- a/web/src/components/ai-usage/ai-usage-meter.test.tsx
+++ b/web/src/components/ai-usage/ai-usage-meter.test.tsx
@@ -358,6 +358,29 @@ describe('HeaderWithAiUsage', () => {
expect(row.className).toContain('sm:flex-row');
});
+ it('leaves room on the row for a drawer’s close button', async () => {
+ await render(
+ 'admin',
+ <HeaderWithAiUsage banner={false} className="pr-8">
+ <h1>Opportunity</h1>
+ </HeaderWithAiUsage>,
+ );
+ expect(container.firstElementChild!.className).toContain('pr-8');
+ expect(container.firstElementChild!.lastElementChild).toBe(trigger());
+ });
+
+ it('leaves the banner to the page with banner={false}', async () => {
+ vi.mocked(readAiUsage).mockResolvedValue(usage({ percentUsed: 84 }));
+ await render(
+ 'admin',
+ <HeaderWithAiUsage banner={false}>
+ <h1>Opportunity</h1>
+ </HeaderWithAiUsage>,
+ );
+ expect(container.children).toHaveLength(1);
+ expect(container.textContent).not.toContain('of this month');
+ });
+
it('follows the row with the banner from 80%', async () => {
vi.mocked(readAiUsage).mockResolvedValue(usage({ percentUsed: 84 }));
await render(
diff --git a/web/src/components/ai-usage/ai-usage-meter.tsx b/web/src/components/ai-usage/ai-usage-meter.tsx
index 098dd25f7..294d33a66 100644
--- a/web/src/components/ai-usage/ai-usage-meter.tsx
+++ b/web/src/components/ai-usage/ai-usage-meter.tsx
@@ -50,16 +50,26 @@ const LABEL_KEY = {
* the row's own buttons wrap beside it. On a phone it goes under the row, on
* the right, so the row keeps the whole width for its buttons. From 80% of
* the month's allowance the banner follows the row (spec §4), spaced as the
- * page spaces its parts.
+ * page spaces its parts; `banner={false}` leaves it to the page, for a row
+ * with more of its header under it.
*/
-export function HeaderWithAiUsage({ children }: { children: ReactNode }) {
+export function HeaderWithAiUsage({
+ children,
+ banner = true,
+ className,
+}: {
+ children: ReactNode;
+ banner?: boolean;
+ /** On the header row: room for a drawer's close button, for one. */
+ className?: string;
+}) {
return (
<>
- <div className="flex flex-col gap-2 sm:flex-row sm:items-start sm:gap-3">
+ <div className={cn('flex flex-col gap-2 sm:flex-row sm:items-start sm:gap-3', className)}>
<div className="min-w-0 sm:flex-1">{children}</div>
<AiUsageMeter className="self-end sm:self-auto" />
</div>
- <AiUsageBanner />
+ {banner && <AiUsageBanner />}
</>
);
}
diff --git a/web/src/components/content/opportunity-detail.tsx b/web/src/components/content/opportunity-detail.tsx
index bceda434c..4a05cd6e4 100644
--- a/web/src/components/content/opportunity-detail.tsx
+++ b/web/src/components/content/opportunity-detail.tsx
@@ -22,6 +22,8 @@ import {
Info,
} from 'lucide-react';
import { cn } from '@/lib/utils';
+import { HeaderWithAiUsage } from '@/components/ai-usage/ai-usage-meter';
+import { AiUsageBanner } from '@/components/ai-usage/ai-usage-banner';
import { Link, useRouter } from '@/i18n/navigation';
import {
getOpportunity,
@@ -478,35 +480,41 @@ export function OpportunityDetail({
// full width or the drawer's — rather than the viewport.
<div className="@container space-y-6">
<div className="space-y-3">
- <div className="flex items-start gap-3">
- {!inDrawer && (
- <Link href="/dashboard/content">
- <Button variant="ghost" size="icon" aria-label="Go back to content list">
- <ArrowLeft className="h-4 w-4" />
- </Button>
- </Link>
- )}
- <div className="min-w-0 flex-1">
- <h1 className="text-xl font-bold tracking-tight">{opportunity.title}</h1>
- {sd.alternativeOf && (
- <p className="mt-1 text-xs text-muted-foreground">
- <Badge variant="outline" className="mr-1.5 text-[10px] font-normal">
- {t('alternative.badge')}
- </Badge>
- {t('alternative.of')}{' '}
- <Link
- href={`/dashboard/content?opportunity=${sd.alternativeOf.id}`}
- className="text-primary hover:underline"
- >
- {sd.alternativeOf.title}
- </Link>
- </p>
- )}
- {opportunity.description && (
- <p className="text-sm text-muted-foreground mt-1">{opportunity.description}</p>
+ {/* The month's AI usage at the row's right, as on every page, also in
+ the drawer, which covers the Content page's header; there it
+ leaves room for the drawer's close button (top-3 right-3, 28 px).
+ The banner follows the whole header block. */}
+ <HeaderWithAiUsage banner={false} className={inDrawer ? 'pr-8' : undefined}>
+ <div className="flex items-start gap-3">
+ {!inDrawer && (
+ <Link href="/dashboard/content">
+ <Button variant="ghost" size="icon" aria-label="Go back to content list">
+ <ArrowLeft className="h-4 w-4" />
+ </Button>
+ </Link>
)}
+ <div className="min-w-0 flex-1">
+ <h1 className="text-xl font-bold tracking-tight">{opportunity.title}</h1>
+ {sd.alternativeOf && (
+ <p className="mt-1 text-xs text-muted-foreground">
+ <Badge variant="outline" className="mr-1.5 text-[10px] font-normal">
+ {t('alternative.badge')}
+ </Badge>
+ {t('alternative.of')}{' '}
+ <Link
+ href={`/dashboard/content?opportunity=${sd.alternativeOf.id}`}
+ className="text-primary hover:underline"
+ >
+ {sd.alternativeOf.title}
+ </Link>
+ </p>
+ )}
+ {opportunity.description && (
+ <p className="text-sm text-muted-foreground mt-1">{opportunity.description}</p>
+ )}
+ </div>
</div>
- </div>
+ </HeaderWithAiUsage>
<div className="flex flex-wrap items-center gap-2">
<Badge
@@ -601,6 +609,7 @@ export function OpportunityDetail({
onDismiss={opportunity.status === 'new' ? () => setDismissOpen(true) : undefined}
/>
</div>
+ <AiUsageBanner />
{sd.reopened && ['new', 'reviewed'].includes(opportunity.status) && (
<div className="rounded-md border border-amber-500/30 bg-amber-500/10 px-4 py-3 text-sm">