feat: market event

This commit is contained in:
OpenSquared
2026-06-29 12:49:12 +02:00
parent 79593a8fd3
commit ac441ad5cb
2 changed files with 40 additions and 3 deletions

View File

@@ -509,8 +509,32 @@ function EventDetail({
setRecMsg(`${rec.template_name}${rec.confidence ? ` (${Math.round(rec.confidence * 100)}%)` : ''}`)
await instantiate(rec.template_id)
} else {
setRecMsg('Aucun template adapté trouvé')
setNoTemplateFound(true)
// Aucun template adapté — création automatique d'un nouveau
setRecMsg('Aucun template adapté — création en cours…')
setNoTemplateFound(false)
setLoadingCreate(true)
try {
const cr = await fetch('/api/causal-lab/create-from-event', {
method: 'POST', headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ market_event_id: detail.id }),
})
const cd = await cr.json()
if (!cr.ok) throw new Error(cd.detail || cr.statusText)
const newTmplId = cd.template?.id ?? cd.template_id
if (newTmplId) {
setTemplates(prev => [...prev, cd.template].filter(Boolean))
setSelTmpl(newTmplId)
setRecMsg(`✦ Nouveau template créé : ${cd.template?.name ?? 'template'}`)
await instantiate(newTmplId)
} else {
setRecMsg('Template créé mais ID manquant')
}
} catch (ce: any) {
setRecMsg(`✗ Création échouée : ${ce.message}`)
setNoTemplateFound(true)
} finally {
setLoadingCreate(false)
}
}
} catch (e: any) { setRecMsg(`${(e as any).message}`) }
finally { setLoadingRec(false) }