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 { memberData } = useAuth()
|
||||||
const { posts, loading, fetchPosts, createPost, updatePost, deletePost } = useBoardPosts()
|
const { posts, loading, fetchPosts, createPost, updatePost, deletePost } = useBoardPosts()
|
||||||
const { channels, fetchChannels } = useBoardChannels()
|
const { channels, fetchChannels } = useBoardChannels()
|
||||||
|
const toast = useToast()
|
||||||
|
|
||||||
const cooperativeTags = ref([])
|
const cooperativeTags = ref([])
|
||||||
const showTagsDrawer = ref(false)
|
const showTagsDrawer = ref(false)
|
||||||
|
|
@ -150,12 +151,20 @@ const handleDelete = async (post) => {
|
||||||
}
|
}
|
||||||
|
|
||||||
const handleSubmit = async (body) => {
|
const handleSubmit = async (body) => {
|
||||||
|
try {
|
||||||
if (editingPost.value) {
|
if (editingPost.value) {
|
||||||
await updatePost(editingPost.value._id, body)
|
await updatePost(editingPost.value._id, body)
|
||||||
} else {
|
} else {
|
||||||
await createPost(body)
|
await createPost(body)
|
||||||
}
|
}
|
||||||
closeForm()
|
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',
|
||||||
|
})
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const loadTags = async () => {
|
const loadTags = async () => {
|
||||||
|
|
@ -174,7 +183,7 @@ useHead({
|
||||||
})
|
})
|
||||||
|
|
||||||
onMounted(async () => {
|
onMounted(async () => {
|
||||||
await Promise.all([loadTags(), fetchPosts(), fetchChannels()])
|
await Promise.allSettled([loadTags(), fetchPosts(), fetchChannels()])
|
||||||
})
|
})
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue