feat(admin): refactor product management components for improved state handling and data fetching
This commit is contained in:
@@ -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) {
|
||||
|
||||
Reference in New Issue
Block a user