fix(admin): show error toast instead of success when savePost fails
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:
@@ -2103,8 +2103,10 @@ async function savePost(){
|
|||||||
categoryId:catId?parseInt(catId):null,
|
categoryId:catId?parseInt(catId):null,
|
||||||
ogImage:document.getElementById('post-image').value,
|
ogImage:document.getElementById('post-image').value,
|
||||||
};
|
};
|
||||||
if(id) await api(`/api/blog/posts/${id}`,{method:'PUT',body:JSON.stringify(body)});
|
const res = id
|
||||||
else await api('/api/blog/posts',{method:'POST',body:JSON.stringify(body)});
|
? 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();
|
closeModal('postModal'); toast('مقاله ذخیره شد ✓'); loadPosts();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user