fix(plantes): deleteVariety/submitVariety — try/catch + refresh detailPlantObj

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
2026-03-08 19:38:06 +01:00
parent 174ed9c25d
commit 672ac529e7

View File

@@ -868,25 +868,36 @@ function closeFormVariety() {
async function submitVariety() {
if (!detailPlantObj.value?.id) return
const payload = { ...formVariety, prix_achat: formVariety.prix_achat ?? undefined }
if (editVariety.value?.id) {
await plantsStore.updateVariety(detailPlantObj.value.id, editVariety.value.id, payload)
toast.success('Variété modifiée')
} else {
await plantsStore.createVariety(detailPlantObj.value.id, payload)
toast.success('Variété ajoutée')
try {
if (editVariety.value?.id) {
await plantsStore.updateVariety(detailPlantObj.value.id, editVariety.value.id, payload)
toast.success('Variété modifiée')
} else {
await plantsStore.createVariety(detailPlantObj.value.id, payload)
toast.success('Variété ajoutée')
}
// Refresh plant data so detailPlantObj reflects updated varieties
await plantsStore.fetchAll()
const updatedPlant = plantsStore.plants.find(p => p.id === detailPlantObj.value?.id)
if (updatedPlant) detailPlantObj.value = updatedPlant
closeFormVariety()
} catch {
// L'intercepteur Axios affiche le message d'erreur
}
// Refresh plant data so detailPlantObj reflects updated varieties
await plantsStore.fetchAll()
const updatedPlant = plantsStore.plants.find(p => p.id === detailPlantObj.value?.id)
if (updatedPlant) detailPlantObj.value = updatedPlant
closeFormVariety()
}
async function deleteVariety(vid: number) {
if (!detailPlantObj.value?.id) return
if (!confirm('Supprimer cette variété ?')) return
await plantsStore.removeVariety(detailPlantObj.value.id, vid)
toast.success('Variété supprimée')
try {
await plantsStore.removeVariety(detailPlantObj.value.id, vid)
await plantsStore.fetchAll()
const updatedPlant = plantsStore.plants.find(p => p.id === detailPlantObj.value?.id)
if (updatedPlant) detailPlantObj.value = updatedPlant
toast.success('Variété supprimée')
} catch {
// L'intercepteur Axios affiche le message d'erreur
}
}
async function submitPlant() {