From be952509a102bd8db1e85175e3aad7cb5d6e8bdd Mon Sep 17 00:00:00 2001 From: NotII <46204250+NotII@users.noreply.github.com> Date: Tue, 23 Sep 2025 22:41:27 +0100 Subject: [PATCH] Improve ProductSelector response handling and UI Enhanced the ProductSelector to robustly handle different response shapes from the products API, preventing runtime errors. Also adjusted dropdown and scroll area sizing for better UI consistency. --- .../dashboard/promotions/ProductSelector.tsx | 16 ++++++++++++---- public/git-info.json | 4 ++-- 2 files changed, 14 insertions(+), 6 deletions(-) diff --git a/components/dashboard/promotions/ProductSelector.tsx b/components/dashboard/promotions/ProductSelector.tsx index a0e4422..27bc2b2 100644 --- a/components/dashboard/promotions/ProductSelector.tsx +++ b/components/dashboard/promotions/ProductSelector.tsx @@ -50,7 +50,15 @@ export default function ProductSelector({ setLoading(true); try { const response = await fetchClient('/promotions/products/all'); - setProducts(response); + // Ensure we only set an array to state to avoid runtime errors + if (Array.isArray(response)) { + setProducts(response); + } else if (response && Array.isArray((response as any).products)) { + setProducts((response as any).products); + } else { + console.error('Unexpected products response shape:', response); + setProducts([]); + } } catch (error) { console.error('Error fetching products:', error); } finally { @@ -119,8 +127,8 @@ export default function ProductSelector({ {/* Dropdown using absolute positioning within relative container */} {open && (