feat(admin): refactor product management components for improved state handling and data fetching

This commit is contained in:
Nils-Johan Gynther
2026-04-19 18:22:43 +02:00
parent f12d881395
commit e9b5de4407
5 changed files with 57 additions and 28 deletions
+10
View File
@@ -97,6 +97,8 @@ export async function updateProductWithTags(formData: FormData, tags: string[])
throw new Error(`Kunde inte uppdatera produkt: ${text}`);
}
const updatedProduct = await res.json();
const tagsRes = await fetch(`${API_BASE}/api/products/${id}/tags`, {
method: 'PUT',
headers: { 'Content-Type': 'application/json', ...authHeaders },
@@ -108,6 +110,14 @@ export async function updateProductWithTags(formData: FormData, tags: string[])
const text = await tagsRes.text();
throw new Error(`Kunde inte uppdatera taggar: ${text}`);
}
// Fetch the complete product (includes tags, categoryRef) after both updates
const fullRes = await fetch(`${API_BASE}/api/products/${id}`, {
headers: authHeaders,
cache: 'no-store',
});
if (!fullRes.ok) return updatedProduct;
return fullRes.json();
}
export async function deleteProduct(id: number) {