diff --git a/src/app/admin/stops/page.tsx b/src/app/admin/stops/page.tsx index a76ed3e..1534468 100644 --- a/src/app/admin/stops/page.tsx +++ b/src/app/admin/stops/page.tsx @@ -1,5 +1,6 @@ import { pool } from "@/lib/db"; import { getAdminUser } from "@/lib/admin-permissions"; +import { getActiveBrandId } from "@/lib/brand-scope"; import AdminAccessDenied from "@/components/admin/AdminAccessDenied"; import { PageHeader } from "@/components/admin/design-system"; import { redirect } from "next/navigation"; @@ -26,11 +27,18 @@ export default async function AdminStopsPage({ searchParams }: PageProps) { let error: string | null = null; let totalCount = 0; + // Resolve active brand from cookie/URL (respects platform_admin "All brands" = null) + let activeBrandId: string | null = null; try { - // Platform admin sees all stops, brand admin sees their brand's stops - const brandCondition = adminUser.brand_id - ? `brand_id = '${adminUser.brand_id}'` - : "1=1"; + activeBrandId = await getActiveBrandId(adminUser); + + // If brand-scoped (not platform_admin) and no active brand, restrict query + const brandCondition = + activeBrandId + ? `brand_id = '${activeBrandId}'` + : adminUser.role === "platform_admin" + ? "1=1" + : `brand_id IN ('${(adminUser.brand_ids ?? []).join("','")}')`; const countResult = await pool.query<{ count: string }>( `SELECT count(*) as count FROM stops WHERE ${brandCondition}` @@ -104,9 +112,9 @@ export default async function AdminStopsPage({ searchParams }: PageProps) {
- {adminUser.brand_id - ? "No stops for your brand yet. Upload a schedule or add stops manually." - : "No stops in the database. Import the Tuxedo Tour schedule."} + {activeBrandId + ? "No stops for the selected brand. Upload a schedule or add stops manually." + : "No stops in the database."}