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
fix(sidebar): gate Shopping entry by active brand, not org-wide (#170) (#173)
Gökhan Geyik128a999ceb26
diff --git a/web/src/app/[locale]/(dashboard)/layout.tsx b/web/src/app/[locale]/(dashboard)/layout.tsxindex 3da90bf34..f786dca98 100644--- a/web/src/app/[locale]/(dashboard)/layout.tsx+++ b/web/src/app/[locale]/(dashboard)/layout.tsx@@ -51,16 +51,12 @@ export default async function DashboardLayout({ children }: { children: React.Re}const planId = (org?.plan ?? 'starter') as PlanId;- // Sidebar reveals the Shopping entry when at least one brand has Shopping- // mode on (#155). Org-wide signal, derived from the brand list we already- // fetch here.- const shoppingModeEnabled = brands.some((b) => b.shoppingModeEnabled);return (<><AuthProvider user={user} /><BrandLoader brands={brands} />- <PlanProvider planId={planId} shoppingModeEnabled={shoppingModeEnabled}>+ <PlanProvider planId={planId}><RoleProvider role={role}><div className="flex h-screen overflow-hidden">{/* Desktop sidebar */}diff --git a/web/src/components/layout/sidebar.tsx b/web/src/components/layout/sidebar.tsxindex 66907d6ba..e256400ef 100644--- a/web/src/components/layout/sidebar.tsx+++ b/web/src/components/layout/sidebar.tsx@@ -7,8 +7,8 @@ import { useTranslations } from 'next-intl';import { usePathname, Link } from '@/i18n/navigation';import { dashboardNav } from '@/config/dashboard';import { useSidebarStore } from '@/stores/use-sidebar-store';+import { useBrandStore } from '@/stores/use-brand-store';import { useFeatureGate } from '@/hooks/use-feature-gate';-import { usePlanContext } from '@/components/providers/plan-provider';import { siteConfig } from '@/config/site';import { cn } from '@/lib/utils';import { Button } from '@/components/ui/button';@@ -25,11 +25,14 @@ export function Sidebar() {const t = useTranslations('nav');const tBrands = useTranslations('brands');const { canUse, requiredPlanFor, isCloud } = useFeatureGate();- const { shoppingModeEnabled } = usePlanContext();- // Map from a NavItem.requiresOrgPref key to its current value. Sidebar- // hides the item entirely when this returns false — see #155 for why- // Shopping uses this on top of the existing plan-feature gate.- const orgPrefs = { shoppingModeEnabled };+ // Brand-scoped gates follow the active brand, not the org. Selecting the+ // derived brand keeps this reactive: switching brands via BrandSwitcher or+ // toggling the flag in Brand Settings flips the gate without a route change.+ const activeBrand = useBrandStore((s) => s.brands.find((b) => b.id === s.activeBrandId) ?? null);+ // Map from a NavItem.requiresBrandPref key to the active brand's value.+ // Sidebar hides the item entirely when this returns false — see #155/#170+ // for why Shopping uses this on top of the existing plan-feature gate.+ const brandPrefs = { shoppingModeEnabled: !!activeBrand?.shoppingModeEnabled };const { resolvedTheme } = useTheme();const [mounted, setMounted] = useState(false);// Hydration guard: SSR can't know the resolved theme, so we render the@@ -100,10 +103,10 @@ export function Sidebar() {{group.title && isCollapsed && i > 0 && <Separator className="my-2" />}<nav className="space-y-0.5">{group.items.map((item) => {- // Hide entirely if a required org preference is off — the- // user shouldn't see "Shopping (upgrade)" when they're- // simply not in e-commerce.- if (item.requiresOrgPref && !orgPrefs[item.requiresOrgPref]) {+ // Hide entirely if a required brand preference is off — the+ // user shouldn't see "Shopping (upgrade)" when the active+ // brand simply isn't in e-commerce.+ if (item.requiresBrandPref && !brandPrefs[item.requiresBrandPref]) {return null;}diff --git a/web/src/components/providers/plan-provider.tsx b/web/src/components/providers/plan-provider.tsxindex dc904bd67..5cea25843 100644--- a/web/src/components/providers/plan-provider.tsx+++ b/web/src/components/providers/plan-provider.tsx@@ -6,29 +6,19 @@ import type { PlanId } from '@/config/plans';interface PlanContextValue {planId: PlanId;isCloud: boolean;- shoppingModeEnabled: boolean;}const PlanContext = createContext<PlanContextValue>({planId: 'self_hosted',isCloud: false,- shoppingModeEnabled: false,});-export function PlanProvider({- planId,- shoppingModeEnabled,- children,-}: {- planId: PlanId;- shoppingModeEnabled: boolean;- children: React.ReactNode;-}) {+export function PlanProvider({ planId, children }: { planId: PlanId; children: React.ReactNode }) {const isCloud = process.env.NEXT_PUBLIC_IS_CLOUD === 'true';const effectivePlan: PlanId = isCloud ? planId : 'self_hosted';return (- <PlanContext.Provider value={{ planId: effectivePlan, isCloud, shoppingModeEnabled }}>+ <PlanContext.Provider value={{ planId: effectivePlan, isCloud }}>{children}</PlanContext.Provider>);diff --git a/web/src/config/dashboard.ts b/web/src/config/dashboard.tsindex 5a5e6ac6d..e7aeba0c3 100644--- a/web/src/config/dashboard.ts+++ b/web/src/config/dashboard.ts@@ -13,14 +13,14 @@ import {import type { Feature } from '@/config/plans';/**- * An org-level preference that, when present on a NavItem, must be `true`- * for the item to render at all. Distinct from plan-level `requiredFeature`- * which downgrades the item to a locked/disabled state when the plan- * doesn't include it — `requiresOrgPref` hides the item entirely so it- * doesn't appear as a "you could have this if you paid more" hint when the- * relevant org isn't supposed to see Shopping in the first place.+ * A brand-level preference that, when present on a NavItem, must be `true`+ * on the active brand for the item to render at all. Distinct from plan-level+ * `requiredFeature` which downgrades the item to a locked/disabled state when+ * the plan doesn't include it — `requiresBrandPref` hides the item entirely so+ * it doesn't appear as a "you could have this if you paid more" hint when the+ * active brand isn't supposed to see Shopping in the first place.*/-export type OrgPrefKey = 'shoppingModeEnabled';+export type BrandPrefKey = 'shoppingModeEnabled';export interface NavItem {title: string;@@ -29,7 +29,7 @@ export interface NavItem {badge?: string;disabled?: boolean;requiredFeature?: Feature;- requiresOrgPref?: OrgPrefKey;+ requiresBrandPref?: BrandPrefKey;}export interface NavGroup {@@ -82,7 +82,7 @@ export const dashboardNav: NavGroup[] = [href: '/dashboard/shopping',icon: ShoppingBag,requiredFeature: 'shopping_analytics',- requiresOrgPref: 'shoppingModeEnabled',+ requiresBrandPref: 'shoppingModeEnabled',},{title: 'AI Traffic Analytics',