From 44b6e0998c3315903e8e53022eb26f9dce7ff80e Mon Sep 17 00:00:00 2001 From: r-dev Date: Sat, 4 Apr 2026 13:18:16 +0200 Subject: [PATCH] fix(custom-fields) : fix declaration order in useComponentEdit and useComponentCreate Co-Authored-By: Claude Opus 4.6 (1M context) --- .../app/composables/useComponentCreate.ts | 24 ++++++------- frontend/app/composables/useComponentEdit.ts | 34 +++++++++---------- 2 files changed, 29 insertions(+), 29 deletions(-) diff --git a/frontend/app/composables/useComponentCreate.ts b/frontend/app/composables/useComponentCreate.ts index 9c77342..f1e35f5 100644 --- a/frontend/app/composables/useComponentCreate.ts +++ b/frontend/app/composables/useComponentCreate.ts @@ -93,18 +93,6 @@ export function useComponentCreate() { const lastSuggestedName = ref('') const createdComponentId = ref(null) - const { - fields: customFieldInputs, - requiredFilled: requiredCustomFieldsFilled, - saveAll: saveAllCustomFields, - refresh: refreshCustomFieldInputs, - } = useCustomFieldInputs({ - definitions: computed(() => selectedTypeStructure.value?.customFields ?? []), - values: computed(() => []), - entityType: 'composant', - entityId: createdComponentId, - }) - const structureAssignments = ref(null) const selectedDocuments = ref([]) const uploadingDocuments = ref(false) @@ -154,6 +142,18 @@ export function useComponentCreate() { return structure ? normalizeStructureForEditor(structure) : null }) + const { + fields: customFieldInputs, + requiredFilled: requiredCustomFieldsFilled, + saveAll: saveAllCustomFields, + refresh: refreshCustomFieldInputs, + } = useCustomFieldInputs({ + definitions: computed(() => selectedTypeStructure.value?.customFields ?? []), + values: computed(() => []), + entityType: 'composant', + entityId: createdComponentId, + }) + const structureHasRequirements = computed(() => hasAssignments(structureAssignments.value), ) diff --git a/frontend/app/composables/useComponentEdit.ts b/frontend/app/composables/useComponentEdit.ts index f8fb127..e8e23c3 100644 --- a/frontend/app/composables/useComponentEdit.ts +++ b/frontend/app/composables/useComponentEdit.ts @@ -89,23 +89,6 @@ export function useComponentEdit(componentId: string) { const originalConstructeurLinks = ref([]) const constructeurIdsFromForm = computed(() => constructeurIdsFromLinks(constructeurLinks.value)) - const { - fields: customFieldInputs, - requiredFilled: requiredCustomFieldsFilled, - saveAll: saveAllCustomFields, - refresh: refreshCustomFieldInputs, - } = useCustomFieldInputs({ - definitions: computed(() => selectedTypeStructure.value?.customFields ?? []), - values: computed(() => component.value?.customFieldValues ?? []), - entityType: 'composant', - entityId: computed(() => component.value?.id ?? null), - onValueCreated: (newValue) => { - if (component.value && Array.isArray(component.value.customFieldValues)) { - component.value.customFieldValues.push(newValue) - } - }, - }) - const fetchedPieceTypeMap = ref>({}) const pieceTypeLabelMap = computed(() => buildTypeLabelMap(pieceTypes.value, fetchedPieceTypeMap.value), @@ -216,6 +199,23 @@ export function useComponentEdit(componentId: string) { return structure ? normalizeStructureForEditor(structure) : null }) + const { + fields: customFieldInputs, + requiredFilled: requiredCustomFieldsFilled, + saveAll: saveAllCustomFields, + refresh: refreshCustomFieldInputs, + } = useCustomFieldInputs({ + definitions: computed(() => selectedTypeStructure.value?.customFields ?? []), + values: computed(() => component.value?.customFieldValues ?? []), + entityType: 'composant', + entityId: computed(() => component.value?.id ?? null), + onValueCreated: (newValue) => { + if (component.value && Array.isArray(component.value.customFieldValues)) { + component.value.customFieldValues.push(newValue) + } + }, + }) + const canSubmit = computed(() => Boolean( canEdit.value && component.value