fix(board): handle submit errors + tolerate tag fetch failure
This commit is contained in:
parent
c06cdd71fd
commit
5bdc3244bd
1 changed files with 15 additions and 6 deletions
|
|
@ -93,6 +93,7 @@ definePageMeta({ middleware: ['members-auth'] })
|
|||
const { memberData } = useAuth()
|
||||
const { posts, loading, fetchPosts, createPost, updatePost, deletePost } = useBoardPosts()
|
||||
const { channels, fetchChannels } = useBoardChannels()
|
||||
const toast = useToast()
|
||||
|
||||
const cooperativeTags = ref([])
|
||||
const showTagsDrawer = ref(false)
|
||||
|
|
@ -150,12 +151,20 @@ const handleDelete = async (post) => {
|
|||
}
|
||||
|
||||
const handleSubmit = async (body) => {
|
||||
if (editingPost.value) {
|
||||
await updatePost(editingPost.value._id, body)
|
||||
} else {
|
||||
await createPost(body)
|
||||
try {
|
||||
if (editingPost.value) {
|
||||
await updatePost(editingPost.value._id, body)
|
||||
} else {
|
||||
await createPost(body)
|
||||
}
|
||||
closeForm()
|
||||
} catch (err) {
|
||||
toast.add({
|
||||
title: editingPost.value ? 'Failed to update post' : 'Failed to create post',
|
||||
description: err?.data?.message || err?.message || 'Please try again.',
|
||||
color: 'red',
|
||||
})
|
||||
}
|
||||
closeForm()
|
||||
}
|
||||
|
||||
const loadTags = async () => {
|
||||
|
|
@ -174,7 +183,7 @@ useHead({
|
|||
})
|
||||
|
||||
onMounted(async () => {
|
||||
await Promise.all([loadTags(), fetchPosts(), fetchChannels()])
|
||||
await Promise.allSettled([loadTags(), fetchPosts(), fetchChannels()])
|
||||
})
|
||||
</script>
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue