From f72cfad5f371f7bf5396ba1a07497d1cad6fd0a3 Mon Sep 17 00:00:00 2001 From: default Date: Tue, 2 Jun 2026 04:17:50 +0000 Subject: [PATCH] Organize Brand tab by brand selection for platform admins - Added BrandSelector component showing all brands as cards - Platform admins see brand selector at top of Brand tab - Non-platform admins see only their brand's settings - Brand selection via ?brand= query param updates the page - Cards show which brand is currently selected --- src/app/admin/settings/page.tsx | 21 +++++-- src/components/admin/SettingsClient.tsx | 74 ++++++++++++++++++++++++- 2 files changed, 90 insertions(+), 5 deletions(-) diff --git a/src/app/admin/settings/page.tsx b/src/app/admin/settings/page.tsx index e3390a5..0910b8f 100644 --- a/src/app/admin/settings/page.tsx +++ b/src/app/admin/settings/page.tsx @@ -9,18 +9,31 @@ export const metadata = { description: "Manage your brand settings, workers, tasks, and user permissions", }; -export default async function AdminSettingsPage() { +export default async function AdminSettingsPage({ + searchParams, +}: { + searchParams: Promise<{ brand?: string }>; +}) { const adminUser = await getAdminUser(); if (!adminUser) redirect("/login"); - const brandId = adminUser.brand_id ?? "64294306-5f42-463d-a5e8-2ad6c81a96de"; + const params = await searchParams; + const isPlatformAdmin = adminUser.role === "platform_admin"; + + // Platform admin can select a brand via query param, otherwise use their assigned brand + let brandId = adminUser.brand_id ?? ""; + if (isPlatformAdmin && params.brand) { + brandId = params.brand; + } else if (!brandId) { + brandId = "64294306-5f42-463d-a5e8-2ad6c81a96de"; + } const [{ users, error }, { brands }] = await Promise.all([ - getAdminUsers(adminUser.role === "platform_admin" ? undefined : (adminUser.brand_id ?? undefined)), + getAdminUsers(isPlatformAdmin ? undefined : (adminUser.brand_id ?? undefined)), getBrands(), ]); - // Fetch payment settings for the brand tab + // Fetch payment settings for the current brand const paymentResult = await getPaymentSettings(brandId); const paymentSettings = paymentResult.success ? paymentResult.settings : null; diff --git a/src/components/admin/SettingsClient.tsx b/src/components/admin/SettingsClient.tsx index 8ea2b13..1d7676c 100644 --- a/src/components/admin/SettingsClient.tsx +++ b/src/components/admin/SettingsClient.tsx @@ -58,6 +58,53 @@ const Icons = { type Brand = { id: string; name: string }; +// Brand Selector Component +function BrandSelector({ + brands, + selectedBrandId, + onSelect, +}: { + brands: Brand[]; + selectedBrandId: string; + onSelect: (id: string) => void; +}) { + return ( +
+

Select which brand's settings to manage:

+
+ {brands.map((brand) => ( + + ))} +
+
+ ); +} + type Props = { brandId: string; users: import("@/actions/admin/users").AdminUserRow[]; @@ -151,7 +198,32 @@ export default function SettingsClient({ {activeTab === "brand" && (
- {/* Brand Settings */} + {currentUser.role === "platform_admin" && brands.length > 0 && ( +
+
+
+
+ {Icons.brand("w-4 h-4 text-white")} +
+
+

Select Brand

+

Choose a brand to view and edit its settings

+
+
+
+
+ { + window.location.href = `/admin/settings?brand=${id}#brand`; + }} + /> +
+
+ )} + + {/* Selected Brand Settings */}