Support paginated REST framework product, order, and return list structures in frontend state
This commit is contained in:
parent
6e5e175689
commit
8fc514bc45
1 changed files with 9 additions and 1 deletions
10
src/App.tsx
10
src/App.tsx
|
|
@ -199,6 +199,7 @@ export default function App() {
|
|||
.then(res => res.json())
|
||||
.then(data => {
|
||||
if (Array.isArray(data)) setProducts(data);
|
||||
else if (data && Array.isArray(data.results)) setProducts(data.results);
|
||||
})
|
||||
.catch(err => console.error('Error fetching products:', err));
|
||||
|
||||
|
|
@ -207,6 +208,7 @@ export default function App() {
|
|||
.then(res => res.json())
|
||||
.then(data => {
|
||||
if (Array.isArray(data)) setOrders(data);
|
||||
else if (data && Array.isArray(data.results)) setOrders(data.results);
|
||||
})
|
||||
.catch(err => console.error('Error fetching orders:', err));
|
||||
|
||||
|
|
@ -215,6 +217,7 @@ export default function App() {
|
|||
.then(res => res.json())
|
||||
.then(data => {
|
||||
if (Array.isArray(data)) setReturns(data);
|
||||
else if (data && Array.isArray(data.results)) setReturns(data.results);
|
||||
})
|
||||
.catch(err => console.error('Error fetching returns:', err));
|
||||
|
||||
|
|
@ -600,7 +603,10 @@ export default function App() {
|
|||
// Refresh products from backend
|
||||
apiFetch(`${CONFIG.apiBaseUrl}/api/products/`)
|
||||
.then(r => r.json())
|
||||
.then(prods => setProducts(prods))
|
||||
.then(prods => {
|
||||
if (Array.isArray(prods)) setProducts(prods);
|
||||
else if (prods && Array.isArray(prods.results)) setProducts(prods.results);
|
||||
})
|
||||
setIsEditingProduct(false)
|
||||
alert(isEditingProduct ? 'Product modified successfully!' : 'Product uploaded successfully!')
|
||||
})
|
||||
|
|
@ -668,6 +674,8 @@ export default function App() {
|
|||
const prods = await prodRes.json();
|
||||
if (Array.isArray(prods)) {
|
||||
setProducts(prods);
|
||||
} else if (prods && Array.isArray(prods.results)) {
|
||||
setProducts(prods.results);
|
||||
}
|
||||
setBulkCsvFile(null);
|
||||
setBulkZipFile(null);
|
||||
|
|
|
|||
Loading…
Reference in a new issue