feat(frontend): Refactor organization, fixed several organization bugs

This commit is contained in:
2025-08-17 09:28:26 +02:00
parent b7b6d02cf2
commit 6090d543c1
14 changed files with 279 additions and 221 deletions

View File

@@ -0,0 +1,66 @@
import type { CreateCommentDto, CommentDto } from '~/.api-client'
export function useCommentTextarea(applicationFormId: string) {
const commentStore = useCommentStore()
const { createComment, updateComment } = commentStore
const { user } = useAuth()
const isEditingComment = ref(false)
const currentEditedComment = ref<CommentDto | null>(null)
const commentTextAreaValue = ref('')
const toast = useToast()
async function submitComment(formElementId: string) {
const newCommentDto: CreateCommentDto = {
message: commentTextAreaValue.value
}
try {
await createComment(applicationFormId, formElementId, newCommentDto)
commentTextAreaValue.value = ''
toast.add({ title: 'Comment created successfully', color: 'success' })
} catch (e) {
toast.add({ title: 'Error creating comment', color: 'error' })
console.error('Error creating comment:', e)
}
}
async function updateEditComment() {
if (!currentEditedComment.value) return
const updatedComment: CommentDto = { ...currentEditedComment.value, message: commentTextAreaValue.value }
try {
await updateComment(currentEditedComment.value.id, updatedComment)
commentTextAreaValue.value = ''
currentEditedComment.value = null
isEditingComment.value = false
toast.add({ title: 'Comment updated successfully', color: 'success' })
} catch (e) {
toast.add({ title: 'Error updating comment', color: 'error' })
console.error('Error updating comment:', e)
}
}
function editComment(comment: CommentDto) {
isEditingComment.value = true
currentEditedComment.value = comment
commentTextAreaValue.value = comment.message || ''
}
function cancelEditComment() {
isEditingComment.value = false
currentEditedComment.value = null
commentTextAreaValue.value = ''
}
function isCommentByUser(comment: CommentDto) {
return comment.createdBy.id === user.value?.id
}
return {
commentTextAreaValue,
submitComment,
updateEditComment,
editComment,
cancelEditComment,
isEditingComment,
isCommentByUser
}
}