refactor: adopt canonical component model structure schema
This commit is contained in:
@@ -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')
|
||||
|
||||
Reference in New Issue
Block a user