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>
This commit is contained in:
@@ -313,9 +313,8 @@ export function useComponentEdit(componentId: string) {
|
||||
})
|
||||
|
||||
const savePieceSlotSelection = async (slotId: string, selectedPieceId: string | null) => {
|
||||
try {
|
||||
await patch(`/composant-piece-slots/${slotId}`, { selectedPieceId })
|
||||
// Update local structure
|
||||
const result = await patch(`/composant-piece-slots/${slotId}`, { selectedPieceId })
|
||||
if (result.success) {
|
||||
const structure = component.value?.structure
|
||||
if (structure?.pieces) {
|
||||
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')
|
||||
}
|
||||
catch (error: any) {
|
||||
toast.showError(error?.message || 'Erreur lors de la mise à jour')
|
||||
}
|
||||
}
|
||||
|
||||
const saveProductSlotSelection = async (slotId: string, selectedProductId: string | null) => {
|
||||
try {
|
||||
await patch(`/composant-product-slots/${slotId}`, { selectedProductId })
|
||||
const result = await patch(`/composant-product-slots/${slotId}`, { selectedProductId })
|
||||
if (result.success) {
|
||||
const structure = component.value?.structure
|
||||
if (structure?.products) {
|
||||
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')
|
||||
}
|
||||
catch (error: any) {
|
||||
toast.showError(error?.message || 'Erreur lors de la mise à jour')
|
||||
}
|
||||
}
|
||||
|
||||
const saveSubcomponentSlotSelection = async (slotId: string, selectedComposantId: string | null) => {
|
||||
try {
|
||||
await patch(`/composant-subcomponent-slots/${slotId}`, { selectedComposantId })
|
||||
const result = await patch(`/composant-subcomponent-slots/${slotId}`, { selectedComposantId })
|
||||
if (result.success) {
|
||||
const structure = component.value?.structure
|
||||
if (structure?.subcomponents) {
|
||||
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')
|
||||
}
|
||||
catch (error: any) {
|
||||
toast.showError(error?.message || 'Erreur lors de la mise à jour')
|
||||
}
|
||||
}
|
||||
|
||||
const saveSlotQuantity = async (entry: SelectionEntry) => {
|
||||
|
||||
Reference in New Issue
Block a user