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.
TypeScript aeoai-agentai-searchanswer-engine-optimizationbrand-monitoringchatgptclaudecopilotdockergeminigeogoogle-ai-overviewsgrokmcpnextjsopen-sourceperplexityseosupabasetypescript
feat(prompts): show a prompt's content opportunities on its detail page (#994)
Nandinikumari026337f90416ac
diff --git a/web/src/app/[locale]/(dashboard)/dashboard/prompts/[id]/_workflow-cards.tsx b/web/src/app/[locale]/(dashboard)/dashboard/prompts/[id]/_workflow-cards.tsxindex c2066cfad..67155cb17 100644--- a/web/src/app/[locale]/(dashboard)/dashboard/prompts/[id]/_workflow-cards.tsx+++ b/web/src/app/[locale]/(dashboard)/dashboard/prompts/[id]/_workflow-cards.tsx@@ -1,12 +1,17 @@'use client';/**- * Prompt workflow section on the prompt detail page: a notes thread and the- * target URLs list. The work-status picker lives in the page header (next to- * the Active badge); these two cards carry the collaboration surface.+ * Prompt workflow section on the prompt detail page: a notes thread, the+ * target URLs list, and content opportunities. The work-status picker lives in+ * the page header (next to the Active badge); these three cards carry the+ * collaboration surface.*/+import { useTranslations } from 'next-intl';+import { Link } from '@/i18n/navigation';+import type { ContentOpportunity } from '@/types';import { useCallback, useState } from 'react';+import { IMPACT_COLORS } from '@/components/content/opportunity-detail';import { Badge } from '@/components/ui/badge';import { Button } from '@/components/ui/button';import { Card, CardContent, CardHeader, CardTitle } from '@/components/ui/card';@@ -14,6 +19,8 @@ import { Input } from '@/components/ui/input';import { Textarea } from '@/components/ui/textarea';import {CheckCircle2,+ FileText,+ Lightbulb,ExternalLink,Link2,Loader2,@@ -345,3 +352,105 @@ export function TargetUrlsCard({</Card>);}++export const OPPORTUNITY_PREVIEW_LIMIT = 5;++export function ContentOpportunitiesCard({+ promptId,+ opportunities,+ total,+ loading,+ failed,+}: {+ promptId: string;+ opportunities: ContentOpportunity[];+ total: number;+ loading: boolean;+ failed?: boolean;+}) {+ const t = useTranslations('content');++ return (+ <Card>+ <CardHeader className="pb-3">+ <CardTitle className="flex items-center gap-2 text-sm font-medium">+ <Lightbulb className="h-4 w-4" />+ Content opportunities+ {total > 0 && (+ <Badge variant="secondary" className="text-xs tabular-nums">+ {total}+ </Badge>+ )}+ </CardTitle>+ <p className="text-xs text-muted-foreground">+ Opportunities identified for this prompt that are waiting for action.+ </p>+ </CardHeader>+ <CardContent>+ {loading ? (+ <div className="flex justify-center py-4">+ <Loader2 className="h-4 w-4 animate-spin text-muted-foreground" />+ </div>+ ) : failed ? (+ <p className="py-4 text-center text-xs text-muted-foreground">+ Content opportunities couldn't be loaded.+ </p>+ ) : opportunities.length === 0 ? (+ <p className="py-4 text-center text-xs text-muted-foreground">+ No open opportunities for this prompt.+ </p>+ ) : (+ <div className="space-y-3">+ <ul className="space-y-1.5">+ {opportunities.map((opp) => (+ <li+ key={opp.id}+ className="flex flex-col gap-1.5 rounded-lg border bg-muted/20 px-3 py-2"+ >+ <Link+ href={`/dashboard/content/${opp.id}`}+ title={opp.title}+ className="block truncate text-sm font-medium hover:underline"+ >+ {opp.title}+ </Link>+ <div className="flex items-center gap-2">+ <Badge variant="outline" className={cn('text-xs', IMPACT_COLORS[opp.impact])}>+ {t(`impact.${opp.impact}` as 'impact.high' | 'impact.medium' | 'impact.low')}+ </Badge>+ <Badge+ variant="outline"+ className="text-xs"+ title={t(`typeHint.${opp.type}` as 'typeHint.owned' | 'typeHint.earned')}+ >+ {t(`type.${opp.type}` as 'type.owned' | 'type.earned')}+ </Badge>+ {opp.brief && (+ <Badge+ variant="secondary"+ className="text-[10px] gap-1 bg-blue-500/10 text-blue-600 dark:text-blue-400 hover:bg-blue-500/20"+ >+ <FileText className="h-3 w-3" />+ Brief ready+ </Badge>+ )}+ </div>+ </li>+ ))}+ </ul>+ {total > OPPORTUNITY_PREVIEW_LIMIT && (+ <div className="flex justify-center pt-2">+ <Link+ href={`/dashboard/content?prompt=${encodeURIComponent(promptId)}&status=new`}+ className="text-xs text-muted-foreground hover:text-foreground hover:underline"+ >+ View all {total}+ </Link>+ </div>+ )}+ </div>+ )}+ </CardContent>+ </Card>+ );+}diff --git a/web/src/app/[locale]/(dashboard)/dashboard/prompts/[id]/page.tsx b/web/src/app/[locale]/(dashboard)/dashboard/prompts/[id]/page.tsxindex 9ccdbaa3b..f9ff6b8b9 100644--- a/web/src/app/[locale]/(dashboard)/dashboard/prompts/[id]/page.tsx+++ b/web/src/app/[locale]/(dashboard)/dashboard/prompts/[id]/page.tsx@@ -41,6 +41,8 @@ import { cn } from '@/lib/utils';import { formatRegionDisplay } from '@/lib/region';import { toast } from 'sonner';import { useUserRole } from '@/hooks/use-user-role';+import { getOpportunities } from '@/lib/actions/content';+import type { ContentOpportunity } from '@/types';import { AIProviderAvatar, resolveAIProvider } from '@/components/ai-provider-avatar';import { WorkStatusBadge } from '@/components/prompts/work-status';import {@@ -50,7 +52,12 @@ import {type PromptTargetUrl,type PromptWorkStatus,} from '@/lib/actions/prompt-workflow';-import { NotesCard, TargetUrlsCard } from './_workflow-cards';+import {+ NotesCard,+ TargetUrlsCard,+ ContentOpportunitiesCard,+ OPPORTUNITY_PREVIEW_LIMIT,+} from './_workflow-cards';import { ResponseDetail } from '@/components/results/response-detail';import {CategoryBadge,@@ -632,8 +639,13 @@ export default function PromptDetailPage() {const promptId = params.id as string;const { canManage } = useUserRole();-const [data, setData] = useState<PromptDetailData | null>(null);+ const promptBrandId = data?.prompt.brandId;+ const [opportunities, setOpportunities] = useState<ContentOpportunity[]>([]);+ const [opportunitiesTotal, setOpportunitiesTotal] = useState(0);+ const [opportunitiesLoading, setOpportunitiesLoading] = useState(true);+ const [opportunitiesFailed, setOpportunitiesFailed] = useState(false);+const [loading, setLoading] = useState(true);const [notFound, setNotFound] = useState(false);const [expanded, setExpanded] = useState<Set<string>>(new Set());@@ -662,6 +674,42 @@ export default function PromptDetailPage() {};}, [promptId]);+ useEffect(() => {+ let cancelled = false;+ if (!promptBrandId) return;++ setOpportunities([]);+ setOpportunitiesTotal(0);+ setOpportunitiesFailed(false);+ setOpportunitiesLoading(true);++ getOpportunities(promptBrandId, {+ promptId,+ status: 'new',+ limit: OPPORTUNITY_PREVIEW_LIMIT,+ })+ .then((res) => {+ if (cancelled) return;+ setOpportunities(res.opportunities);+ setOpportunitiesTotal(res.total);+ })+ .catch((err) => {+ console.error('Failed to load opportunities:', err);+ if (cancelled) return;+ setOpportunities([]);+ setOpportunitiesTotal(0);+ setOpportunitiesFailed(true);+ toast.error('Failed to load content opportunities');+ })+ .finally(() => {+ if (!cancelled) setOpportunitiesLoading(false);+ });++ return () => {+ cancelled = true;+ };+ }, [promptBrandId, promptId]);+const handleStatusChange = (status: PromptWorkStatus | null) => {const previous = workStatus;setWorkStatus(status);@@ -922,18 +970,27 @@ export default function PromptDetailPage() {{/* Workflow — outside the refetch overlay: notes and target URLs aredate-window independent. */}- <div className="grid gap-4 lg:grid-cols-2">- <NotesCard- promptId={promptId}- notes={notes}- onNotesChange={setNotes}- canManage={canManage}- />- <TargetUrlsCard+ <div className="space-y-4">+ <div className="grid gap-4 lg:grid-cols-2">+ <NotesCard+ promptId={promptId}+ notes={notes}+ onNotesChange={setNotes}+ canManage={canManage}+ />+ <TargetUrlsCard+ promptId={promptId}+ urls={targetUrls}+ onUrlsChange={setTargetUrls}+ canManage={canManage}+ />+ </div>+ <ContentOpportunitiesCardpromptId={promptId}- urls={targetUrls}- onUrlsChange={setTargetUrls}- canManage={canManage}+ opportunities={opportunities}+ total={opportunitiesTotal}+ loading={opportunitiesLoading}+ failed={opportunitiesFailed}/></div></div>diff --git a/web/src/components/content/opportunity-detail.tsx b/web/src/components/content/opportunity-detail.tsxindex 9bcf4edf2..fc4e31eae 100644--- a/web/src/components/content/opportunity-detail.tsx+++ b/web/src/components/content/opportunity-detail.tsx@@ -57,7 +57,7 @@ import {import { opportunityToMarkdown } from '@/lib/content/opportunity-markdown';import { toast } from 'sonner';-const IMPACT_COLORS: Record<string, string> = {+export const IMPACT_COLORS: Record<string, string> = {high: 'border-red-500/30 bg-red-500/10 text-red-600 dark:text-red-400',medium: 'border-amber-500/30 bg-amber-500/10 text-amber-600 dark:text-amber-400',low: 'border-slate-500/30 bg-slate-500/10 text-slate-600 dark:text-slate-400',