major(fullstack): Add dynamic section spawning, removal of app. form create DTOs,
This commit is contained in:
@@ -1,15 +1,15 @@
|
||||
import type { ApplicationFormDto, CreateFormElementDto, FormElementDto } from '~~/.api-client'
|
||||
import type { FormElementDto } from '~~/.api-client'
|
||||
|
||||
export function useFormElementManagement() {
|
||||
const applicationForm = useApplicationForm()
|
||||
function addInputFormElement(elements: FormElementDto[], position: number): FormElementDto[] {
|
||||
const inputFormElement = createInputFormElement()
|
||||
const updatedElements = [...elements]
|
||||
updatedElements.splice(position + 1, 0, inputFormElement)
|
||||
return updatedElements
|
||||
}
|
||||
|
||||
async function addFormElementToSubSection(
|
||||
applicationFormId: string | undefined,
|
||||
subsectionId: string,
|
||||
formElements: FormElementDto[],
|
||||
position: number
|
||||
): Promise<ApplicationFormDto | undefined> {
|
||||
const inputFormElement: CreateFormElementDto = {
|
||||
function createInputFormElement(): FormElementDto {
|
||||
return {
|
||||
title: 'Formular ergänzen',
|
||||
description: 'Bitte fügen Sie hier Ihre Ergänzungen ein.',
|
||||
options: [
|
||||
@@ -22,27 +22,9 @@ export function useFormElementManagement() {
|
||||
],
|
||||
type: 'TITLE_BODY_TEXTFIELDS'
|
||||
}
|
||||
|
||||
if (applicationFormId) {
|
||||
try {
|
||||
return await applicationForm.addFormElementToSubSection(
|
||||
applicationFormId,
|
||||
subsectionId,
|
||||
inputFormElement,
|
||||
position + 1
|
||||
)
|
||||
} catch (error) {
|
||||
console.error('Failed to add form element:', error)
|
||||
throw error
|
||||
}
|
||||
} else {
|
||||
// @ts-expect-error Add CreateFormElementDto to formElements array. ID will be generated by the backend.
|
||||
formElements.splice(position + 1, 0, inputFormElement)
|
||||
return undefined
|
||||
}
|
||||
}
|
||||
|
||||
return {
|
||||
addFormElementToSubSection
|
||||
addInputFormElement
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user