major: Rename legalconsenthub to gremiumhub
This commit is contained in:
@@ -1,67 +0,0 @@
|
||||
import {
|
||||
CommentApi,
|
||||
Configuration,
|
||||
type ApplicationFormCommentCountsDto,
|
||||
type CommentDto,
|
||||
type CreateCommentDto,
|
||||
type CursorPagedCommentDto
|
||||
} from '~~/.api-client'
|
||||
import { cleanDoubleSlashes, withoutTrailingSlash } from 'ufo'
|
||||
import { wrappedFetchWrap } from '~/utils/wrappedFetch'
|
||||
|
||||
export function useCommentApi() {
|
||||
const appBaseUrl = useRuntimeConfig().app.baseURL
|
||||
const { serverApiBasePath, clientProxyBasePath } = useRuntimeConfig().public
|
||||
|
||||
const basePath = withoutTrailingSlash(
|
||||
cleanDoubleSlashes(import.meta.client ? appBaseUrl + clientProxyBasePath : clientProxyBasePath + serverApiBasePath)
|
||||
)
|
||||
|
||||
const commentApiClient = new CommentApi(
|
||||
new Configuration({ basePath, fetchApi: wrappedFetchWrap(useRequestFetch()) })
|
||||
)
|
||||
|
||||
async function createComment(
|
||||
applicationFormId: string,
|
||||
formElementId: string,
|
||||
createCommentDto: CreateCommentDto
|
||||
): Promise<CommentDto> {
|
||||
return commentApiClient.createComment({ applicationFormId, formElementId, createCommentDto })
|
||||
}
|
||||
|
||||
async function getCommentsByApplicationFormId(
|
||||
applicationFormId: string,
|
||||
formElementId?: string,
|
||||
cursorCreatedAt?: Date,
|
||||
limit: number = 10
|
||||
): Promise<CursorPagedCommentDto> {
|
||||
return commentApiClient.getCommentsByApplicationFormId({
|
||||
applicationFormId,
|
||||
formElementId,
|
||||
cursorCreatedAt,
|
||||
limit
|
||||
})
|
||||
}
|
||||
|
||||
async function getGroupedCommentCountByApplicationFromId(
|
||||
applicationFormId: string
|
||||
): Promise<ApplicationFormCommentCountsDto> {
|
||||
return commentApiClient.getGroupedCommentCountByApplicationFromId({ applicationFormId })
|
||||
}
|
||||
|
||||
async function updateComment(id: string, commentDto: CommentDto): Promise<CommentDto> {
|
||||
return commentApiClient.updateComment({ id, commentDto })
|
||||
}
|
||||
|
||||
async function deleteCommentById(id: string): Promise<void> {
|
||||
return commentApiClient.deleteComment({ id })
|
||||
}
|
||||
|
||||
return {
|
||||
createComment,
|
||||
getCommentsByApplicationFormId,
|
||||
getGroupedCommentCountByApplicationFromId,
|
||||
updateComment,
|
||||
deleteCommentById
|
||||
}
|
||||
}
|
||||
@@ -1,72 +0,0 @@
|
||||
import type { CreateCommentDto, CommentDto } from '~~/.api-client'
|
||||
import { useCommentStore } from '~~/stores/useCommentStore'
|
||||
import { useUserStore } from '~~/stores/useUserStore'
|
||||
import { useLogger } from '../useLogger'
|
||||
|
||||
export function useCommentTextarea(applicationFormId: string) {
|
||||
const commentStore = useCommentStore()
|
||||
const { createComment, updateComment } = commentStore
|
||||
const userStore = useUserStore()
|
||||
const { user } = storeToRefs(userStore)
|
||||
const isEditingComment = ref(false)
|
||||
const currentEditedComment = ref<CommentDto | null>(null)
|
||||
const commentTextAreaValue = ref('')
|
||||
const toast = useToast()
|
||||
const { t: $t } = useI18n()
|
||||
const logger = useLogger().withTag('commentTextarea')
|
||||
|
||||
async function submitComment(formElementId: string) {
|
||||
const newCommentDto: CreateCommentDto = {
|
||||
message: commentTextAreaValue.value
|
||||
}
|
||||
try {
|
||||
await createComment(applicationFormId, formElementId, newCommentDto)
|
||||
commentTextAreaValue.value = ''
|
||||
toast.add({ title: $t('comments.created'), color: 'success' })
|
||||
} catch (e) {
|
||||
toast.add({ title: $t('comments.createError'), color: 'error' })
|
||||
logger.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: $t('comments.updated'), color: 'success' })
|
||||
} catch (e) {
|
||||
toast.add({ title: $t('comments.updateError'), color: 'error' })
|
||||
logger.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.keycloakId === user.value?.keycloakId
|
||||
}
|
||||
|
||||
return {
|
||||
commentTextAreaValue,
|
||||
submitComment,
|
||||
updateEditComment,
|
||||
editComment,
|
||||
cancelEditComment,
|
||||
isEditingComment,
|
||||
isCommentByUser
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user