diff --git a/artifacts/voix-du-peuple/src/pages/consultation.tsx b/artifacts/voix-du-peuple/src/pages/consultation.tsx index c124e78..594cf26 100644 --- a/artifacts/voix-du-peuple/src/pages/consultation.tsx +++ b/artifacts/voix-du-peuple/src/pages/consultation.tsx @@ -181,6 +181,12 @@ export default function ConsultationPage() { setShowConsentDialog(true); return; } + try { + const visitorId = getVisitorId(); + const h: Record = { "Content-Type": "application/json" }; + if (visitorId) h["X-Visitor-Id"] = visitorId; + await fetch(`${API_BASE}/api/consent`, { method: "POST", headers: h, body: JSON.stringify({ consent_version: "1.0" }) }); + } catch { /* non-bloquant */ } await doActualSubmit(data); }; diff --git a/artifacts/voix-du-peuple/src/pages/home.tsx b/artifacts/voix-du-peuple/src/pages/home.tsx index c4d2172..13fbc0a 100644 --- a/artifacts/voix-du-peuple/src/pages/home.tsx +++ b/artifacts/voix-du-peuple/src/pages/home.tsx @@ -165,22 +165,24 @@ export default function Home() { }); }; - // Confirme le consentement, l'enregistre en DB, puis exécute la soumission en attente - const handleConsentConfirm = () => { - localStorage.setItem("consent_v1", new Date().toISOString()); - setConsentGiven(true); - setShowConsentDialog(false); + const postConsent = async () => { const visitorId = getVisitorId(); - fetch(`${API_BASE}/api/consent`, { + await fetch(`${API_BASE}/api/consent`, { method: "POST", headers: { "Content-Type": "application/json", ...(visitorId ? { "X-Visitor-Id": visitorId } : {}), }, body: JSON.stringify({ consent_version: "1.0" }), - }).catch(() => { - // Dégradation silencieuse — localStorage suffit comme preuve côté client - }); + }).catch(() => {}); + }; + + // Confirme le consentement, l'enregistre en DB, puis exécute la soumission en attente + const handleConsentConfirm = async () => { + localStorage.setItem("consent_v1", new Date().toISOString()); + setConsentGiven(true); + setShowConsentDialog(false); + await postConsent(); if (pendingSubmitData.current) { doActualSubmit(pendingSubmitData.current); pendingSubmitData.current = null; @@ -250,7 +252,7 @@ export default function Home() { defaultValues: { content: "", author: "" }, }); - const onSubmit = (data: SubmitIdeaValues) => { + const onSubmit = async (data: SubmitIdeaValues) => { // Honeypot — si le champ leurre est rempli, c'est un bot if (honeypotRef.current?.value) { setSubmitResult({ success: true, message: "Votre contribution a été ajoutée à la synthèse." }); @@ -268,6 +270,7 @@ export default function Home() { setShowConsentDialog(true); return; } + await postConsent(); doActualSubmit(data); };