diff --git a/admin-next/src/components/catalog/catalog-page.tsx b/admin-next/src/components/catalog/catalog-page.tsx index 99c3844..c36928b 100755 --- a/admin-next/src/components/catalog/catalog-page.tsx +++ b/admin-next/src/components/catalog/catalog-page.tsx @@ -341,9 +341,18 @@ export function CatalogPage() { }; // ─── Tree node actions ───────────────────────── + // Маппинг type → API path (category → categories, subcategory → subcategories) + const typeToPath = (type: string) => { + if (type === "category") return "categories"; + if (type === "subcategory") return "subcategories"; + if (type === "location") return "locations"; + if (type === "product") return "products"; + return `${type}s`; + }; + const handleToggleActive = async (type: string, id: number) => { try { - const res = await fetch(`/api/${type}s/${id}`, { method: "PATCH" }); + const res = await fetch(`/api/${typeToPath(type)}/${id}`, { method: "PATCH" }); if (!res.ok) throw new Error(); toast.success(`${type} toggled`); fetchTree(); @@ -386,7 +395,7 @@ export function CatalogPage() { await handleCityDelete(country, city); return; } - const typePath = deleteTarget.type === "product" ? "products" : `${deleteTarget.type}s`; + const typePath = deleteTarget.type === "product" ? "products" : typeToPath(deleteTarget.type); const res = await fetch(`/api/${typePath}/${deleteTarget.id}`, { method: "DELETE" }); if (!res.ok) { const data = await res.json(); @@ -490,7 +499,7 @@ export function CatalogPage() { } } else { const body = { name: renameValue.trim() }; - const typePath = `${type}s`; + const typePath = typeToPath(type); const res = await fetch(`/api/${typePath}/${id}`, { method: "PUT", headers: { "Content-Type": "application/json" }, body: JSON.stringify(body), }); @@ -506,7 +515,7 @@ export function CatalogPage() { const handleSort = async (type: string, id: number, direction: "up" | "down") => { try { - const res = await fetch(`/api/${type}s/${id}/sort`, { + const res = await fetch(`/api/${typeToPath(type)}/${id}/sort`, { method: "PATCH", headers: { "Content-Type": "application/json" }, body: JSON.stringify({ direction }),