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(action-center): start and skip Getting started, and ask before running it for another brand (#1243)
Cihan2041298d2a4c
diff --git a/supabase/migrations/00197_getting_started_start_skip.sql b/supabase/migrations/00197_getting_started_start_skip.sqlnew file mode 100644index 000000000..5dd9a6cf9--- /dev/null+++ b/supabase/migrations/00197_getting_started_start_skip.sql@@ -0,0 +1,187 @@+-- ============================================================================+-- 00197: start and skip Getting started (New Ansvisor, AC-ALT2 §5)+-- ============================================================================+-- 00196 starts Getting started for every new brand. This lets a person start+-- and skip it from the Actions page, and asks first for a brand added to an+-- organization that already has one:+--+-- * getting_started.confirmed_at: when someone chose to run it. The first+-- brand of an organization (onboarding) runs it at once; a later brand+-- asks "Run Getting started for [brand]?" until someone answers, so its+-- row starts with confirmed_at null. dismissed_at stays "skipped", and+-- starting again clears it.+-- * admins and managers start and skip it (insert and update policies, as+-- for kpi_definitions); members keep reading it.+-- * getting_started_facts also returns confirmed_at and content_recent,+-- the content of the last 30 days, for the existing-customer rule: fewer+-- than 3 competitors or topics, no Search Console, or no content in 30+-- days offers "Start getting started".++alter table public.getting_started+ add column if not exists confirmed_at timestamptz;++comment on column public.getting_started.confirmed_at is+ 'When someone chose to run Getting started for the brand; null while a later brand of the organization still asks.';++-- Rows from before this migration ran it at once.+update public.getting_started+ set confirmed_at = started_at+ where confirmed_at is null;++create or replace function public.start_brand_getting_started()+returns trigger+language plpgsql+security definer+set search_path to 'public'+as $$+begin+ insert into public.getting_started (brand_id, confirmed_at)+ values (+ new.id,+ -- The organization's first brand runs it; a later one asks first.+ case+ when exists (+ select 1 from public.brands b+ where b.organization_id = new.organization_id and b.id <> new.id+ ) then null+ else now()+ end+ )+ on conflict (brand_id) do nothing;+ return new;+end;+$$;++revoke all on function public.start_brand_getting_started() from public, anon, authenticated;++create policy "getting_started: admin/manager insert"+ on public.getting_started+ for insert+ with check (+ brand_id in (+ select b.id+ from public.brands b+ join public.profiles p on p.organization_id = b.organization_id+ where p.id = auth.uid()+ and p.role = any (array['admin'::public.user_role, 'manager'::public.user_role])+ )+ );++create policy "getting_started: admin/manager update"+ on public.getting_started+ for update+ using (+ brand_id in (+ select b.id+ from public.brands b+ join public.profiles p on p.organization_id = b.organization_id+ where p.id = auth.uid()+ and p.role = any (array['admin'::public.user_role, 'manager'::public.user_role])+ )+ );++create or replace function public.getting_started_facts(p_brand_id uuid)+returns jsonb+language sql+stable+security invoker+set search_path to 'public'+as $$+ select jsonb_build_object(+ 'started_at', gs.started_at,+ 'dismissed_at', gs.dismissed_at,+ 'confirmed_at', gs.confirmed_at,+ 'steps', coalesce((+ select jsonb_object_agg(s.step, jsonb_build_object('state', s.state, 'at', s.updated_at))+ from public.getting_started_steps s+ where s.brand_id = p_brand_id+ ), '{}'::jsonb),+ 'kpi_setup_at', b.kpi_setup_at,+ 'competitors', (+ select count(*) from public.competitors c where c.brand_id = p_brand_id+ ),+ -- Active prompts in each active topic, oldest topic first.+ 'topic_prompts', coalesce((+ select jsonb_agg(n.prompts order by t.created_at, t.id)+ from public.topics t+ cross join lateral (+ select count(*) as prompts+ from public.prompts p+ join public.prompt_sets ps on ps.id = p.prompt_set_id+ where p.topic_id = t.id+ and p.is_active+ and ps.brand_id = p_brand_id+ ) n+ where t.brand_id = p_brand_id+ and t.is_active+ ), '[]'::jsonb),+ -- Connected for the organization and mapped to a property for the brand,+ -- as Settings › Integrations shows it.+ 'gsc', nullif(b.gsc_property, '') is not null and exists (+ select 1 from public.integration_connections ic+ where ic.organization_id = b.organization_id+ and ic.provider = 'google-search-console'+ and ic.status = 'connected'+ ),+ 'ga', nullif(b.ga_property_id, '') is not null and exists (+ select 1 from public.integration_connections ic+ where ic.organization_id = b.organization_id+ and ic.provider = 'google-analytics'+ and ic.status = 'connected'+ ),+ 'first_answer', exists (+ select 1 from public.prompt_results r where r.brand_id = p_brand_id+ ),+ 'first_visit', exists (+ select 1 from public.ai_traffic_logs l where l.brand_id = p_brand_id+ ),+ -- Prompt suggestions built from Search Console and Analytics data.+ 'data_suggestions', (+ select count(*) from public.prompt_suggestions s+ where s.brand_id = p_brand_id and s.source in ('gsc', 'ga')+ ),+ 'data_tracked', (+ select count(*) from public.prompt_suggestions s+ where s.brand_id = p_brand_id and s.source in ('gsc', 'ga') and s.status = 'added'+ ),+ 'content_suggestions', (+ select count(*) from public.content_opportunities o where o.brand_id = p_brand_id+ ),+ -- Picked: reviewed, sent to the Action Center or given a brief (00106).+ 'content_picked', (+ select count(*) from public.content_opportunities o+ where o.brand_id = p_brand_id+ and (o.status in ('reviewed', 'sent', 'in_progress', 'done') or o.brief is not null)+ ),+ -- Created: its work was completed, or it went to the CMS webhook. There+ -- is no published state until the Content Editor.+ 'content_created', (+ select count(*) from public.content_opportunities o+ where o.brand_id = p_brand_id+ and (o.status = 'done' or o.webhook_sent_at is not null)+ ),+ -- Content in the last 30 days, the same way: for the existing-customer+ -- rule (no content in 30 days → offer Getting started).+ 'content_recent', (+ select count(*) from public.content_opportunities o+ where o.brand_id = p_brand_id+ and (+ o.webhook_sent_at >= now() - interval '30 days'+ or (o.status = 'done' and o.updated_at >= now() - interval '30 days')+ )+ ),+ -- Audits a person ran (not the automatic sweep, 00167) that finished.+ 'audits', (+ select count(*) from public.site_audits a+ where a.brand_id = p_brand_id and a.source = 'user' and a.status = 'completed'+ )+ )+ from public.brands b+ left join public.getting_started gs on gs.brand_id = b.id+ where b.id = p_brand_id;+$$;++revoke all on function public.getting_started_facts(uuid) from public, anon;+grant execute on function public.getting_started_facts(uuid) to authenticated;++notify pgrst, 'reload schema';diff --git a/supabase/schema.sql b/supabase/schema.sqlindex a81cb6bf3..26e63c28f 100644--- a/supabase/schema.sql+++ b/supabase/schema.sql@@ -27125,6 +27125,197 @@ comment on function public.getting_started_facts(uuid) isnotify pgrst, 'reload schema';+-- ─────────────────────────────────────────────────────────────────────────+-- migrations/00197_getting_started_start_skip.sql+-- ─────────────────────────────────────────────────────────────────────────+-- ============================================================================+-- 00197: start and skip Getting started (New Ansvisor, AC-ALT2 §5)+-- ============================================================================+-- 00196 starts Getting started for every new brand. This lets a person start+-- and skip it from the Actions page, and asks first for a brand added to an+-- organization that already has one:+--+-- * getting_started.confirmed_at: when someone chose to run it. The first+-- brand of an organization (onboarding) runs it at once; a later brand+-- asks "Run Getting started for [brand]?" until someone answers, so its+-- row starts with confirmed_at null. dismissed_at stays "skipped", and+-- starting again clears it.+-- * admins and managers start and skip it (insert and update policies, as+-- for kpi_definitions); members keep reading it.+-- * getting_started_facts also returns confirmed_at and content_recent,+-- the content of the last 30 days, for the existing-customer rule: fewer+-- than 3 competitors or topics, no Search Console, or no content in 30+-- days offers "Start getting started".++alter table public.getting_started+ add column if not exists confirmed_at timestamptz;++comment on column public.getting_started.confirmed_at is+ 'When someone chose to run Getting started for the brand; null while a later brand of the organization still asks.';++-- Rows from before this migration ran it at once.+update public.getting_started+ set confirmed_at = started_at+ where confirmed_at is null;++create or replace function public.start_brand_getting_started()+returns trigger+language plpgsql+security definer+set search_path to 'public'+as $$+begin+ insert into public.getting_started (brand_id, confirmed_at)+ values (+ new.id,+ -- The organization's first brand runs it; a later one asks first.+ case+ when exists (+ select 1 from public.brands b+ where b.organization_id = new.organization_id and b.id <> new.id+ ) then null+ else now()+ end+ )+ on conflict (brand_id) do nothing;+ return new;+end;+$$;++revoke all on function public.start_brand_getting_started() from public, anon, authenticated;++create policy "getting_started: admin/manager insert"+ on public.getting_started+ for insert+ with check (+ brand_id in (+ select b.id+ from public.brands b+ join public.profiles p on p.organization_id = b.organization_id+ where p.id = auth.uid()+ and p.role = any (array['admin'::public.user_role, 'manager'::public.user_role])+ )+ );++create policy "getting_started: admin/manager update"+ on public.getting_started+ for update+ using (+ brand_id in (+ select b.id+ from public.brands b+ join public.profiles p on p.organization_id = b.organization_id+ where p.id = auth.uid()+ and p.role = any (array['admin'::public.user_role, 'manager'::public.user_role])+ )+ );++create or replace function public.getting_started_facts(p_brand_id uuid)+returns jsonb+language sql+stable+security invoker+set search_path to 'public'+as $$+ select jsonb_build_object(+ 'started_at', gs.started_at,+ 'dismissed_at', gs.dismissed_at,+ 'confirmed_at', gs.confirmed_at,+ 'steps', coalesce((+ select jsonb_object_agg(s.step, jsonb_build_object('state', s.state, 'at', s.updated_at))+ from public.getting_started_steps s+ where s.brand_id = p_brand_id+ ), '{}'::jsonb),+ 'kpi_setup_at', b.kpi_setup_at,+ 'competitors', (+ select count(*) from public.competitors c where c.brand_id = p_brand_id+ ),+ -- Active prompts in each active topic, oldest topic first.+ 'topic_prompts', coalesce((+ select jsonb_agg(n.prompts order by t.created_at, t.id)+ from public.topics t+ cross join lateral (+ select count(*) as prompts+ from public.prompts p+ join public.prompt_sets ps on ps.id = p.prompt_set_id+ where p.topic_id = t.id+ and p.is_active+ and ps.brand_id = p_brand_id+ ) n+ where t.brand_id = p_brand_id+ and t.is_active+ ), '[]'::jsonb),+ -- Connected for the organization and mapped to a property for the brand,+ -- as Settings › Integrations shows it.+ 'gsc', nullif(b.gsc_property, '') is not null and exists (+ select 1 from public.integration_connections ic+ where ic.organization_id = b.organization_id+ and ic.provider = 'google-search-console'+ and ic.status = 'connected'+ ),+ 'ga', nullif(b.ga_property_id, '') is not null and exists (+ select 1 from public.integration_connections ic+ where ic.organization_id = b.organization_id+ and ic.provider = 'google-analytics'+ and ic.status = 'connected'+ ),+ 'first_answer', exists (+ select 1 from public.prompt_results r where r.brand_id = p_brand_id+ ),+ 'first_visit', exists (+ select 1 from public.ai_traffic_logs l where l.brand_id = p_brand_id+ ),+ -- Prompt suggestions built from Search Console and Analytics data.+ 'data_suggestions', (+ select count(*) from public.prompt_suggestions s+ where s.brand_id = p_brand_id and s.source in ('gsc', 'ga')+ ),+ 'data_tracked', (+ select count(*) from public.prompt_suggestions s+ where s.brand_id = p_brand_id and s.source in ('gsc', 'ga') and s.status = 'added'+ ),+ 'content_suggestions', (+ select count(*) from public.content_opportunities o where o.brand_id = p_brand_id+ ),+ -- Picked: reviewed, sent to the Action Center or given a brief (00106).+ 'content_picked', (+ select count(*) from public.content_opportunities o+ where o.brand_id = p_brand_id+ and (o.status in ('reviewed', 'sent', 'in_progress', 'done') or o.brief is not null)+ ),+ -- Created: its work was completed, or it went to the CMS webhook. There+ -- is no published state until the Content Editor.+ 'content_created', (+ select count(*) from public.content_opportunities o+ where o.brand_id = p_brand_id+ and (o.status = 'done' or o.webhook_sent_at is not null)+ ),+ -- Content in the last 30 days, the same way: for the existing-customer+ -- rule (no content in 30 days → offer Getting started).+ 'content_recent', (+ select count(*) from public.content_opportunities o+ where o.brand_id = p_brand_id+ and (+ o.webhook_sent_at >= now() - interval '30 days'+ or (o.status = 'done' and o.updated_at >= now() - interval '30 days')+ )+ ),+ -- Audits a person ran (not the automatic sweep, 00167) that finished.+ 'audits', (+ select count(*) from public.site_audits a+ where a.brand_id = p_brand_id and a.source = 'user' and a.status = 'completed'+ )+ )+ from public.brands b+ left join public.getting_started gs on gs.brand_id = b.id+ where b.id = p_brand_id;+$$;++revoke all on function public.getting_started_facts(uuid) from public, anon;+grant execute on function public.getting_started_facts(uuid) to authenticated;++notify pgrst, 'reload schema';+-- ─────────────────────────────────────────────────────────────────────────-- migrations/00198_webhook_event_subscriptions.sql-- ─────────────────────────────────────────────────────────────────────────diff --git a/web/messages/en.json b/web/messages/en.jsonindex 35ac8e091..252241f4a 100644--- a/web/messages/en.json+++ b/web/messages/en.json@@ -1635,6 +1635,32 @@"connect": "Connect now","skipped": "Skipped · you can connect it later","failed": "Couldn’t skip the step. Try again."+ },+ "start": {+ "button": "Start getting started",+ "hint": "For admins and managers · about 15 min",+ "started": "{count, plural, =0 {Getting started is on} one {Getting started · # step already done} other {Getting started · # steps already done}}",+ "failed": "Couldn’t start Getting started. Try again."+ },+ "skip": {+ "button": "Skip getting started",+ "title": "Skip getting started?",+ "body": "Your actions list goes back to normal. Steps you finished stay done.",+ "later": "You can start again any time from the same button.",+ "confirm": "Skip",+ "keep": "Keep going",+ "done": "Back to your actions",+ "failed": "Couldn’t skip Getting started. Try again."+ },+ "secondBrand": {+ "title": "Run Getting started for {brand}?",+ "body": "You already know Ansvisor. Run the setup steps for this brand, or skip them.",+ "runLine": "Run: KPIs, competitors, topics and prompts for {brand}, guided",+ "skipLine": "Skip: go straight to the actions list",+ "run": "Run Getting started",+ "skip": "Skip",+ "ran": "Getting started is on for {brand}",+ "skipped": "Skipped · {brand} goes straight to the actions"}},"actionTexts": {diff --git a/web/src/app/[locale]/(dashboard)/dashboard/action-center/actions/page.test.tsx b/web/src/app/[locale]/(dashboard)/dashboard/action-center/actions/page.test.tsxindex 6fd70259c..e3fd6ea5b 100644--- a/web/src/app/[locale]/(dashboard)/dashboard/action-center/actions/page.test.tsx+++ b/web/src/app/[locale]/(dashboard)/dashboard/action-center/actions/page.test.tsx@@ -58,10 +58,22 @@ const action: ActionItem = {priorityReason: null,};-const { getActions, getActionsAffected, getGettingStarted, saveBlob, toast } = vi.hoisted(() => ({+const {+ getActions,+ getActionsAffected,+ getGettingStarted,+ startGettingStarted,+ skipGettingStarted,+ role,+ saveBlob,+ toast,+} = vi.hoisted(() => ({getActions: vi.fn(),getActionsAffected: vi.fn(),getGettingStarted: vi.fn(),+ startGettingStarted: vi.fn(),+ skipGettingStarted: vi.fn(),+ role: { canManage: true },saveBlob: vi.fn(),toast: Object.assign(vi.fn(), { error: vi.fn(), success: vi.fn() }),}));@@ -74,7 +86,12 @@ vi.mock('@/stores/use-brand-store', () => ({selector({ getActiveBrand: () => brand }),}));vi.mock('@/lib/actions/action-center', () => ({ getActions, getActionsAffected }));-vi.mock('@/lib/actions/getting-started', () => ({ getGettingStarted }));+vi.mock('@/lib/actions/getting-started', () => ({+ getGettingStarted,+ startGettingStarted,+ skipGettingStarted,+}));+vi.mock('@/hooks/use-user-role', () => ({ useUserRole: () => role }));vi.mock('@/lib/actions/team', () => ({ listMembers: vi.fn(async () => []) }));vi.mock('@/lib/download', () => ({ saveBlob }));vi.mock('sonner', () => ({ toast }));@@ -124,6 +141,9 @@ beforeEach(() => {window.history.replaceState(null, '', '/');getActions.mockReset().mockResolvedValue([action]);getGettingStarted.mockReset().mockResolvedValue(null);+ startGettingStarted.mockReset().mockResolvedValue(undefined);+ skipGettingStarted.mockReset().mockResolvedValue(undefined);+ role.canManage = true;container = document.createElement('div');document.body.append(container);root = createRoot(container);@@ -189,6 +209,7 @@ const started = (over: Partial<GettingStartedFacts> = {}): GettingStartedStatusbuildGettingStarted({startedAt: '2026-10-20T10:00:00Z',dismissedAt: null,+ confirmedAt: '2026-10-20T10:00:00Z',records: {},recordedAt: {},kpiSetupAt: null,@@ -203,6 +224,7 @@ const started = (over: Partial<GettingStartedFacts> = {}): GettingStartedStatuscontentSuggestions: 0,contentPicked: 0,contentCreated: 0,+ contentRecent: 0,audits: 0,...over,});@@ -284,3 +306,82 @@ describe('Getting started in the actions list', () => {expect(text()).toContain('cards.priority');});});++// Dialogs open in a portal on the body.+const pageText = () => document.body.textContent ?? '';+const buttonNamed = (label: string) =>+ [...document.querySelectorAll('button')].find((b) => b.textContent?.trim() === label);++// AC-ALT2 §5: existing customers, skipping, and a brand added beside others.+describe('starting and skipping Getting started', () => {+ it('offers Start to a manager whose brand isn’t set up, and runs it', async () => {+ getGettingStarted+ .mockResolvedValueOnce(started({ startedAt: null }))+ .mockResolvedValue(started({ competitors: 4 }));+ await render();+ expect(text()).toContain('start.hint');+ await act(async () => buttonNamed('start.button')!.click());++ expect(startGettingStarted).toHaveBeenCalledWith('brand-id');+ expect(toast.success).toHaveBeenCalledWith('start.started');+ expect(steps()).not.toBeNull();+ });++ it('offers nothing to a brand that is set up, nor to someone who can’t set it up', async () => {+ const setUp = { startedAt: null, competitors: 3, topicPrompts: [3, 3, 3], gsc: true };+ getGettingStarted.mockResolvedValue(started({ ...setUp, contentRecent: 1 }));+ await render();+ expect(buttonNamed('start.button')).toBeUndefined();++ act(() => root.unmount());+ root = createRoot(container);+ role.canManage = false;+ getGettingStarted.mockResolvedValue(started({ startedAt: null }));+ await render();+ expect(buttonNamed('start.button')).toBeUndefined();+ });++ it('skips it only after asking, then lists the actions', async () => {+ getGettingStarted+ .mockResolvedValueOnce(started())+ .mockResolvedValue(started({ dismissedAt: '2026-10-20T12:00:00Z' }));+ await render();+ await act(async () => buttonNamed('skip.button')!.click());+ expect(skipGettingStarted).not.toHaveBeenCalled();+ expect(pageText()).toContain('skip.body');++ await act(async () => buttonNamed('skip.confirm')!.click());+ expect(skipGettingStarted).toHaveBeenCalledWith('brand-id');+ expect(toast.success).toHaveBeenCalledWith('skip.done');+ expect(steps()).toBeNull();+ // Start stays available after a skip.+ expect(buttonNamed('start.button')).toBeDefined();+ });++ it("closes the new brand's question when the answer can't be saved, and keeps it closed", async () => {+ getGettingStarted.mockResolvedValue(started({ confirmedAt: null }));+ startGettingStarted.mockRejectedValue(new Error('missing column confirmed_at'));+ await render();+ expect(pageText()).toContain('secondBrand.title');++ await act(async () => buttonNamed('secondBrand.run')!.click());+ expect(toast.error).toHaveBeenCalledWith('start.failed');+ expect(pageText()).not.toContain('secondBrand.title');+ // Start takes the question's place, to run it later.+ expect(buttonNamed('start.button')).toBeDefined();+ });++ it('asks a manager whether to run it for a brand added beside others', async () => {+ getGettingStarted+ .mockResolvedValueOnce(started({ confirmedAt: null }))+ .mockResolvedValue(started());+ await render();+ expect(pageText()).toContain('secondBrand.title');+ expect(steps()).toBeNull();++ await act(async () => buttonNamed('secondBrand.run')!.click());+ expect(startGettingStarted).toHaveBeenCalledWith('brand-id');+ expect(toast.success).toHaveBeenCalledWith('secondBrand.ran');+ expect(steps()).not.toBeNull();+ });+});diff --git a/web/src/app/[locale]/(dashboard)/dashboard/action-center/actions/page.tsx b/web/src/app/[locale]/(dashboard)/dashboard/action-center/actions/page.tsxindex 4e6c1c767..661348e00 100644--- a/web/src/app/[locale]/(dashboard)/dashboard/action-center/actions/page.tsx+++ b/web/src/app/[locale]/(dashboard)/dashboard/action-center/actions/page.tsx@@ -27,7 +27,11 @@ import {type ActionItem,} from '@/lib/actions/action-center';import { listMembers, type TeamMember } from '@/lib/actions/team';-import { getGettingStarted } from '@/lib/actions/getting-started';+import {+ getGettingStarted,+ skipGettingStarted,+ startGettingStarted,+} from '@/lib/actions/getting-started';import type { GettingStartedStatus, GettingStartedStep } from '@/lib/getting-started/steps';import { readUrlChoice, readUrlParam, writeUrlParams } from '@/lib/url-state';import {@@ -63,6 +67,14 @@ import { GettingStartedSummaryCard } from '@/components/getting-started/summary-import { GettingStartedStepCard } from '@/components/getting-started/step-card';import { Button } from '@/components/ui/button';import { Card, CardContent } from '@/components/ui/card';+import {+ Dialog,+ DialogContent,+ DialogDescription,+ DialogFooter,+ DialogHeader,+ DialogTitle,+} from '@/components/ui/dialog';import { Input } from '@/components/ui/input';import {Select,@@ -113,23 +125,36 @@ export default function ActionCenterActionsPage() {return (<div className="space-y-6">- <div>- <h1 className="text-2xl font-bold tracking-tight">{t('title')}</h1>- <p className="mt-1 text-sm text-muted-foreground">{t('subtitle')}</p>- </div>- <ActionCenterTabs />{brand ? (<ActionsContent key={brand.id} brand={brand} />) : (- <div className="flex flex-col items-center justify-center py-20 text-center">- <h2 className="text-lg font-semibold">{t('noBrand.title')}</h2>- <p className="mt-1 text-sm text-muted-foreground">{t('noBrand.description')}</p>- </div>+ <>+ <ActionsHeader />+ <ActionCenterTabs />+ <div className="flex flex-col items-center justify-center py-20 text-center">+ <h2 className="text-lg font-semibold">{t('noBrand.title')}</h2>+ <p className="mt-1 text-sm text-muted-foreground">{t('noBrand.description')}</p>+ </div>+ </>)}</div>);}+/** The page's title, with Getting started's Start or Skip on the right. */+function ActionsHeader({ action }: { action?: React.ReactNode }) {+ const t = useTranslations('actionCenter.actionsPage');+ return (+ <div className="flex flex-wrap items-start justify-between gap-4">+ <div>+ <h1 className="text-2xl font-bold tracking-tight">{t('title')}</h1>+ <p className="mt-1 text-sm text-muted-foreground">{t('subtitle')}</p>+ </div>+ {action}+ </div>+ );+}+function ActionsContent({ brand }: { brand: Brand }) {const t = useTranslations('actionCenter.actionsPage');const common = useTranslations('common');@@ -472,8 +497,134 @@ function ActionsContent({ brand }: { brand: Brand }) {setSearch('');};+ const showSteps = startedActive && gettingStarted !== null && category === GETTING_STARTED;+ const openCard = showSteps ? gettingStarted.steps.find((s) => s.key === stepKey) : undefined;++ // Getting started's Start and Skip (AC-ALT2 §5), for admins and managers:+ // the people who can set the steps up. Start shows while it isn't running+ // and the brand's setup is incomplete, or after a skip.+ const [confirmingSkip, setConfirmingSkip] = useState(false);+ const [switching, setSwitching] = useState(false);+ // The new brand's question, once answered or closed, stays closed for+ // this visit, even when the answer couldn't be saved or read back: it+ // never traps anyone on the page.+ const [askClosed, setAskClosed] = useState(false);+ const switchGettingStarted = async (+ change: (brandId: string) => Promise<void>,+ done: (started: GettingStartedStatus | null) => string,+ failed: string,+ ) => {+ setSwitching(true);+ setAskClosed(true);+ try {+ await change(brand.id);+ const started = await getGettingStarted(brand.id).catch(() => null);+ if (!mounted.current) return;+ if (started) setGettingStarted(started);+ setStepKey(null);+ setFocus(null);+ setCategory(started?.active ? GETTING_STARTED : 'all');+ toast.success(done(started));+ } catch {+ toast.error(failed);+ } finally {+ setSwitching(false);+ }+ };+ const start = (message: (started: GettingStartedStatus | null) => string) =>+ void switchGettingStarted(startGettingStarted, message, tStarted('start.failed'));+ const skip = (message: string) =>+ void switchGettingStarted(skipGettingStarted, () => message, tStarted('skip.failed'));++ const headerAction =+ !canManage || !gettingStarted ? null : startedActive ? (+ <Button+ variant="outline"+ size="sm"+ disabled={switching}+ onClick={() => setConfirmingSkip(true)}+ >+ {tStarted('skip.button')}+ </Button>+ ) : // A new brand's question, once closed, leaves Start in its place.+ (gettingStarted.asking ? askClosed : gettingStarted.needsSetup || gettingStarted.skipped) ? (+ <div className="flex flex-col items-end gap-1">+ <Button+ size="sm"+ disabled={switching}+ onClick={() => start((s) => tStarted('start.started', { count: s?.done ?? 0 }))}+ >+ <Sparkles className="h-3.5 w-3.5" />+ {tStarted('start.button')}+ </Button>+ <span className="text-xs text-muted-foreground">{tStarted('start.hint')}</span>+ </div>+ ) : null;++ // Header and tabs above every state of the page, with the dialogs; with a+ // step's card open, the page makes room for it on wide screens.+ const frame = (body: React.ReactNode) => (+ <div className={cn('space-y-6', openCard && 'min-[1300px]:pr-[440px]')}>+ <ActionsHeader action={headerAction} />+ <ActionCenterTabs />+ {body}++ <Dialog open={confirmingSkip} onOpenChange={setConfirmingSkip}>+ <DialogContent className="sm:max-w-sm">+ <DialogHeader>+ <DialogTitle>{tStarted('skip.title')}</DialogTitle>+ <DialogDescription>{tStarted('skip.body')}</DialogDescription>+ </DialogHeader>+ <p className="text-xs text-muted-foreground">{tStarted('skip.later')}</p>+ <DialogFooter>+ <Button+ variant="outline"+ onClick={() => {+ setConfirmingSkip(false);+ skip(tStarted('skip.done'));+ }}+ >+ {tStarted('skip.confirm')}+ </Button>+ <Button onClick={() => setConfirmingSkip(false)}>{tStarted('skip.keep')}</Button>+ </DialogFooter>+ </DialogContent>+ </Dialog>++ {/* A brand added beside others asks before running it. */}+ <Dialog+ open={canManage && Boolean(gettingStarted?.asking) && !askClosed}+ onOpenChange={(open) => {+ if (!open) setAskClosed(true);+ }}+ >+ <DialogContent className="sm:max-w-md">+ <DialogHeader>+ <DialogTitle>{tStarted('secondBrand.title', { brand: brand.name })}</DialogTitle>+ <DialogDescription>{tStarted('secondBrand.body')}</DialogDescription>+ </DialogHeader>+ <ul className="list-disc space-y-1 pl-5 text-sm">+ <li>{tStarted('secondBrand.runLine', { brand: brand.name })}</li>+ <li>{tStarted('secondBrand.skipLine')}</li>+ </ul>+ <DialogFooter>+ <Button+ variant="outline"+ onClick={() => skip(tStarted('secondBrand.skipped', { brand: brand.name }))}+ >+ {tStarted('secondBrand.skip')}+ </Button>+ <Button onClick={() => start(() => tStarted('secondBrand.ran', { brand: brand.name }))}>+ {tStarted('secondBrand.run')}+ </Button>+ </DialogFooter>+ </DialogContent>+ </Dialog>+ </div>+ );+if (isLoading) {- return (+ return frame(<div className="space-y-4"><div className="grid gap-3 sm:grid-cols-2 lg:grid-cols-5">{[0, 1, 2, 3, 4].map((i) => (@@ -485,35 +636,33 @@ function ActionsContent({ brand }: { brand: Brand }) {<Skeleton key={i} className="h-16 w-full" />))}</div>- </div>+ </div>,);}if (loadFailed) {- return (+ return frame(<div className="flex flex-col items-center justify-center rounded-lg border border-dashed py-20 text-center"><AlertCircle className="h-8 w-8 text-muted-foreground" /><h2 className="mt-4 font-semibold">{t('error.title')}</h2><Button variant="outline" className="mt-4" onClick={() => void load()}>{t('error.retry')}</Button>- </div>+ </div>,);}if (!actions?.length && !startedActive) {- return (+ return frame(<div className="flex flex-col items-center justify-center rounded-lg border border-dashed py-20 text-center"><ListChecks className="h-8 w-8 text-muted-foreground" /><h2 className="mt-4 font-semibold">{t('empty.title')}</h2><p className="mt-1 max-w-md text-sm text-muted-foreground">{t('empty.description')}</p>- </div>+ </div>,);}const list = actions ?? [];- const showSteps = startedActive && gettingStarted !== null && category === GETTING_STARTED;- const openCard = showSteps ? gettingStarted.steps.find((s) => s.key === stepKey) : undefined;// Before the first signals, the cards that rank actions have nothing to say.const noActions = list.length === 0;const showStepsCategory = () => {@@ -530,9 +679,8 @@ function ActionsContent({ brand }: { brand: Brand }) {? { value: '—', sub: tStarted('firstSignals'), dim: true }: { value, sub, isActive: focus === card, onClick: () => toggleFocus(card) };- return (- // With a step's card open, the list makes room for it on wide screens.- <div className={cn('space-y-4', openCard && 'min-[1300px]:pr-[440px]')}>+ return frame(+ <div className="space-y-4"><div className="grid gap-3 sm:grid-cols-2 lg:grid-cols-5">{startedActive && gettingStarted && (<GettingStartedSummaryCard@@ -748,7 +896,7 @@ function ActionsContent({ brand }: { brand: Brand }) {onChanged={() => void load()}onPatched={patchAction}/>- </div>+ </div>,);}diff --git a/web/src/lib/actions/getting-started.ts b/web/src/lib/actions/getting-started.tsindex 3fcbbdb3c..5a9bd60f5 100644--- a/web/src/lib/actions/getting-started.ts+++ b/web/src/lib/actions/getting-started.ts@@ -58,3 +58,36 @@ export async function skipGettingStartedStep(brandId: string, step: string): Pro);if (error) throw new Error(error.message);}++/**+ * Run Getting started for the brand: an existing brand's "Start getting+ * started", or "Run" on a new brand's question. Starting again after a skip+ * clears it. Admins and managers only (00197); the started time is kept, so+ * steps finished meanwhile still count.+ */+export async function startGettingStarted(brandId: string): Promise<void> {+ const supabase = await createClient();+ const { error } = await supabase+ .from('getting_started')+ .upsert(+ { brand_id: brandId, confirmed_at: new Date().toISOString(), dismissed_at: null },+ { onConflict: 'brand_id' },+ );+ if (error) throw new Error(error.message);+}++/**+ * Skip Getting started: the actions list goes back to normal, the steps+ * already done stay done, and Start brings it back.+ */+export async function skipGettingStarted(brandId: string): Promise<void> {+ const supabase = await createClient();+ const { data, error } = await supabase+ .from('getting_started')+ .update({ dismissed_at: new Date().toISOString() })+ .eq('brand_id', brandId)+ .select('brand_id');+ if (error) throw new Error(error.message);+ // RLS lets only admins and managers write: nothing changed otherwise.+ if (!data?.length) throw new Error('not skipped');+}diff --git a/web/src/lib/getting-started/steps.test.ts b/web/src/lib/getting-started/steps.test.tsindex 96e866e2d..022d30f34 100644--- a/web/src/lib/getting-started/steps.test.ts+++ b/web/src/lib/getting-started/steps.test.ts@@ -18,6 +18,7 @@ import {const facts = (over: Partial<GettingStartedFacts> = {}): GettingStartedFacts => ({startedAt: '2026-10-20T10:00:00Z',dismissedAt: null,+ confirmedAt: '2026-10-20T10:00:00Z',records: {},recordedAt: {},kpiSetupAt: null,@@ -32,6 +33,7 @@ const facts = (over: Partial<GettingStartedFacts> = {}): GettingStartedFacts =>contentSuggestions: 0,contentPicked: 0,contentCreated: 0,+ contentRecent: 0,audits: 0,...over,});@@ -240,6 +242,33 @@ describe('buildGettingStarted', () => {expect(buildGettingStarted(facts({ startedAt: null })).active).toBe(false);expect(buildGettingStarted(facts({ dismissedAt: '2026-10-21T00:00:00Z' })).active).toBe(false);});++ it('asks first for a brand added beside others, until someone answers', () => {+ const asking = buildGettingStarted(facts({ confirmedAt: null }));+ expect(asking).toMatchObject({ active: false, asking: true });+ // Skipped from the question: neither running nor asking.+ expect(+ buildGettingStarted(facts({ confirmedAt: null, dismissedAt: '2026-10-21T00:00:00Z' })),+ ).toMatchObject({ active: false, asking: false });+ });++ it('offers it to a brand whose setup is incomplete (AC-ALT2 §5)', () => {+ const complete = {+ competitors: 3,+ topicPrompts: [3, 3, 3],+ gsc: true,+ contentRecent: 1,+ };+ expect(buildGettingStarted(facts(complete)).needsSetup).toBe(false);+ for (const gap of [+ { competitors: 2 },+ { topicPrompts: [3, 3] },+ { gsc: false },+ { contentRecent: 0 },+ ]) {+ expect(buildGettingStarted(facts({ ...complete, ...gap })).needsSetup).toBe(true);+ }+ });});describe('parseGettingStartedFacts', () => {@@ -248,6 +277,7 @@ describe('parseGettingStartedFacts', () => {parseGettingStartedFacts({started_at: '2026-10-20T10:00:00+00:00',dismissed_at: null,+ confirmed_at: '2026-10-20T10:00:00+00:00',steps: {kpis: { state: 'done', at: '2026-10-20T12:00:00+00:00' },gsc: { state: 'skipped', at: '2026-10-20T12:05:00+00:00' },@@ -266,11 +296,13 @@ describe('parseGettingStartedFacts', () => {content_suggestions: 3,content_picked: 0,content_created: 0,+ content_recent: 2,audits: 1,}),).toEqual({startedAt: '2026-10-20T10:00:00+00:00',dismissedAt: null,+ confirmedAt: '2026-10-20T10:00:00+00:00',records: { kpis: 'done', gsc: 'skipped', visibility: 'opened' },recordedAt: { kpis: '2026-10-20T12:00:00+00:00', gsc: '2026-10-20T12:05:00+00:00' },kpiSetupAt: '2026-10-20T11:00:00+00:00',@@ -285,10 +317,22 @@ describe('parseGettingStartedFacts', () => {contentSuggestions: 3,contentPicked: 0,contentCreated: 0,+ contentRecent: 2,audits: 1,});});+ // gkhngyk on #1243: until 00197 is applied, the facts have no confirmed_at,+ // and every running brand would ask "Run Getting started?".+ it('reads a running brand as confirmed on a database without 00197', () => {+ const facts = parseGettingStartedFacts({ started_at: '2026-10-20T10:00:00+00:00' });+ expect(facts?.confirmedAt).toBe('2026-10-20T10:00:00+00:00');+ expect(+ parseGettingStartedFacts({ started_at: '2026-10-20T10:00:00+00:00', confirmed_at: null })+ ?.confirmedAt,+ ).toBeNull();+ });+it('gives null for a brand the caller can’t see', () => {expect(parseGettingStartedFacts(null)).toBeNull();});diff --git a/web/src/lib/getting-started/steps.ts b/web/src/lib/getting-started/steps.tsindex 9233718ed..1e801e278 100644--- a/web/src/lib/getting-started/steps.ts+++ b/web/src/lib/getting-started/steps.ts@@ -100,6 +100,8 @@ export type GettingStartedRecord = 'opened' | 'skipped' | 'done';export interface GettingStartedFacts {startedAt: string | null;dismissedAt: string | null;+ /** When someone chose to run it; null while a later brand still asks (00197). */+ confirmedAt: string | null;/** What a person did that leaves no other trace (getting_started_steps). */records: Partial<Record<string, GettingStartedRecord>>;/** When each record was made. */@@ -117,6 +119,8 @@ export interface GettingStartedFacts {contentSuggestions: number;contentPicked: number;contentCreated: number;+ /** Content sent to the CMS or completed in the last 30 days. */+ contentRecent: number;audits: number;}@@ -135,6 +139,16 @@ export interface GettingStartedStep extends GettingStartedStepDef {export interface GettingStartedStatus {/** Started for the brand and not skipped. */active: boolean;+ /** A brand added beside others: "Run Getting started for it?" is open. */+ asking: boolean;+ /**+ * The existing-customer rule (AC-ALT2 §5): fewer than 3 competitors or+ * topics, no Search Console, or no content in 30 days. Offers "Start+ * getting started" while it isn't running.+ */+ needsSetup: boolean;+ /** Skipped from the Actions page (or a new brand's question); Start brings it back. */+ skipped: boolean;steps: GettingStartedStep[];/** Steps done or skipped. */done: number;@@ -167,6 +181,8 @@ export function parseGettingStartedFacts(raw: unknown): GettingStartedFacts | nureturn {startedAt: str(r.started_at),dismissedAt: str(r.dismissed_at),+ // A database without 00197 has no confirmed_at: what started runs.+ confirmedAt: 'confirmed_at' in r ? str(r.confirmed_at) : str(r.started_at),records,recordedAt,kpiSetupAt: str(r.kpi_setup_at),@@ -181,6 +197,7 @@ export function parseGettingStartedFacts(raw: unknown): GettingStartedFacts | nucontentSuggestions: num(r.content_suggestions),contentPicked: num(r.content_picked),contentCreated: num(r.content_created),+ contentRecent: num(r.content_recent),audits: num(r.audits),};}@@ -275,8 +292,16 @@ export function buildGettingStarted(f: GettingStartedFacts): GettingStartedStatu}));const ready = steps.find((s) => s.key === 'ready')!;ready.state = steps.every((s) => s === ready || complete(s)) ? 'done' : 'waiting';+ const running = Boolean(f.startedAt) && !f.dismissedAt;return {- active: Boolean(f.startedAt) && !f.dismissedAt,+ active: running && Boolean(f.confirmedAt),+ asking: running && !f.confirmedAt,+ needsSetup:+ f.competitors < MIN_COMPETITORS ||+ f.topicPrompts.length < MIN_TOPICS ||+ !f.gsc ||+ f.contentRecent === 0,+ skipped: Boolean(f.dismissedAt),steps,done: steps.filter(complete).length,total: steps.length,diff --git a/web/src/types/supabase.ts b/web/src/types/supabase.tsindex 0c536e521..0be1efd18 100644--- a/web/src/types/supabase.ts+++ b/web/src/types/supabase.ts@@ -1101,16 +1101,19 @@ export type Database = {getting_started: {Row: {brand_id: string+ confirmed_at: string | nulldismissed_at: string | nullstarted_at: string}Insert: {brand_id: string+ confirmed_at?: string | nulldismissed_at?: string | nullstarted_at?: string}Update: {brand_id?: string+ confirmed_at?: string | nulldismissed_at?: string | nullstarted_at?: string}