refactor: adopt canonical component model structure schema

This commit is contained in:
MatthieuTD
2025-10-01 14:26:31 +02:00
parent d3f8ac3649
commit 386a1c9d1b
9 changed files with 470 additions and 146 deletions

View File

@@ -214,6 +214,7 @@ import {
cloneStructure,
normalizeStructureForSave,
} from '~/shared/modelUtils'
import { componentModelStructureValidator } from '~/shared/types/inventory'
import { formatFrenchDate } from '~/utils/date'
import IconLucidePlus from '~icons/lucide/plus'
import IconLucideLayers from '~icons/lucide/layers'
@@ -328,12 +329,19 @@ const handleSubmit = async () => {
form.submitting = true
try {
const normalizedStructure = normalizeStructureForSave(form.data.structure)
const validationResult = componentModelStructureValidator.safeParse(normalizedStructure)
if (!validationResult.success) {
showError(`Structure invalide: ${validationResult.issues.join(', ')}`)
return
}
if (form.mode === 'create') {
const result = await createComponentModel({
name: form.data.name.trim(),
description: form.data.description.trim() || undefined,
typeComposantId: form.data.typeComposantId,
structure: normalizeStructureForSave(form.data.structure),
structure: normalizedStructure,
})
if (!result.success) {
showError(result.error || 'Impossible de créer le modèle')
@@ -345,7 +353,7 @@ const handleSubmit = async () => {
name: form.data.name.trim(),
description: form.data.description.trim() || undefined,
typeComposantId: form.data.typeComposantId,
structure: normalizeStructureForSave(form.data.structure),
structure: normalizedStructure,
})
if (!result.success) {
showError(result.error || 'Impossible de mettre à jour le modèle')