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.
This commit is contained in:
2026-06-04 17:18:02 +00:00
parent 63842a9efc
commit df6f4181df
+6 -3
View File
@@ -245,7 +245,10 @@ export default function ProductsClient({ products, brandId }: { products: Produc
} }
try { 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"); setError("Brand ID is required");
setSaving(false); setSaving(false);
setIsLoading(false); setIsLoading(false);
@@ -256,7 +259,7 @@ export default function ProductsClient({ products, brandId }: { products: Produc
const imageUrl = pendingImageUrl || formData.image_url || null; const imageUrl = pendingImageUrl || formData.image_url || null;
if (editingProduct) { if (editingProduct) {
result = await updateProduct(editingProduct.id, brandId, { result = await updateProduct(editingProduct.id, effectiveBrandId, {
name: formData.name.trim(), name: formData.name.trim(),
description: formData.description.trim(), description: formData.description.trim(),
price, price,
@@ -266,7 +269,7 @@ export default function ProductsClient({ products, brandId }: { products: Produc
is_taxable: formData.is_taxable, is_taxable: formData.is_taxable,
}); });
} else { } else {
result = await createProduct(brandId, { result = await createProduct(effectiveBrandId, {
name: formData.name.trim(), name: formData.name.trim(),
description: formData.description.trim(), description: formData.description.trim(),
price, price,