1 Commits

Author SHA1 Message Date
Matthieu
d4fc0f1fee fix(slots) : check API response before updating local state on slot selection
The save functions (savePieceSlotSelection, saveProductSlotSelection,
saveSubcomponentSlotSelection) were not checking result.success before
updating local state and showing success toast. Since useApi.patch()
never throws, the catch block was dead code and errors were silently
ignored while the UI showed success.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-03-16 11:31:19 +01:00

View File

@@ -313,9 +313,8 @@ export function useComponentEdit(componentId: string) {
}) })
const savePieceSlotSelection = async (slotId: string, selectedPieceId: string | null) => { const savePieceSlotSelection = async (slotId: string, selectedPieceId: string | null) => {
try { const result = await patch(`/composant-piece-slots/${slotId}`, { selectedPieceId })
await patch(`/composant-piece-slots/${slotId}`, { selectedPieceId }) if (result.success) {
// Update local structure
const structure = component.value?.structure const structure = component.value?.structure
if (structure?.pieces) { if (structure?.pieces) {
const slot = (structure.pieces as any[]).find((s: any) => s.slotId === slotId) const slot = (structure.pieces as any[]).find((s: any) => s.slotId === slotId)
@@ -323,14 +322,11 @@ export function useComponentEdit(componentId: string) {
} }
toast.showSuccess('Pièce mise à jour') toast.showSuccess('Pièce mise à jour')
} }
catch (error: any) {
toast.showError(error?.message || 'Erreur lors de la mise à jour')
}
} }
const saveProductSlotSelection = async (slotId: string, selectedProductId: string | null) => { const saveProductSlotSelection = async (slotId: string, selectedProductId: string | null) => {
try { const result = await patch(`/composant-product-slots/${slotId}`, { selectedProductId })
await patch(`/composant-product-slots/${slotId}`, { selectedProductId }) if (result.success) {
const structure = component.value?.structure const structure = component.value?.structure
if (structure?.products) { if (structure?.products) {
const slot = (structure.products as any[]).find((s: any) => s.slotId === slotId) const slot = (structure.products as any[]).find((s: any) => s.slotId === slotId)
@@ -338,14 +334,11 @@ export function useComponentEdit(componentId: string) {
} }
toast.showSuccess('Produit mis à jour') toast.showSuccess('Produit mis à jour')
} }
catch (error: any) {
toast.showError(error?.message || 'Erreur lors de la mise à jour')
}
} }
const saveSubcomponentSlotSelection = async (slotId: string, selectedComposantId: string | null) => { const saveSubcomponentSlotSelection = async (slotId: string, selectedComposantId: string | null) => {
try { const result = await patch(`/composant-subcomponent-slots/${slotId}`, { selectedComposantId })
await patch(`/composant-subcomponent-slots/${slotId}`, { selectedComposantId }) if (result.success) {
const structure = component.value?.structure const structure = component.value?.structure
if (structure?.subcomponents) { if (structure?.subcomponents) {
const slot = (structure.subcomponents as any[]).find((s: any) => s.slotId === slotId) const slot = (structure.subcomponents as any[]).find((s: any) => s.slotId === slotId)
@@ -353,9 +346,6 @@ export function useComponentEdit(componentId: string) {
} }
toast.showSuccess('Sous-composant mis à jour') toast.showSuccess('Sous-composant mis à jour')
} }
catch (error: any) {
toast.showError(error?.message || 'Erreur lors de la mise à jour')
}
} }
const saveSlotQuantity = async (entry: SelectionEntry) => { const saveSlotQuantity = async (entry: SelectionEntry) => {