From df6f4181dfb79a013aac2b1c11a56d148fe88cf0 Mon Sep 17 00:00:00 2001 From: default Date: Thu, 4 Jun 2026 17:18:02 +0000 Subject: [PATCH] fix(products): fall back to product's brand_id in edit modal When a platform_admin (no brand_id assigned) opens the Edit Product modal, the page-level brandId prop is undefined and handleSubmit was erroring with 'Brand ID is required'. The product record itself carries brand_id, so use it as a fallback before bailing out. --- src/components/admin/ProductsClient.tsx | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/src/components/admin/ProductsClient.tsx b/src/components/admin/ProductsClient.tsx index dc9e2eb..778f73a 100644 --- a/src/components/admin/ProductsClient.tsx +++ b/src/components/admin/ProductsClient.tsx @@ -245,7 +245,10 @@ export default function ProductsClient({ products, brandId }: { products: Produc } try { - if (!brandId) { + // For edits, fall back to the product's own brand_id (platform_admins + // don't have a brand_id, but the product record always knows its brand). + const effectiveBrandId = brandId ?? editingProduct?.brand_id; + if (!effectiveBrandId) { setError("Brand ID is required"); setSaving(false); setIsLoading(false); @@ -256,7 +259,7 @@ export default function ProductsClient({ products, brandId }: { products: Produc const imageUrl = pendingImageUrl || formData.image_url || null; if (editingProduct) { - result = await updateProduct(editingProduct.id, brandId, { + result = await updateProduct(editingProduct.id, effectiveBrandId, { name: formData.name.trim(), description: formData.description.trim(), price, @@ -266,7 +269,7 @@ export default function ProductsClient({ products, brandId }: { products: Produc is_taxable: formData.is_taxable, }); } else { - result = await createProduct(brandId, { + result = await createProduct(effectiveBrandId, { name: formData.name.trim(), description: formData.description.trim(), price,