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(layout): reach the brands page and the brand's settings from the brand switcher (#1339)

Cihanbabe26197abe
diff --git a/web/messages/en.json b/web/messages/en.json
index 3473b224c..3e44fc8d3 100644
--- a/web/messages/en.json
+++ b/web/messages/en.json
@@ -6125,6 +6125,8 @@
"title": "Brands",
"description": "Manage all the brands you track across AI platforms.",
"addBrand": "Add Brand",
+ "showAllBrands": "Show My All Brands",
+ "visitBrandSettings": "Visit Brand Setting",
"editBrand": "Edit Brand",
"deleteBrand": "Delete Brand",
"noBrands": "No brands yet",
@@ -6188,6 +6190,8 @@
"confirmDelete": "Type the brand name to confirm:",
"deleteConfirmPlaceholder": "Brand name",
"deleteButton": "Delete Brand Permanently",
+ "managersOnlyEdit": "Only admins and managers can change these settings.",
+ "adminsOnlyDelete": "Only admins can delete a brand.",
"shopping": {
"title": "Shopping mode",
"description": "Turn this on if this brand is in e-commerce. We’ll add ChatGPT Shopping to every prompt under this brand and show Product Visibility in the menu.",
diff --git a/web/src/app/[locale]/(dashboard)/dashboard/brands/[id]/settings/page.test.tsx b/web/src/app/[locale]/(dashboard)/dashboard/brands/[id]/settings/page.test.tsx
index 6c12db576..60c823a20 100644
--- a/web/src/app/[locale]/(dashboard)/dashboard/brands/[id]/settings/page.test.tsx
+++ b/web/src/app/[locale]/(dashboard)/dashboard/brands/[id]/settings/page.test.tsx
@@ -1,7 +1,7 @@
import { Suspense } from 'react';
import { act } from 'react';
import { createRoot } from 'react-dom/client';
-import { afterEach, describe, expect, it, vi } from 'vitest';
+import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest';
import type { Brand } from '@/types';
(
@@ -79,10 +79,11 @@ vi.mock('@/lib/actions/brand-domain', () => ({
syncDomains: vi.fn(),
}));
+const getCompetitors = vi.hoisted(() => vi.fn());
vi.mock('@/lib/actions/competitor', () => ({
addCompetitor: vi.fn(),
deleteCompetitor: vi.fn(),
- getCompetitors: vi.fn().mockResolvedValue([]),
+ getCompetitors: (...args: unknown[]) => getCompetitors(...args),
}));
vi.mock('@/config/api', () => ({
@@ -260,3 +261,76 @@ describe('brand settings Shopping mode', () => {
await act(async () => root.unmount());
});
});
+
+// The brand's writes follow its RLS: brands and brand_domains update and
+// competitors writes for admins and managers, and a brand's delete for admins
+// (the server's rule). The others read the settings, with a note.
+describe('brand settings role gates', () => {
+ // afterEach's restoreAllMocks clears the read the Competitors tab makes.
+ beforeEach(() => getCompetitors.mockResolvedValue([]));
+
+ async function render() {
+ const container = document.createElement('div');
+ document.body.append(container);
+ const root = createRoot(container);
+ await act(async () => {
+ root.render(
+ <Suspense>
+ <BrandSettingsPage params={Promise.resolve({ id: brand.id })} />
+ </Suspense>,
+ );
+ });
+ const openTab = async (name: string) => {
+ const tab = [...container.querySelectorAll<HTMLElement>('[role="tab"]')].find(
+ (el) => el.textContent?.trim() === name,
+ )!;
+ await act(async () => {
+ tab.dispatchEvent(new MouseEvent('pointerdown', { bubbles: true }));
+ tab.click();
+ });
+ };
+ // The shown panel's fieldset: the hidden ones may stay mounted.
+ const fieldset = () =>
+ container.querySelector<HTMLFieldSetElement>('[role="tabpanel"]:not([hidden]) fieldset')!;
+ return { container, root, openTab, fieldset };
+ }
+
+ it('lets an analyst read the brand, not change or delete it', async () => {
+ Object.assign(role, { canAdmin: false, canManage: false });
+ const { container, root, openTab, fieldset } = await render();
+
+ expect(fieldset().disabled).toBe(true);
+ expect(container.textContent).toContain('settings.managersOnlyEdit');
+ for (const tab of ['settings.domainsTab', 'Competitors']) {
+ await openTab(tab);
+ expect(fieldset().disabled).toBe(true);
+ }
+ await openTab('settings.dangerTab');
+ expect(fieldset().disabled).toBe(true);
+ expect(container.textContent).toContain('settings.adminsOnlyDelete');
+
+ await act(async () => root.unmount());
+ });
+
+ it('lets a manager change the brand, but leaves its delete to admins', async () => {
+ Object.assign(role, { canAdmin: false, canManage: true });
+ const { container, root, openTab, fieldset } = await render();
+
+ expect(fieldset().disabled).toBe(false);
+ expect(container.textContent).not.toContain('settings.managersOnlyEdit');
+ await openTab('settings.dangerTab');
+ expect(fieldset().disabled).toBe(true);
+ expect(container.textContent).toContain('settings.adminsOnlyDelete');
+
+ await act(async () => root.unmount());
+ });
+
+ it('lets an admin delete the brand', async () => {
+ const { container, root, openTab, fieldset } = await render();
+ await openTab('settings.dangerTab');
+ expect(fieldset().disabled).toBe(false);
+ expect(container.textContent).not.toContain('settings.adminsOnlyDelete');
+
+ await act(async () => root.unmount());
+ });
+});
diff --git a/web/src/app/[locale]/(dashboard)/dashboard/brands/[id]/settings/page.tsx b/web/src/app/[locale]/(dashboard)/dashboard/brands/[id]/settings/page.tsx
index 9044a7e5b..191909667 100644
--- a/web/src/app/[locale]/(dashboard)/dashboard/brands/[id]/settings/page.tsx
+++ b/web/src/app/[locale]/(dashboard)/dashboard/brands/[id]/settings/page.tsx
@@ -154,6 +154,7 @@ function GeneralTab({
onUpdate: (updates: Partial<Brand>) => void;
}) {
const t = useTranslations('brands');
+ const { canManage } = useUserRole();
const [name, setName] = useState(brand.name);
const [logoUrl, setLogoUrl] = useState(brand.logoUrl ?? '');
const [industry, setIndustry] = useState(brand.industry ?? '');
@@ -213,140 +214,146 @@ function GeneralTab({
<CardDescription>Update your brand&apos;s basic information.</CardDescription>
</CardHeader>
<CardContent className="space-y-4">
- <div className="space-y-2">
- <Label htmlFor="name">{t('brandName')} *</Label>
- <Input
- id="name"
- value={name}
- onChange={(e) => setName(e.target.value)}
- placeholder={t('brandNamePlaceholder')}
- />
- </div>
-
- <div className="space-y-2">
- <Label htmlFor="logo-url">{t('logoUrl')}</Label>
- <Input
- id="logo-url"
- type="text"
- value={logoUrl}
- onChange={(e) => setLogoUrl(e.target.value)}
- placeholder="https://example.com/logo.png"
- />
- {logoUrl.trim() && !logoUrl.trim().match(/^https?:\/\/.+/) && (
- <p className="text-xs text-destructive">URL must start with https:// or http://</p>
- )}
- <p className="text-xs text-muted-foreground">{t('logoUrlHint')}</p>
- </div>
+ {/* Admins and managers write the brand (RLS); others read it. */}
+ <fieldset disabled={!canManage} className="min-w-0 space-y-4">
+ <div className="space-y-2">
+ <Label htmlFor="name">{t('brandName')} *</Label>
+ <Input
+ id="name"
+ value={name}
+ onChange={(e) => setName(e.target.value)}
+ placeholder={t('brandNamePlaceholder')}
+ />
+ </div>
- <div className="space-y-2">
- <Label htmlFor="industry">{t('industry')}</Label>
- <Select
- items={INDUSTRY_ITEMS}
- value={industry}
- onValueChange={(v) => setIndustry(v ?? '')}
- >
- <SelectTrigger id="industry">
- <SelectValue placeholder={t('industryPlaceholder')} />
- </SelectTrigger>
- <SelectContent>
- {INDUSTRIES.map((ind) => (
- <SelectItem key={ind} value={ind}>
- {ind}
- </SelectItem>
- ))}
- </SelectContent>
- </Select>
- </div>
+ <div className="space-y-2">
+ <Label htmlFor="logo-url">{t('logoUrl')}</Label>
+ <Input
+ id="logo-url"
+ type="text"
+ value={logoUrl}
+ onChange={(e) => setLogoUrl(e.target.value)}
+ placeholder="https://example.com/logo.png"
+ />
+ {logoUrl.trim() && !logoUrl.trim().match(/^https?:\/\/.+/) && (
+ <p className="text-xs text-destructive">URL must start with https:// or http://</p>
+ )}
+ <p className="text-xs text-muted-foreground">{t('logoUrlHint')}</p>
+ </div>
- <div className="space-y-2">
- <Label htmlFor="site-type">{t('siteType')}</Label>
- <Select
- items={siteTypeItems}
- value={siteType ?? guessedSiteType}
- onValueChange={(v) => {
- if (isSiteType(v)) setSiteType(v);
- }}
- >
- <SelectTrigger id="site-type">
- <SelectValue />
- </SelectTrigger>
- <SelectContent>
- {siteTypeItems.map((item) => (
- <SelectItem key={item.value} value={item.value}>
- {item.label}
- </SelectItem>
- ))}
- </SelectContent>
- </Select>
- <p className="text-xs text-muted-foreground">
- {t('settings.siteTypeHint')}
- {siteType === null && ` ${t('settings.siteTypeGuessed')}`}
- </p>
- </div>
+ <div className="space-y-2">
+ <Label htmlFor="industry">{t('industry')}</Label>
+ <Select
+ items={INDUSTRY_ITEMS}
+ value={industry}
+ onValueChange={(v) => setIndustry(v ?? '')}
+ >
+ <SelectTrigger id="industry">
+ <SelectValue placeholder={t('industryPlaceholder')} />
+ </SelectTrigger>
+ <SelectContent>
+ {INDUSTRIES.map((ind) => (
+ <SelectItem key={ind} value={ind}>
+ {ind}
+ </SelectItem>
+ ))}
+ </SelectContent>
+ </Select>
+ </div>
- <div className="space-y-2">
- <Label htmlFor="description">{t('description_field')}</Label>
- <Textarea
- id="description"
- value={description}
- onChange={(e) => setDescription(e.target.value)}
- placeholder={t('descriptionPlaceholder')}
- rows={3}
- />
- </div>
+ <div className="space-y-2">
+ <Label htmlFor="site-type">{t('siteType')}</Label>
+ <Select
+ items={siteTypeItems}
+ value={siteType ?? guessedSiteType}
+ onValueChange={(v) => {
+ if (isSiteType(v)) setSiteType(v);
+ }}
+ >
+ <SelectTrigger id="site-type">
+ <SelectValue />
+ </SelectTrigger>
+ <SelectContent>
+ {siteTypeItems.map((item) => (
+ <SelectItem key={item.value} value={item.value}>
+ {item.label}
+ </SelectItem>
+ ))}
+ </SelectContent>
+ </Select>
+ <p className="text-xs text-muted-foreground">
+ {t('settings.siteTypeHint')}
+ {siteType === null && ` ${t('settings.siteTypeGuessed')}`}
+ </p>
+ </div>
- <div className="space-y-2">
- <Label>{t('settings.region')}</Label>
- <Select
- items={REGION_ITEMS}
- value={region}
- onValueChange={(v) => {
- if (!v) return;
- setRegion(v);
- if (v !== 'US') setUsState('');
- }}
- >
- <SelectTrigger>
- <SelectValue />
- </SelectTrigger>
- <SelectContent>
- {REGIONS.map((r) => (
- <SelectItem key={r.code} value={r.code}>
- {r.label}
- </SelectItem>
- ))}
- </SelectContent>
- </Select>
- </div>
+ <div className="space-y-2">
+ <Label htmlFor="description">{t('description_field')}</Label>
+ <Textarea
+ id="description"
+ value={description}
+ onChange={(e) => setDescription(e.target.value)}
+ placeholder={t('descriptionPlaceholder')}
+ rows={3}
+ />
+ </div>
- {region === 'US' && (
<div className="space-y-2">
- <Label>{t('settings.stateOptional')}</Label>
+ <Label>{t('settings.region')}</Label>
<Select
- items={stateItems}
- value={usState || 'nationwide'}
- onValueChange={(v) => setUsState(!v || v === 'nationwide' ? '' : v)}
+ items={REGION_ITEMS}
+ value={region}
+ onValueChange={(v) => {
+ if (!v) return;
+ setRegion(v);
+ if (v !== 'US') setUsState('');
+ }}
>
<SelectTrigger>
<SelectValue />
</SelectTrigger>
<SelectContent>
- <SelectItem value="nationwide">{t('settings.nationwide')}</SelectItem>
- {US_STATES.map((s) => (
- <SelectItem key={s.code} value={s.code}>
- {s.label}
+ {REGIONS.map((r) => (
+ <SelectItem key={r.code} value={r.code}>
+ {r.label}
</SelectItem>
))}
</SelectContent>
</Select>
- <p className="text-xs text-muted-foreground">{t('settings.stateHint')}</p>
</div>
- )}
- <Button onClick={handleSave} disabled={isSaving || !name.trim()} className="gap-2">
- {isSaving ? <Loader2 className="h-4 w-4 animate-spin" /> : <Save className="h-4 w-4" />}
- {t('settings.saveChanges')}
- </Button>
+ {region === 'US' && (
+ <div className="space-y-2">
+ <Label>{t('settings.stateOptional')}</Label>
+ <Select
+ items={stateItems}
+ value={usState || 'nationwide'}
+ onValueChange={(v) => setUsState(!v || v === 'nationwide' ? '' : v)}
+ >
+ <SelectTrigger>
+ <SelectValue />
+ </SelectTrigger>
+ <SelectContent>
+ <SelectItem value="nationwide">{t('settings.nationwide')}</SelectItem>
+ {US_STATES.map((s) => (
+ <SelectItem key={s.code} value={s.code}>
+ {s.label}
+ </SelectItem>
+ ))}
+ </SelectContent>
+ </Select>
+ <p className="text-xs text-muted-foreground">{t('settings.stateHint')}</p>
+ </div>
+ )}
+
+ <Button onClick={handleSave} disabled={isSaving || !name.trim()} className="gap-2">
+ {isSaving ? <Loader2 className="h-4 w-4 animate-spin" /> : <Save className="h-4 w-4" />}
+ {t('settings.saveChanges')}
+ </Button>
+ </fieldset>
+ {!canManage && (
+ <p className="text-xs text-muted-foreground">{t('settings.managersOnlyEdit')}</p>
+ )}
</CardContent>
</Card>
);
@@ -524,6 +531,7 @@ function DomainsTab({
onUpdate: (updates: Partial<Brand>) => void;
}) {
const t = useTranslations('brands');
+ const { canManage } = useUserRole();
const [domains, setDomains] = useState<BrandDomain[]>(brand.domains);
const [isSaving, setIsSaving] = useState(false);
const [newDomain, setNewDomain] = useState('');
@@ -594,79 +602,89 @@ function DomainsTab({
</CardDescription>
</CardHeader>
<CardContent className="space-y-4">
- <div className="space-y-2">
- {domains.map((d) => (
- <div key={d.id} className="flex items-center gap-3 rounded-lg border px-3 py-2.5">
- <Globe className="h-4 w-4 shrink-0 text-muted-foreground" />
- <div className="flex-1 overflow-hidden">
- <p className="truncate text-sm font-medium">{d.domain}</p>
- {d.country && <p className="text-xs text-muted-foreground">{d.country}</p>}
+ {/* Admins and managers write the brand (RLS); others read it. */}
+ <fieldset disabled={!canManage} className="min-w-0 space-y-4">
+ <div className="space-y-2">
+ {domains.map((d) => (
+ <div key={d.id} className="flex items-center gap-3 rounded-lg border px-3 py-2.5">
+ <Globe className="h-4 w-4 shrink-0 text-muted-foreground" />
+ <div className="flex-1 overflow-hidden">
+ <p className="truncate text-sm font-medium">{d.domain}</p>
+ {d.country && <p className="text-xs text-muted-foreground">{d.country}</p>}
+ </div>
+ {d.isPrimary && (
+ <Badge variant="secondary" className="text-xs shrink-0">
+ {t('primaryDomain')}
+ </Badge>
+ )}
+ {!d.isPrimary && (
+ <Button
+ variant="ghost"
+ size="sm"
+ className="h-7 text-xs shrink-0"
+ onClick={() => setPrimary(d.id)}
+ >
+ {t('setPrimary')}
+ </Button>
+ )}
+ {domains.length > 1 && (
+ <Button
+ variant="ghost"
+ size="icon"
+ className="h-7 w-7 shrink-0 text-destructive hover:text-destructive"
+ onClick={() => removeDomainLocal(d.id)}
+ aria-label="Remove domain"
+ >
+ <Trash2 className="h-3.5 w-3.5" />
+ </Button>
+ )}
</div>
- {d.isPrimary && (
- <Badge variant="secondary" className="text-xs shrink-0">
- {t('primaryDomain')}
- </Badge>
- )}
- {!d.isPrimary && (
- <Button
- variant="ghost"
- size="sm"
- className="h-7 text-xs shrink-0"
- onClick={() => setPrimary(d.id)}
- >
- {t('setPrimary')}
- </Button>
- )}
- {domains.length > 1 && (
- <Button
- variant="ghost"
- size="icon"
- className="h-7 w-7 shrink-0 text-destructive hover:text-destructive"
- onClick={() => removeDomainLocal(d.id)}
- aria-label="Remove domain"
- >
- <Trash2 className="h-3.5 w-3.5" />
- </Button>
- )}
- </div>
- ))}
- </div>
+ ))}
+ </div>
- <Separator />
+ <Separator />
- <div className="space-y-2">
- <Label className="text-sm font-medium">{t('addDomain')}</Label>
- <div className="flex gap-2">
- <Input
- placeholder={t('domainPlaceholder')}
- value={newDomain}
- onChange={(e) => setNewDomain(e.target.value)}
- onKeyDown={(e) => e.key === 'Enter' && addDomain()}
- className="flex-1"
- />
- <Input
- placeholder={t('countryPlaceholder')}
- value={newCountry}
- onChange={(e) => setNewCountry(e.target.value)}
- className="w-28"
- />
- <Button
- type="button"
- variant="outline"
- size="icon"
- onClick={addDomain}
- disabled={!newDomain.trim()}
- aria-label="Add domain"
- >
- <Plus className="h-4 w-4" />
- </Button>
+ <div className="space-y-2">
+ <Label className="text-sm font-medium">{t('addDomain')}</Label>
+ <div className="flex gap-2">
+ <Input
+ placeholder={t('domainPlaceholder')}
+ value={newDomain}
+ onChange={(e) => setNewDomain(e.target.value)}
+ onKeyDown={(e) => e.key === 'Enter' && addDomain()}
+ className="flex-1"
+ />
+ <Input
+ placeholder={t('countryPlaceholder')}
+ value={newCountry}
+ onChange={(e) => setNewCountry(e.target.value)}
+ className="w-28"
+ />
+ <Button
+ type="button"
+ variant="outline"
+ size="icon"
+ onClick={addDomain}
+ disabled={!newDomain.trim()}
+ aria-label="Add domain"
+ >
+ <Plus className="h-4 w-4" />
+ </Button>
+ </div>
</div>
- </div>
- <Button onClick={handleSave} disabled={isSaving || domains.length === 0} className="gap-2">
- {isSaving ? <Loader2 className="h-4 w-4 animate-spin" /> : <Save className="h-4 w-4" />}
- {t('settings.saveChanges')}
- </Button>
+ <Button
+ onClick={handleSave}
+ disabled={isSaving || domains.length === 0}
+ className="gap-2"
+ >
+ {isSaving ? <Loader2 className="h-4 w-4 animate-spin" /> : <Save className="h-4 w-4" />}
+ {t('settings.saveChanges')}
+ </Button>
+ </fieldset>
+ {!canManage && (
+ <p className="text-xs text-muted-foreground">{t('settings.managersOnlyEdit')}</p>
+ )}
</CardContent>
</Card>
);
@@ -675,6 +693,8 @@ function DomainsTab({
// ─── Competitors Tab ──────────────────────────────────────────────────────────
function CompetitorsTab({ brandId }: { brandId: string }) {
+ const t = useTranslations('brands');
+ const { canManage } = useUserRole();
const [competitors, setCompetitors] = useState<Competitor[]>([]);
const [isLoading, setIsLoading] = useState(true);
const [isAdding, setIsAdding] = useState(false);
@@ -747,111 +767,120 @@ function CompetitorsTab({ brandId }: { brandId: string }) {
</CardDescription>
</CardHeader>
<CardContent className="space-y-4">
- {isLoading ? (
- <div className="flex items-center justify-center py-8">
- <Loader2 className="h-6 w-6 animate-spin text-muted-foreground" />
- </div>
- ) : (
- <>
- {competitors.length > 0 && (
- <div className="space-y-2">
- {competitors.map((c) => (
- <div key={c.id} className="flex items-center gap-3 rounded-lg border px-3 py-2.5">
- {c.domain ? (
- /* eslint-disable-next-line @next/next/no-img-element */
- <img
- src={getFaviconUrl(c.domain, 64)}
- alt={c.name}
- className="h-8 w-8 shrink-0 rounded-full bg-white object-contain"
- />
- ) : (
- <div className="flex h-8 w-8 shrink-0 items-center justify-center rounded-full bg-white text-xs font-bold">
- {c.name.charAt(0).toUpperCase()}
- </div>
- )}
- <div className="flex-1 overflow-hidden">
- <p className="truncate text-sm font-medium">{c.name}</p>
- {c.domain && <p className="text-xs text-muted-foreground">{c.domain}</p>}
- </div>
- <Dialog
- open={deletingId === c.id}
- onOpenChange={(open) => !open && setDeletingId(null)}
+ {/* Admins and managers write the brand (RLS); others read it. */}
+ <fieldset disabled={!canManage} className="min-w-0 space-y-4">
+ {isLoading ? (
+ <div className="flex items-center justify-center py-8">
+ <Loader2 className="h-6 w-6 animate-spin text-muted-foreground" />
+ </div>
+ ) : (
+ <>
+ {competitors.length > 0 && (
+ <div className="space-y-2">
+ {competitors.map((c) => (
+ <div
+ key={c.id}
+ className="flex items-center gap-3 rounded-lg border px-3 py-2.5"
>
- <Button
- variant="ghost"
- size="icon"
- className="h-7 w-7 shrink-0 text-destructive hover:text-destructive"
- onClick={() => setDeletingId(c.id)}
- aria-label="Delete competitor"
+ {c.domain ? (
+ /* eslint-disable-next-line @next/next/no-img-element */
+ <img
+ src={getFaviconUrl(c.domain, 64)}
+ alt={c.name}
+ className="h-8 w-8 shrink-0 rounded-full bg-white object-contain"
+ />
+ ) : (
+ <div className="flex h-8 w-8 shrink-0 items-center justify-center rounded-full bg-white text-xs font-bold">
+ {c.name.charAt(0).toUpperCase()}
+ </div>
+ )}
+ <div className="flex-1 overflow-hidden">
+ <p className="truncate text-sm font-medium">{c.name}</p>
+ {c.domain && <p className="text-xs text-muted-foreground">{c.domain}</p>}
+ </div>
+ <Dialog
+ open={deletingId === c.id}
+ onOpenChange={(open) => !open && setDeletingId(null)}
>
- <Trash2 className="h-3.5 w-3.5" />
- </Button>
- <DialogContent>
- <DialogHeader>
- <DialogTitle>Remove {c.name}?</DialogTitle>
- <DialogDescription>
- This will remove the competitor and its comparison data. This action
- cannot be undone.
- </DialogDescription>
- </DialogHeader>
- <DialogFooter>
- <Button variant="outline" onClick={() => setDeletingId(null)}>
- Cancel
- </Button>
- <Button variant="destructive" onClick={() => handleDelete(c.id)}>
- Remove
- </Button>
- </DialogFooter>
- </DialogContent>
- </Dialog>
- </div>
- ))}
- </div>
- )}
+ <Button
+ variant="ghost"
+ size="icon"
+ className="h-7 w-7 shrink-0 text-destructive hover:text-destructive"
+ onClick={() => setDeletingId(c.id)}
+ aria-label="Delete competitor"
+ >
+ <Trash2 className="h-3.5 w-3.5" />
+ </Button>
+ <DialogContent>
+ <DialogHeader>
+ <DialogTitle>Remove {c.name}?</DialogTitle>
+ <DialogDescription>
+ This will remove the competitor and its comparison data. This action
+ cannot be undone.
+ </DialogDescription>
+ </DialogHeader>
+ <DialogFooter>
+ <Button variant="outline" onClick={() => setDeletingId(null)}>
+ Cancel
+ </Button>
+ <Button variant="destructive" onClick={() => handleDelete(c.id)}>
+ Remove
+ </Button>
+ </DialogFooter>
+ </DialogContent>
+ </Dialog>
+ </div>
+ ))}
+ </div>
+ )}
- {competitors.length === 0 && (
- <div className="rounded-lg border border-dashed py-8 text-center">
- <p className="text-sm text-muted-foreground">
- No competitors added yet. Add your competitors below.
- </p>
- </div>
- )}
+ {competitors.length === 0 && (
+ <div className="rounded-lg border border-dashed py-8 text-center">
+ <p className="text-sm text-muted-foreground">
+ No competitors added yet. Add your competitors below.
+ </p>
+ </div>
+ )}
- <Separator />
+ <Separator />
- <div className="space-y-2">
- <Label className="text-sm font-medium">Add Competitor</Label>
- <div className="flex gap-2">
- <Input
- placeholder="Competitor name"
- value={newName}
- onChange={(e) => setNewName(e.target.value)}
- onKeyDown={(e) => e.key === 'Enter' && newName.trim() && handleAdd()}
- className="flex-1"
- />
- <Input
- placeholder="domain.com"
- value={newDomain}
- onChange={(e) => setNewDomain(e.target.value)}
- onKeyDown={(e) => e.key === 'Enter' && newName.trim() && handleAdd()}
- className="w-40"
- />
- <Button
- variant="outline"
- onClick={handleAdd}
- disabled={isAdding || !newName.trim()}
- className="gap-1.5 shrink-0"
- >
- {isAdding ? (
- <Loader2 className="h-4 w-4 animate-spin" />
- ) : (
- <Plus className="h-4 w-4" />
- )}
- Add
- </Button>
+ <div className="space-y-2">
+ <Label className="text-sm font-medium">Add Competitor</Label>
+ <div className="flex gap-2">
+ <Input
+ placeholder="Competitor name"
+ value={newName}
+ onChange={(e) => setNewName(e.target.value)}
+ onKeyDown={(e) => e.key === 'Enter' && newName.trim() && handleAdd()}
+ className="flex-1"
+ />
+ <Input
+ placeholder="domain.com"
+ value={newDomain}
+ onChange={(e) => setNewDomain(e.target.value)}
+ onKeyDown={(e) => e.key === 'Enter' && newName.trim() && handleAdd()}
+ className="w-40"
+ />
+ <Button
+ variant="outline"
+ onClick={handleAdd}
+ disabled={isAdding || !newName.trim()}
+ className="gap-1.5 shrink-0"
+ >
+ {isAdding ? (
+ <Loader2 className="h-4 w-4 animate-spin" />
+ ) : (
+ <Plus className="h-4 w-4" />
+ )}
+ Add
+ </Button>
+ </div>
</div>
- </div>
- </>
+ </>
+ )}
+ </fieldset>
+ {!canManage && (
+ <p className="text-xs text-muted-foreground">{t('settings.managersOnlyEdit')}</p>
)}
</CardContent>
</Card>
@@ -998,6 +1027,7 @@ function DangerTab({
onDelete: (pending: boolean) => Promise<void>;
}) {
const t = useTranslations('brands');
+ const { canAdmin } = useUserRole();
const [confirmValue, setConfirmValue] = useState('');
const [isDeleting, setIsDeleting] = useState(false);
@@ -1027,29 +1057,35 @@ function DangerTab({
<CardDescription>{t('settings.deleteWarning')}</CardDescription>
</CardHeader>
<CardContent className="space-y-4">
- <div className="space-y-2">
- <Label className="text-sm">
- {t('settings.confirmDelete')} <span className="font-semibold">{brand.name}</span>
- </Label>
- <Input
- placeholder={t('settings.deleteConfirmPlaceholder')}
- value={confirmValue}
- onChange={(e) => setConfirmValue(e.target.value)}
- />
- </div>
- <Button
- variant="destructive"
- disabled={!canDelete || isDeleting}
- onClick={handleDelete}
- className="gap-2"
- >
- {isDeleting ? (
- <Loader2 className="h-4 w-4 animate-spin" />
- ) : (
- <Trash2 className="h-4 w-4" />
- )}
- {t('settings.deleteButton')}
- </Button>
+ {/* Only an admin deletes a brand (the server's rule). */}
+ <fieldset disabled={!canAdmin} className="min-w-0 space-y-4">
+ <div className="space-y-2">
+ <Label className="text-sm">
+ {t('settings.confirmDelete')} <span className="font-semibold">{brand.name}</span>
+ </Label>
+ <Input
+ placeholder={t('settings.deleteConfirmPlaceholder')}
+ value={confirmValue}
+ onChange={(e) => setConfirmValue(e.target.value)}
+ />
+ </div>
+ <Button
+ variant="destructive"
+ disabled={!canDelete || isDeleting}
+ onClick={handleDelete}
+ className="gap-2"
+ >
+ {isDeleting ? (
+ <Loader2 className="h-4 w-4 animate-spin" />
+ ) : (
+ <Trash2 className="h-4 w-4" />
+ )}
+ {t('settings.deleteButton')}
+ </Button>
+ </fieldset>
+ {!canAdmin && (
+ <p className="text-xs text-muted-foreground">{t('settings.adminsOnlyDelete')}</p>
+ )}
</CardContent>
</Card>
);
diff --git a/web/src/components/layout/brand-switcher.test.tsx b/web/src/components/layout/brand-switcher.test.tsx
new file mode 100644
index 000000000..2b2a0901a
--- /dev/null
+++ b/web/src/components/layout/brand-switcher.test.tsx
@@ -0,0 +1,134 @@
+import { act } from 'react';
+import { createRoot, type Root } from 'react-dom/client';
+import { NextIntlClientProvider } from 'next-intl';
+import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest';
+import messages from '../../../messages/en.json';
+import { BrandSwitcher } from './brand-switcher';
+
+const push = vi.fn();
+vi.mock('@/i18n/navigation', () => ({
+ useRouter: () => ({ push }),
+ Link: ({ href, children, ...rest }: { href: string; children?: React.ReactNode }) => (
+ <a href={href} {...rest}>
+ {children}
+ </a>
+ ),
+}));
+const brand = (id: string, name: string) => ({
+ id,
+ name,
+ logoUrl: undefined,
+ isActive: true,
+ domains: [
+ { id: `${id}-d`, brandId: id, domain: `${name.toLowerCase()}.example`, isPrimary: true },
+ ],
+});
+const store = vi.hoisted(() => ({
+ brands: [] as ReturnType<typeof brand>[],
+ activeBrandId: null as string | null,
+ setActiveBrand: vi.fn(),
+}));
+vi.mock('@/stores/use-brand-store', () => ({ useBrandStore: () => store }));
+const role = vi.hoisted(() => ({ canManage: true }));
+vi.mock('@/hooks/use-user-role', () => ({ useUserRole: () => role }));
+
+(globalThis as typeof globalThis & { IS_REACT_ACT_ENVIRONMENT: boolean }).IS_REACT_ACT_ENVIRONMENT =
+ true;
+
+let container: HTMLDivElement;
+let root: Root;
+const onNavigate = vi.fn();
+
+async function render(collapsed = false) {
+ await act(async () =>
+ root.render(
+ <NextIntlClientProvider locale="en" messages={messages}>
+ <BrandSwitcher collapsed={collapsed} onNavigate={onNavigate} />
+ </NextIntlClientProvider>,
+ ),
+ );
+}
+const trigger = () => container.querySelector<HTMLButtonElement>('[aria-label="Switch brand"]')!;
+const settings = () =>
+ container.querySelector<HTMLAnchorElement>('[aria-label="Visit Brand Setting"]');
+async function openMenu() {
+ await act(async () => {
+ trigger().dispatchEvent(new MouseEvent('pointerdown', { bubbles: true }));
+ trigger().click();
+ });
+ return [...document.querySelectorAll<HTMLElement>('[role="menuitem"]')];
+}
+
+beforeEach(() => {
+ container = document.createElement('div');
+ document.body.appendChild(container);
+ root = createRoot(container);
+ store.brands = [brand('b1', 'Acme'), brand('b2', 'Globex')];
+ store.activeBrandId = 'b1';
+ push.mockReset();
+ onNavigate.mockReset();
+ role.canManage = true;
+});
+
+afterEach(() => {
+ act(() => root.unmount());
+ container.remove();
+ document.body.replaceChildren();
+});
+
+describe('BrandSwitcher', () => {
+ it("links the selected brand's settings beside the switcher, not inside it", async () => {
+ await render();
+ expect(trigger().textContent).toContain('Acme');
+ const link = settings()!;
+ expect(link.getAttribute('href')).toBe('/dashboard/brands/b1/settings');
+ expect(trigger().contains(link)).toBe(false);
+ // jsdom can't follow a link: keep the click, not the navigation.
+ link.addEventListener('click', (e) => e.preventDefault());
+ await act(async () => link.click());
+ expect(onNavigate).toHaveBeenCalled();
+ });
+
+ it('lists the brands, then all brands and a new one', async () => {
+ await render();
+ const items = await openMenu();
+ expect(items).toHaveLength(4);
+ expect(items[0].textContent).toContain('acme.example');
+ expect(items[1].textContent).toContain('globex.example');
+ expect(items.slice(2).map((i) => i.textContent?.trim())).toEqual([
+ 'Show My All Brands',
+ 'Add Brand',
+ ]);
+ await act(async () => items[2].click());
+ expect(push).toHaveBeenCalledWith('/dashboard/brands');
+ expect(onNavigate).toHaveBeenCalled();
+ });
+
+ it('adds a brand on its own page', async () => {
+ await render();
+ const items = await openMenu();
+ await act(async () => items[3].click());
+ expect(push).toHaveBeenCalledWith('/dashboard/brands/new');
+ });
+
+ // brands: admin/manager insert — the others would hit the wizard's first error.
+ it('offers Add Brand to admins and managers only', async () => {
+ role.canManage = false;
+ await render();
+ const items = await openMenu();
+ expect(items.map((i) => i.textContent?.trim()).slice(2)).toEqual(['Show My All Brands']);
+
+ act(() => root.unmount());
+ document.body.replaceChildren(container);
+ root = createRoot(container);
+ store.brands = [];
+ await render();
+ expect(container.textContent).toBe('');
+ });
+
+ it('has no room for the settings link when the sidebar is collapsed', async () => {
+ await render(true);
+ expect(trigger()).not.toBeNull();
+ expect(settings()).toBeNull();
+ });
+});
diff --git a/web/src/components/layout/brand-switcher.tsx b/web/src/components/layout/brand-switcher.tsx
index 8f11bbdae..4c50b6e44 100644
--- a/web/src/components/layout/brand-switcher.tsx
+++ b/web/src/components/layout/brand-switcher.tsx
@@ -1,8 +1,9 @@
'use client';
import { useTranslations } from 'next-intl';
-import { useRouter } from '@/i18n/navigation';
+import { Link, useRouter } from '@/i18n/navigation';
import { useBrandStore } from '@/stores/use-brand-store';
+import { useUserRole } from '@/hooks/use-user-role';
import {
DropdownMenu,
DropdownMenuContent,
@@ -14,24 +15,41 @@ import {
} from '@/components/ui/dropdown-menu';
import { BrandAvatar } from '@/components/brand-avatar';
import { cn } from '@/lib/utils';
-import { Check, ChevronsUpDown, Plus } from 'lucide-react';
+import { Tooltip, TooltipContent, TooltipTrigger } from '@/components/ui/tooltip';
+import { Check, ChevronsUpDown, LayoutGrid, Plus, Settings } from 'lucide-react';
interface BrandSwitcherProps {
collapsed?: boolean;
onOpenChange?: (open: boolean) => void;
+ /** Called when it leaves for another page (the mobile menu closes then). */
+ onNavigate?: () => void;
}
-export function BrandSwitcher({ collapsed = false, onOpenChange }: BrandSwitcherProps) {
+/**
+ * The brand switcher at the top of the menu. Beside the selected brand, its
+ * settings (a separate button, so the switcher still opens on the name and
+ * the chevron); in the list, every brand to switch to, then all brands and a
+ * new one. The brands page has no menu item of its own: this is its way in.
+ */
+export function BrandSwitcher({ collapsed = false, onOpenChange, onNavigate }: BrandSwitcherProps) {
const t = useTranslations('brands');
const router = useRouter();
const { brands, activeBrandId, setActiveBrand } = useBrandStore();
+ // Only admins and managers add a brand (brands: admin/manager insert).
+ const { canManage } = useUserRole();
const activeBrand = brands.find((b) => b.id === activeBrandId) ?? null;
+ const go = (href: string) => {
+ onNavigate?.();
+ router.push(href);
+ };
+
if (brands.length === 0) {
+ if (!canManage) return null;
return (
<button
- onClick={() => router.push('/dashboard/brands/new')}
+ onClick={() => go('/dashboard/brands/new')}
className={cn(
'flex w-full items-center gap-2 rounded-md border border-dashed px-2 py-2 text-sm text-muted-foreground transition-colors hover:border-primary hover:text-primary',
collapsed && 'justify-center px-0',
@@ -45,92 +63,123 @@ export function BrandSwitcher({ collapsed = false, onOpenChange }: BrandSwitcher
}
return (
- <DropdownMenu onOpenChange={onOpenChange}>
- <DropdownMenuTrigger
- className={cn(
- 'flex w-full items-center gap-2 rounded-md px-2 py-2 text-sm transition-colors hover:bg-sidebar-accent focus-visible:outline-none',
- collapsed && 'justify-center px-0',
- )}
- aria-label={t('switchBrand')}
- >
- {activeBrand ? (
- <BrandAvatar
- logoUrl={activeBrand.logoUrl}
- name={activeBrand.name}
- domains={activeBrand.domains}
- className="h-6 w-6 shrink-0 rounded-md bg-zinc-50 dark:bg-zinc-100"
- />
- ) : (
- <span className="flex h-6 w-6 shrink-0 items-center justify-center rounded-md bg-muted text-xs font-semibold">
- ?
- </span>
- )}
-
- {!collapsed && (
- <>
- <span className="flex-1 truncate text-left text-sm font-medium">
- {activeBrand?.name ?? t('selectBrand')}
+ <div className="flex items-center gap-1">
+ <DropdownMenu onOpenChange={onOpenChange}>
+ <DropdownMenuTrigger
+ className={cn(
+ 'flex min-w-0 flex-1 items-center gap-2 rounded-md px-2 py-2 text-sm transition-colors hover:bg-sidebar-accent focus-visible:outline-none',
+ collapsed && 'justify-center px-0',
+ )}
+ aria-label={t('switchBrand')}
+ >
+ {activeBrand ? (
+ <BrandAvatar
+ logoUrl={activeBrand.logoUrl}
+ name={activeBrand.name}
+ domains={activeBrand.domains}
+ className="h-6 w-6 shrink-0 rounded-md bg-zinc-50 dark:bg-zinc-100"
+ />
+ ) : (
+ <span className="flex h-6 w-6 shrink-0 items-center justify-center rounded-md bg-muted text-xs font-semibold">
+ ?
</span>
- <ChevronsUpDown className="h-3.5 w-3.5 shrink-0 text-muted-foreground" />
- </>
- )}
- </DropdownMenuTrigger>
+ )}
+
+ {!collapsed && (
+ <>
+ <span className="flex-1 truncate text-left text-sm font-medium">
+ {activeBrand?.name ?? t('selectBrand')}
+ </span>
+ <ChevronsUpDown className="h-3.5 w-3.5 shrink-0 text-muted-foreground" />
+ </>
+ )}
+ </DropdownMenuTrigger>
- <DropdownMenuContent className="w-56" align="start" side="bottom" sideOffset={4}>
- <DropdownMenuGroup>
- <DropdownMenuLabel className="text-xs text-muted-foreground">
- {t('switchBrand')}
- </DropdownMenuLabel>
- </DropdownMenuGroup>
- <DropdownMenuSeparator />
+ <DropdownMenuContent className="w-56" align="start" side="bottom" sideOffset={4}>
+ <DropdownMenuGroup>
+ <DropdownMenuLabel className="text-xs text-muted-foreground">
+ {t('switchBrand')}
+ </DropdownMenuLabel>
+ </DropdownMenuGroup>
+ <DropdownMenuSeparator />
- {brands.map((brand) => {
- const isActive = brand.id === activeBrandId;
- const primaryDomain = brand.domains.find((d) => d.isPrimary);
+ {brands.map((brand) => {
+ const isActive = brand.id === activeBrandId;
+ const primaryDomain = brand.domains.find((d) => d.isPrimary);
- return (
+ return (
+ <DropdownMenuItem
+ key={brand.id}
+ onClick={() => setActiveBrand(brand.id)}
+ className="flex items-center gap-2"
+ >
+ <BrandAvatar
+ logoUrl={brand.logoUrl}
+ name={brand.name}
+ domains={brand.domains}
+ className="h-5 w-5 shrink-0 rounded-md bg-zinc-50 dark:bg-zinc-100"
+ fallbackClassName="rounded-md bg-primary/10 text-primary text-xs font-semibold"
+ />
+ <div className="flex-1 overflow-hidden">
+ <p className="flex items-center gap-1.5 truncate text-sm font-medium">
+ <span className="truncate">{brand.name}</span>
+ {!brand.isActive && (
+ <span className="shrink-0 rounded bg-amber-500/15 px-1 py-px text-[9px] font-medium uppercase tracking-wide text-amber-700 dark:text-amber-400">
+ Paused
+ </span>
+ )}
+ </p>
+ {primaryDomain && (
+ <p className="truncate text-xs text-muted-foreground">{primaryDomain.domain}</p>
+ )}
+ </div>
+ {isActive && <Check className="h-3.5 w-3.5 shrink-0 text-primary" />}
+ </DropdownMenuItem>
+ );
+ })}
+
+ <DropdownMenuSeparator />
+
+ <DropdownMenuItem
+ onClick={() => go('/dashboard/brands')}
+ className="flex items-center gap-2 text-muted-foreground"
+ >
+ <div className="flex h-5 w-5 shrink-0 items-center justify-center rounded-md border">
+ <LayoutGrid className="h-3 w-3" />
+ </div>
+ <span className="text-sm">{t('showAllBrands')}</span>
+ </DropdownMenuItem>
+ {canManage && (
<DropdownMenuItem
- key={brand.id}
- onClick={() => setActiveBrand(brand.id)}
- className="flex items-center gap-2"
+ onClick={() => go('/dashboard/brands/new')}
+ className="flex items-center gap-2 text-muted-foreground"
>
- <BrandAvatar
- logoUrl={brand.logoUrl}
- name={brand.name}
- domains={brand.domains}
- className="h-5 w-5 shrink-0 rounded-md bg-zinc-50 dark:bg-zinc-100"
- fallbackClassName="rounded-md bg-primary/10 text-primary text-xs font-semibold"
- />
- <div className="flex-1 overflow-hidden">
- <p className="flex items-center gap-1.5 truncate text-sm font-medium">
- <span className="truncate">{brand.name}</span>
- {!brand.isActive && (
- <span className="shrink-0 rounded bg-amber-500/15 px-1 py-px text-[9px] font-medium uppercase tracking-wide text-amber-700 dark:text-amber-400">
- Paused
- </span>
- )}
- </p>
- {primaryDomain && (
- <p className="truncate text-xs text-muted-foreground">{primaryDomain.domain}</p>
- )}
+ <div className="flex h-5 w-5 shrink-0 items-center justify-center rounded-md border">
+ <Plus className="h-3 w-3" />
</div>
- {isActive && <Check className="h-3.5 w-3.5 shrink-0 text-primary" />}
+ <span className="text-sm">{t('addBrand')}</span>
</DropdownMenuItem>
- );
- })}
-
- <DropdownMenuSeparator />
-
- <DropdownMenuItem
- onClick={() => router.push('/dashboard/brands')}
- className="flex items-center gap-2 text-muted-foreground"
- >
- <div className="flex h-5 w-5 shrink-0 items-center justify-center rounded-md border">
- <Plus className="h-3 w-3" />
- </div>
- <span className="text-sm">{t('addBrand')}</span>
- </DropdownMenuItem>
- </DropdownMenuContent>
- </DropdownMenu>
+ )}
+ </DropdownMenuContent>
+ </DropdownMenu>
+ {/* The selected brand's settings; too narrow beside the logo when collapsed. */}
+ {activeBrand && !collapsed && (
+ <Tooltip>
+ <TooltipTrigger
+ render={
+ <Link
+ href={`/dashboard/brands/${activeBrand.id}/settings`}
+ onClick={onNavigate}
+ aria-label={t('visitBrandSettings')}
+ className="flex h-7 w-7 shrink-0 items-center justify-center rounded-md text-muted-foreground transition-colors hover:bg-sidebar-accent hover:text-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring/50"
+ />
+ }
+ >
+ <Settings className="h-3.5 w-3.5" />
+ </TooltipTrigger>
+ <TooltipContent side="right">{t('visitBrandSettings')}</TooltipContent>
+ </Tooltip>
+ )}
+ </div>
);
}
diff --git a/web/src/components/layout/mobile-nav.tsx b/web/src/components/layout/mobile-nav.tsx
index af1cf9363..b445a36a1 100644
--- a/web/src/components/layout/mobile-nav.tsx
+++ b/web/src/components/layout/mobile-nav.tsx
@@ -4,6 +4,7 @@ import { useEffect, useState } from 'react';
import { useTranslations } from 'next-intl';
import { usePathname, Link } from '@/i18n/navigation';
import { dashboardNav } from '@/config/dashboard';
+import { BrandSwitcher } from '@/components/layout/brand-switcher';
import {
activeChildHref,
getDashboardNavLabel,
@@ -27,7 +28,6 @@ export function MobileNav() {
const [open, setOpen] = useState(false);
const pathname = usePathname();
const t = useTranslations('nav');
- const tBrands = useTranslations('brands');
const { canUse, requiredPlanFor, isCloud } = useFeatureGate();
// Probe once per session — shares the module-level cache with sidebar.tsx
// so at most one network request is made even when both components mount.
@@ -72,6 +72,11 @@ export function MobileNav() {
{/* Left of the sheet's close button, which sits at its top right. */}
<ThemeToggle className="ml-auto mr-8" />
</div>
+ {/* The brand switcher, as the sidebar has it: the brands page and the
+ brand's settings are reached from it. */}
+ <div className="border-b px-3 py-2">
+ <BrandSwitcher onNavigate={() => setOpen(false)} />
+ </div>
<div className="min-h-0 flex-1 overflow-y-auto">
<nav className="space-y-0.5 p-3">
{activeBrandId && (
@@ -102,7 +107,7 @@ export function MobileNav() {
item.href === '/dashboard'
? pathname === '/dashboard'
: pathname.startsWith(item.href);
- const label = getDashboardNavLabel(item.title, t, tBrands);
+ const label = getDashboardNavLabel(item.title, t);
// Dynamic badge override: show "Set up" on the Agent item
// when the org has no provider key for Chat (cloud only).
@@ -171,7 +176,7 @@ export function MobileNav() {
: 'text-muted-foreground hover:bg-accent hover:text-accent-foreground',
)}
>
- {getDashboardNavLabel(child.title, t, tBrands)}
+ {getDashboardNavLabel(child.title, t)}
{child.badge && (
<Badge
variant="secondary"
diff --git a/web/src/components/layout/sidebar.tsx b/web/src/components/layout/sidebar.tsx
index 33d5143f8..1ae4363f0 100644
--- a/web/src/components/layout/sidebar.tsx
+++ b/web/src/components/layout/sidebar.tsx
@@ -136,7 +136,6 @@ export function Sidebar() {
const [trackedCount, setTrackedCount] = useState<number | null>(null);
const activeBrandId = useBrandStore((s) => s.activeBrandId);
const t = useTranslations('nav');
- const tBrands = useTranslations('brands');
const { canUse, requiredPlanFor, isCloud } = useFeatureGate();
// Probe once per session whether the org has a provider key for Chat.
// Returns 'configured' immediately on self-host (no network call).
@@ -355,7 +354,7 @@ export function Sidebar() {
item.href === '/dashboard'
? pathname === '/dashboard'
: pathname.startsWith(item.href);
- const label = getDashboardNavLabel(item.title, t, tBrands);
+ const label = getDashboardNavLabel(item.title, t);
// Dynamic badge override: show "Set up" on the Agent item
// when the org has no provider key for Chat (cloud only).
@@ -452,7 +451,7 @@ export function Sidebar() {
)}
>
<span className="flex-1 truncate">
- {getDashboardNavLabel(child.title, t, tBrands)}
+ {getDashboardNavLabel(child.title, t)}
</span>
{child.badge && (
<Badge
diff --git a/web/src/components/onboarding/dashboard-preview.tsx b/web/src/components/onboarding/dashboard-preview.tsx
index f11866214..58117cdfa 100644
--- a/web/src/components/onboarding/dashboard-preview.tsx
+++ b/web/src/components/onboarding/dashboard-preview.tsx
@@ -49,7 +49,6 @@ export function DashboardPreview({
competitors,
}: DashboardPreviewProps) {
const t = useTranslations('nav');
- const tBrands = useTranslations('brands');
const { resolvedTheme } = useTheme();
const [mounted, setMounted] = useState(false);
useEffect(() => {
@@ -107,9 +106,7 @@ export function DashboardPreview({
)}
>
<item.icon className="h-4 w-4 shrink-0" />
- <span className="truncate">
- {getDashboardNavLabel(item.title, t, tBrands)}
- </span>
+ <span className="truncate">{getDashboardNavLabel(item.title, t)}</span>
</div>
))}
</div>
diff --git a/web/src/config/dashboard.ts b/web/src/config/dashboard.ts
index 2aa3ffef3..5da9bce95 100644
--- a/web/src/config/dashboard.ts
+++ b/web/src/config/dashboard.ts
@@ -1,6 +1,5 @@
import {
BarChart3,
- Building2,
FileBarChart,
FileText,
Gauge,
@@ -51,16 +50,11 @@ export interface NavGroup {
items: NavItem[];
}
+/**
+ * The brands page has no item here: the brand switcher above the menu opens
+ * it ("Show My All Brands") and the selected brand's settings.
+ */
export const dashboardNav: NavGroup[] = [
- {
- items: [
- {
- title: 'Brands',
- href: '/dashboard/brands',
- icon: Building2,
- },
- ],
- },
/**
* New Ansvisor: the groups name the two things the product does. Execution
* does the work (actions, the agent, content, page fixes); Analytics shows
diff --git a/web/src/lib/dashboard-navigation.test.ts b/web/src/lib/dashboard-navigation.test.ts
index c1bb49a5b..2d56aca10 100644
--- a/web/src/lib/dashboard-navigation.test.ts
+++ b/web/src/lib/dashboard-navigation.test.ts
@@ -9,7 +9,6 @@ import {
} from '@/lib/dashboard-navigation';
const translateNav = (key: string) => `nav.${key}`;
-const translateBrands = (key: string) => `brands.${key}`;
describe('getDashboardNavLabel', () => {
it('maps every dashboard item through an i18n key', () => {
@@ -20,7 +19,7 @@ describe('getDashboardNavLabel', () => {
expect(Object.keys(dashboardNavLabelKeys).sort()).toEqual([...titles].sort());
for (const title of titles) {
- expect(getDashboardNavLabel(title, translateNav, translateBrands)).not.toBe(title);
+ expect(getDashboardNavLabel(title, translateNav)).not.toBe(title);
}
});
@@ -57,13 +56,12 @@ describe('getDashboardNavLabel', () => {
]);
});
- it('uses the brands namespace only for Brands', () => {
- expect(getDashboardNavLabel('Brands', translateNav, translateBrands)).toBe('brands.title');
- expect(getDashboardNavLabel('Shopping', translateNav, translateBrands)).toBe('nav.shopping');
+ it('reads each title from the nav namespace', () => {
+ expect(getDashboardNavLabel('Shopping', translateNav)).toBe('nav.shopping');
});
it('leaves an unknown title unchanged', () => {
- expect(getDashboardNavLabel('Unknown', translateNav, translateBrands)).toBe('Unknown');
+ expect(getDashboardNavLabel('Unknown', translateNav)).toBe('Unknown');
});
});
@@ -97,15 +95,18 @@ describe('the Mentions item', () => {
// New Ansvisor: Execution (do the work) above Analytics (measure it); the
// Optimization group is gone, its items moved under Execution.
describe('the sidebar groups', () => {
- it('runs Brands, Execution, Analytics, then Reports', () => {
+ it('runs Execution, Analytics, then Reports', () => {
expect(dashboardNav.map((group) => group.title ?? null)).toEqual([
- null,
'Execution',
'Analytics',
null,
]);
- expect(dashboardNav[0].items.map((item) => item.title)).toEqual(['Brands']);
- expect(dashboardNav[3].items.map((item) => item.title)).toEqual(['Reports']);
+ expect(dashboardNav[2].items.map((item) => item.title)).toEqual(['Reports']);
+ });
+
+ it('leaves the brands page to the brand switcher', () => {
+ const hrefs = dashboardNav.flatMap((group) => group.items.map((item) => item.href));
+ expect(hrefs).not.toContain('/dashboard/brands');
});
it('puts Action Center, Chat, Content and Audit under Execution, in that order', () => {
diff --git a/web/src/lib/dashboard-navigation.ts b/web/src/lib/dashboard-navigation.ts
index 66325d373..2d87e3b4f 100644
--- a/web/src/lib/dashboard-navigation.ts
+++ b/web/src/lib/dashboard-navigation.ts
@@ -2,32 +2,29 @@ import type { BrandPrefKey, NavChild, NavItem } from '@/config/dashboard';
type Translator = (key: string) => string;
-type NavLabelKey = { namespace: 'nav'; key: string } | { namespace: 'brands'; key: 'title' };
-
/** Every dashboard title rendered from dashboardNav is resolved through this
* map. Keeping it outside either layout component prevents the desktop and
* mobile menus from silently falling out of sync. */
-export const dashboardNavLabelKeys: Record<string, NavLabelKey> = {
- Brands: { namespace: 'brands', key: 'title' },
- Chat: { namespace: 'nav', key: 'chat' },
- 'Action Center': { namespace: 'nav', key: 'actionCenter' },
- 'Answer Engine Insights': { namespace: 'nav', key: 'insights' },
- 'AI Referral Traffic': { namespace: 'nav', key: 'traffic' },
- Prompts: { namespace: 'nav', key: 'prompts' },
- 'Tracked Prompts': { namespace: 'nav', key: 'trackedPrompts' },
- 'Prompt Suggestions': { namespace: 'nav', key: 'promptSuggestions' },
- Topics: { namespace: 'nav', key: 'topics' },
- 'Query Fan-outs': { namespace: 'nav', key: 'queryFanouts' },
- 'Prompts Insights': { namespace: 'nav', key: 'promptsInsights' },
- Content: { namespace: 'nav', key: 'content' },
- Plan: { namespace: 'nav', key: 'contentPlan' },
- Opportunities: { namespace: 'nav', key: 'contentOpportunities' },
- Library: { namespace: 'nav', key: 'contentLibrary' },
- 'Site Audit': { namespace: 'nav', key: 'audit' },
- Citations: { namespace: 'nav', key: 'citations' },
- Mentions: { namespace: 'nav', key: 'mentions' },
- Shopping: { namespace: 'nav', key: 'shopping' },
- Reports: { namespace: 'nav', key: 'reports' },
+export const dashboardNavLabelKeys: Record<string, string> = {
+ Chat: 'chat',
+ 'Action Center': 'actionCenter',
+ 'Answer Engine Insights': 'insights',
+ 'AI Referral Traffic': 'traffic',
+ Prompts: 'prompts',
+ 'Tracked Prompts': 'trackedPrompts',
+ 'Prompt Suggestions': 'promptSuggestions',
+ Topics: 'topics',
+ 'Query Fan-outs': 'queryFanouts',
+ 'Prompts Insights': 'promptsInsights',
+ Content: 'content',
+ Plan: 'contentPlan',
+ Opportunities: 'contentOpportunities',
+ Library: 'contentLibrary',
+ 'Site Audit': 'audit',
+ Citations: 'citations',
+ Mentions: 'mentions',
+ Shopping: 'shopping',
+ Reports: 'reports',
};
/** Map from the static group title string in dashboard.ts to its nav key. */
@@ -43,11 +40,9 @@ export function getDashboardNavGroupLabel(title: string, t: Translator): string
return key ? t(key) : title;
}
-export function getDashboardNavLabel(title: string, t: Translator, tBrands: Translator): string {
- const label = dashboardNavLabelKeys[title];
- if (!label) return title;
-
- return label.namespace === 'brands' ? tBrands(label.key) : t(label.key);
+export function getDashboardNavLabel(title: string, t: Translator): string {
+ const key = dashboardNavLabelKeys[title];
+ return key ? t(key) : title;
}
/**