fix(admin): show error toast instead of success when savePost fails
CI/CD / CI · dotnet build (push) Successful in 1m34s
CI/CD / Deploy · drsousan (push) Successful in 31s

api() returns null on HTTP error; the save block now checks the return
value before closing the modal and showing the success toast.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
soroush.asadi
2026-06-10 22:11:20 +03:30
parent e6fe943217
commit 21769deda6
+4 -2
View File
@@ -2103,8 +2103,10 @@ async function savePost(){
categoryId:catId?parseInt(catId):null,
ogImage:document.getElementById('post-image').value,
};
if(id) await api(`/api/blog/posts/${id}`,{method:'PUT',body:JSON.stringify(body)});
else await api('/api/blog/posts',{method:'POST',body:JSON.stringify(body)});
const res = id
? await api(`/api/blog/posts/${id}`,{method:'PUT',body:JSON.stringify(body)})
: await api('/api/blog/posts',{method:'POST',body:JSON.stringify(body)});
if(res === null && id) return; // api() already showed error toast
closeModal('postModal'); toast('مقاله ذخیره شد ✓'); loadPosts();
}