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(brands): let managers turn Shopping mode on and off (#1211)

Cihane7b44cd67e35
diff --git a/web/messages/en.json b/web/messages/en.json
index 84c26e5d6..4810352f1 100644
--- a/web/messages/en.json
+++ b/web/messages/en.json
@@ -4475,6 +4475,17 @@
"confirmDelete": "Type the brand name to confirm:",
"deleteConfirmPlaceholder": "Brand name",
"deleteButton": "Delete Brand Permanently",
+ "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 reveal the Shopping dashboard.",
+ "label": "This brand is in e-commerce / shopping",
+ "help": "Adds <code>chatgpt-shopping</code> to every existing prompt's platform list and enables the Shopping platform on this brand.",
+ "managersOnly": "Only admins and managers can change this setting.",
+ "on": "Shopping mode on",
+ "onWithPrompts": "Shopping mode on: {count, plural, one {# prompt} other {# prompts}} updated",
+ "off": "Shopping mode off",
+ "saveFailed": "Couldn't save Shopping mode"
+ },
"aiModels": {
"description": "Configure which AI platforms to monitor and how often prompts should be checked for this brand.",
"platformsActive": "platforms active",
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 829c60008..ec0e7ec26 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
@@ -33,7 +33,10 @@ const translations: Record<string, string> = {
};
vi.mock('next-intl', () => ({
- useTranslations: () => (key: string) => translations[key] ?? key,
+ useTranslations: () =>
+ Object.assign((key: string) => translations[key] ?? key, {
+ rich: (key: string) => translations[key] ?? key,
+ }),
}));
vi.mock('@/i18n/navigation', () => ({
@@ -49,14 +52,16 @@ vi.mock('@/stores/use-brand-store', () => ({
}),
}));
+const role = vi.hoisted(() => ({ canAdmin: true, canManage: true }));
vi.mock('@/hooks/use-user-role', () => ({
- useUserRole: () => ({ canAdmin: true }),
+ useUserRole: () => role,
}));
+const setBrandShoppingMode = vi.hoisted(() => vi.fn());
vi.mock('@/lib/actions/brand', () => ({
deleteBrand: vi.fn(),
setBrandActive: vi.fn(),
- setBrandShoppingMode: vi.fn(),
+ setBrandShoppingMode,
updateBrand: vi.fn(),
}));
@@ -85,6 +90,8 @@ import BrandSettingsPage from './page';
afterEach(() => {
brand.state = 'CA';
+ Object.assign(role, { canAdmin: true, canManage: true });
+ setBrandShoppingMode.mockReset();
document.body.replaceChildren();
vi.restoreAllMocks();
});
@@ -140,3 +147,45 @@ describe('brand settings location selects', () => {
await act(async () => root.unmount());
});
});
+
+describe('brand settings Shopping mode', () => {
+ 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 checkbox = container.querySelector('#shopping-mode') as HTMLElement;
+ return { container, root, checkbox };
+ }
+
+ it('lets a manager turn it on, as the brand and prompt writes allow', async () => {
+ Object.assign(role, { canAdmin: false, canManage: true });
+ setBrandShoppingMode.mockResolvedValue({ promptsUpdated: 3 });
+ const { container, root, checkbox } = await render();
+
+ expect(checkbox.hasAttribute('data-disabled')).toBe(false);
+ expect(container.textContent).not.toContain('settings.shopping.managersOnly');
+ await act(async () => checkbox.click());
+ expect(setBrandShoppingMode).toHaveBeenCalledWith(brand.id, true);
+
+ await act(async () => root.unmount());
+ });
+
+ it('shows anyone else the setting without letting them change it', async () => {
+ Object.assign(role, { canAdmin: false, canManage: false });
+ const { container, root, checkbox } = await render();
+
+ expect(checkbox.hasAttribute('data-disabled')).toBe(true);
+ expect(container.textContent).toContain('settings.shopping.managersOnly');
+ await act(async () => checkbox.click());
+ expect(setBrandShoppingMode).not.toHaveBeenCalled();
+
+ 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 96c0d6d71..55e140cbf 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
@@ -322,12 +322,14 @@ function ShoppingModeCard({
brand: Brand;
onUpdate: (updates: Partial<Brand>) => void;
}) {
- const { canAdmin } = useUserRole();
+ const t = useTranslations('brands');
+ // Admins and managers, as the brands, prompts and brand_platforms writes allow.
+ const { canManage } = useUserRole();
const [enabled, setEnabled] = useState(brand.shoppingModeEnabled);
const [saving, setSaving] = useState(false);
async function handleToggle(next: boolean) {
- if (!canAdmin) return;
+ if (!canManage) return;
const previous = enabled;
setEnabled(next);
setSaving(true);
@@ -335,13 +337,13 @@ function ShoppingModeCard({
const { promptsUpdated } = await setBrandShoppingMode(brand.id, next);
onUpdate({ shoppingModeEnabled: next });
if (next && promptsUpdated > 0) {
- toast.success(`Shopping mode on — ${promptsUpdated} prompt(s) updated`);
+ toast.success(t('settings.shopping.onWithPrompts', { count: promptsUpdated }));
} else {
- toast.success(next ? 'Shopping mode on' : 'Shopping mode off');
+ toast.success(next ? t('settings.shopping.on') : t('settings.shopping.off'));
}
} catch (err) {
setEnabled(previous);
- toast.error(err instanceof Error ? err.message : 'Failed to save');
+ toast.error(err instanceof Error ? err.message : t('settings.shopping.saveFailed'));
} finally {
setSaving(false);
}
@@ -352,33 +354,31 @@ function ShoppingModeCard({
<CardHeader>
<CardTitle className="flex items-center gap-2">
<ShoppingBag className="h-4 w-4" />
- Shopping mode
+ {t('settings.shopping.title')}
</CardTitle>
- <CardDescription>
- Turn this on if this brand is in e-commerce. We&rsquo;ll add ChatGPT Shopping to every
- prompt under this brand and reveal the Shopping dashboard.
- </CardDescription>
+ <CardDescription>{t('settings.shopping.description')}</CardDescription>
</CardHeader>
<CardContent>
<div className="flex items-start gap-3">
<Checkbox
id="shopping-mode"
checked={enabled}
- disabled={saving || !canAdmin}
+ disabled={saving || !canManage}
onCheckedChange={(v) => handleToggle(v === true)}
/>
<div className="space-y-1">
<Label htmlFor="shopping-mode" className="font-medium">
- This brand is in e-commerce / shopping
+ {t('settings.shopping.label')}
</Label>
<p className="text-xs text-muted-foreground">
- Adds{' '}
- <code className="rounded bg-muted px-1 py-0.5 text-[11px]">chatgpt-shopping</code> to
- every existing prompt&apos;s platform list and enables the Shopping platform on this
- brand.
+ {t.rich('settings.shopping.help', {
+ code: (chunks) => (
+ <code className="rounded bg-muted px-1 py-0.5 text-[11px]">{chunks}</code>
+ ),
+ })}
</p>
- {!canAdmin && (
- <p className="text-xs text-muted-foreground">Only admins can change this setting.</p>
+ {!canManage && (
+ <p className="text-xs text-muted-foreground">{t('settings.shopping.managersOnly')}</p>
)}
</div>
{saving && <Loader2 className="ml-auto h-4 w-4 animate-spin text-muted-foreground" />}