From 638d1dad5262b05c4882ef7c6a4807300dfdf662 Mon Sep 17 00:00:00 2001 From: Amirmahdi Nourkazemi Date: Sat, 27 Jun 2026 10:28:37 +0330 Subject: [PATCH] fix --- app/dashboard/categories/page.tsx | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/app/dashboard/categories/page.tsx b/app/dashboard/categories/page.tsx index 94d5103..ef5dc64 100644 --- a/app/dashboard/categories/page.tsx +++ b/app/dashboard/categories/page.tsx @@ -88,7 +88,19 @@ export default function CategoriesPage() { e.preventDefault(); setSaving(true); try { - if (editing) { + // Playlist categories live in the music_categories table, so their writes + // go to /music-categories (image is the `image` field, not `icon`). + const targetType = editing ? editing.type : type; + if (targetType === "playlist") { + const body = toFormData({ name, description, order, image: icon }); + if (editing) { + await apiFetch(`/music-categories/${editing.id}`, { method: "POST", body }); + toast.success("دسته‌بندی ویرایش شد."); + } else { + await apiFetch("/music-categories", { method: "POST", body }); + toast.success("دسته‌بندی افزوده شد."); + } + } else if (editing) { // Icon is a file, so update goes through POST + Laravel method spoofing. const body = toFormData({ _method: "PUT", @@ -120,7 +132,11 @@ export default function CategoriesPage() { if (!deleting) return; setRemoving(true); try { - await apiFetch(`/categories/${deleting.id}`, { method: "DELETE" }); + const path = + deleting.type === "playlist" + ? `/music-categories/${deleting.id}` + : `/categories/${deleting.id}`; + await apiFetch(path, { method: "DELETE" }); toast.success("دسته‌بندی حذف شد."); setDeleting(null); reload();