diff --git a/app/composables/useComponentEdit.ts b/app/composables/useComponentEdit.ts index 1f8ec31..5d95246 100644 --- a/app/composables/useComponentEdit.ts +++ b/app/composables/useComponentEdit.ts @@ -7,7 +7,6 @@ import { useProductTypes } from '~/composables/useProductTypes' import { usePieces } from '~/composables/usePieces' import { useProducts } from '~/composables/useProducts' import { useCustomFields } from '~/composables/useCustomFields' -import type { SelectionEntry } from '~/shared/utils/structureSelectionUtils' import { useApi } from '~/composables/useApi' import { useToast } from '~/composables/useToast' import { extractRelationId } from '~/shared/apiRelations' @@ -348,19 +347,17 @@ export function useComponentEdit(componentId: string) { } } - const saveSlotQuantity = async (entry: SelectionEntry) => { - const slotId = entry.slotId - const quantity = typeof entry._definition?.quantity === 'number' - ? Math.max(1, entry._definition.quantity) - : null - if (!slotId || quantity === null) return - try { - await patch(`/composant-piece-slots/${slotId}`, { quantity }) + const saveSlotQuantity = async (slotId: string, quantity: number) => { + if (!slotId || quantity < 1) return + const result = await patch(`/composant-piece-slots/${slotId}`, { quantity: Math.max(1, quantity) }) + if (result.success) { + const structure = component.value?.structure + if (structure?.pieces) { + const slot = (structure.pieces as any[]).find((s: any) => s.slotId === slotId) + if (slot) slot.quantity = quantity + } toast.showSuccess('Quantité mise à jour') } - catch (error: any) { - toast.showError(error?.message || 'Erreur lors de la mise à jour de la quantité') - } } const submitEdition = async () => { diff --git a/app/pages/component/[id]/edit.vue b/app/pages/component/[id]/edit.vue index 6192bac..c0387a6 100644 --- a/app/pages/component/[id]/edit.vue +++ b/app/pages/component/[id]/edit.vue @@ -186,12 +186,27 @@ {{ slot.label }} - savePieceSlotSelection(slot.slotId, value)" - /> + + + savePieceSlotSelection(slot.slotId, value)" + /> + + + saveSlotQuantity(slot.slotId, Number((e.target as HTMLInputElement).value))" + > + +