feat(#12): Add subsections to sections, fix version deletion after update
This commit is contained in:
@@ -76,25 +76,25 @@ export function useApplicationForm() {
|
||||
}
|
||||
}
|
||||
|
||||
async function addFormElementToSection(
|
||||
async function addFormElementToSubSection(
|
||||
applicationFormId: string,
|
||||
sectionId: string,
|
||||
subsectionId: string,
|
||||
createFormElementDto: CreateFormElementDto,
|
||||
position: number
|
||||
): Promise<ApplicationFormDto> {
|
||||
if (!applicationFormId || !sectionId) {
|
||||
return Promise.reject(new Error('Application form ID or section ID missing'))
|
||||
if (!applicationFormId || !subsectionId) {
|
||||
return Promise.reject(new Error('Application form ID or subsection ID missing'))
|
||||
}
|
||||
|
||||
try {
|
||||
return await applicationFormApi.addFormElementToSection(
|
||||
return await applicationFormApi.addFormElementToSubSection(
|
||||
applicationFormId,
|
||||
sectionId,
|
||||
subsectionId,
|
||||
createFormElementDto,
|
||||
position
|
||||
)
|
||||
} catch (e: unknown) {
|
||||
console.error(`Failed adding form element to section ${sectionId}:`, e)
|
||||
console.error(`Failed adding form element to subsection ${subsectionId}:`, e)
|
||||
return Promise.reject(e)
|
||||
}
|
||||
}
|
||||
@@ -106,6 +106,6 @@ export function useApplicationForm() {
|
||||
updateApplicationForm,
|
||||
deleteApplicationFormById,
|
||||
submitApplicationForm,
|
||||
addFormElementToSection
|
||||
addFormElementToSubSection
|
||||
}
|
||||
}
|
||||
|
||||
@@ -54,15 +54,15 @@ export function useApplicationFormApi() {
|
||||
return applicationFormApiClient.submitApplicationForm({ id })
|
||||
}
|
||||
|
||||
async function addFormElementToSection(
|
||||
async function addFormElementToSubSection(
|
||||
applicationFormId: string,
|
||||
sectionId: string,
|
||||
subsectionId: string,
|
||||
createFormElementDto: CreateFormElementDto,
|
||||
position: number
|
||||
): Promise<ApplicationFormDto> {
|
||||
return applicationFormApiClient.addFormElementToSection({
|
||||
return applicationFormApiClient.addFormElementToSubSection({
|
||||
applicationFormId,
|
||||
sectionId,
|
||||
subsectionId,
|
||||
createFormElementDto,
|
||||
position
|
||||
})
|
||||
@@ -75,6 +75,6 @@ export function useApplicationFormApi() {
|
||||
updateApplicationForm,
|
||||
deleteApplicationFormById,
|
||||
submitApplicationForm,
|
||||
addFormElementToSection
|
||||
addFormElementToSubSection
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,18 +1,14 @@
|
||||
import type { ApplicationFormDto, CreateFormElementDto, FormElementSectionDto } from '~~/.api-client'
|
||||
import type { MaybeRefOrGetter } from 'vue'
|
||||
import type { ApplicationFormDto, CreateFormElementDto, FormElementDto } from '~~/.api-client'
|
||||
|
||||
export function useFormElementManagement(
|
||||
currentFormElementSection: MaybeRefOrGetter<FormElementSectionDto | undefined>,
|
||||
applicationFormId?: string
|
||||
) {
|
||||
const { addFormElementToSection } = useApplicationForm()
|
||||
|
||||
async function addInputFormToApplicationForm(position: number): Promise<ApplicationFormDto | undefined> {
|
||||
const section = toValue(currentFormElementSection)
|
||||
if (!section) return
|
||||
|
||||
const { formElements } = section
|
||||
export function useFormElementManagement() {
|
||||
const applicationForm = useApplicationForm()
|
||||
|
||||
async function addFormElementToSubSection(
|
||||
applicationFormId: string | undefined,
|
||||
subsectionId: string,
|
||||
formElements: FormElementDto[],
|
||||
position: number
|
||||
): Promise<ApplicationFormDto | undefined> {
|
||||
const inputFormElement: CreateFormElementDto = {
|
||||
title: 'Formular ergänzen',
|
||||
description: 'Bitte fügen Sie hier Ihre Ergänzungen ein.',
|
||||
@@ -29,7 +25,7 @@ export function useFormElementManagement(
|
||||
|
||||
if (applicationFormId) {
|
||||
try {
|
||||
return await addFormElementToSection(applicationFormId, section.id, inputFormElement, position + 1)
|
||||
return await applicationForm.addFormElementToSubSection(applicationFormId, subsectionId, inputFormElement, position + 1)
|
||||
} catch (error) {
|
||||
console.error('Failed to add form element:', error)
|
||||
throw error
|
||||
@@ -42,6 +38,6 @@ export function useFormElementManagement(
|
||||
}
|
||||
|
||||
return {
|
||||
addInputFormToApplicationForm
|
||||
addFormElementToSubSection
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user