Merge pull request #26 from rede5/codex/fix-typeerror-for-undefined-properties
Handle missing arrays in marketplace API responses
This commit is contained in:
commit
d79e2ffee0
2 changed files with 11 additions and 3 deletions
|
|
@ -33,8 +33,9 @@ const ProductSearch = () => {
|
||||||
page: 1,
|
page: 1,
|
||||||
page_size: 50,
|
page_size: 50,
|
||||||
})
|
})
|
||||||
setProducts(data.products)
|
const safeProducts = Array.isArray(data.products) ? data.products : []
|
||||||
setTotal(data.total)
|
setProducts(safeProducts)
|
||||||
|
setTotal(typeof data.total === 'number' ? data.total : safeProducts.length)
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
console.error('Failed to fetch products', err)
|
console.error('Failed to fetch products', err)
|
||||||
} finally {
|
} finally {
|
||||||
|
|
|
||||||
|
|
@ -32,7 +32,14 @@ export function SellerDashboardPage() {
|
||||||
try {
|
try {
|
||||||
setLoading(true)
|
setLoading(true)
|
||||||
const response = await apiClient.get('/v1/dashboard/seller')
|
const response = await apiClient.get('/v1/dashboard/seller')
|
||||||
setData(response.data)
|
const payload = response.data ?? {}
|
||||||
|
setData({
|
||||||
|
seller_id: payload.seller_id ?? '',
|
||||||
|
total_sales_cents: payload.total_sales_cents ?? 0,
|
||||||
|
orders_count: payload.orders_count ?? 0,
|
||||||
|
top_products: Array.isArray(payload.top_products) ? payload.top_products : [],
|
||||||
|
low_stock_alerts: Array.isArray(payload.low_stock_alerts) ? payload.low_stock_alerts : []
|
||||||
|
})
|
||||||
setError(null)
|
setError(null)
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
setError('Erro ao carregar dashboard')
|
setError('Erro ao carregar dashboard')
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue