site-mva-global-fret/js/confirmation.js
MVA Global Fret 82bc8ba358 Switch from Resend to Brevo for transactional emails
Resend requires a verified domain to send to arbitrary recipients —
mvaglobalfret.com isn't registered. Brevo accepts single-sender
verification on a free email address, so we can send from
mvaglobalfret@gmail.com without owning a domain.

- Worker: replace resendSend() with brevoSend() (api.brevo.com/v3/smtp/email)
- Env vars: BREVO_API_KEY, BREVO_SENDER_EMAIL, BREVO_SENDER_NAME
- Update comments in confirmation.js and form-handler.js

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-05-06 12:26:50 +02:00

77 lines
2.7 KiB
JavaScript

// ============================================================
// MVA Global Fret — Page de confirmation post-validation email
// ============================================================
// Cette page est la cible du lien dans l'email de validation
// (envoyé par Brevo après soumission du formulaire).
//
// URL : https://mva-global-fret.github.io/site-mva-global-fret/confirmation.html?token=XXX
//
// Étapes :
// 1. Lire le token depuis l'URL
// 2. POST au Worker avec action 'verifyToken'
// 3. Worker valide le token, envoie le welcome email (avec ref +
// adresse Paris) via Brevo, puis renvoie OK
// 4. Page affiche "Inscription confirmée !"
//
// Si le token est invalide / expiré : affichage d'un message d'erreur
// avec invitation à contacter le support.
// ============================================================
const WORKER_PROXY_URL = 'https://mva-hubspot-proxy.mvaglobalfret.workers.dev';
document.addEventListener('DOMContentLoaded', async () => {
const token = new URLSearchParams(window.location.search).get('token');
if (!token) {
showError('Lien de confirmation invalide. Veuillez vérifier votre email ou nous contacter.');
return;
}
try {
const res = await fetch(WORKER_PROXY_URL, {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ action: 'verifyToken', token }),
});
const data = await res.json();
if (data.ok) {
showSuccess(data.reference_client || null);
} else {
// Token expiré, déjà utilisé, ou inconnu
showError(data.error === 'Token invalide ou expiré'
? 'Ce lien de confirmation a expiré ou a déjà été utilisé.'
: 'Une erreur est survenue lors de la confirmation.');
}
} catch (err) {
console.warn('[confirmation]', err);
showError('Impossible de joindre le serveur. Vérifiez votre connexion et réessayez.');
}
});
function showSuccess(ref) {
const loading = document.getElementById('cardLoading');
const success = document.getElementById('cardSuccess');
if (loading) loading.style.display = 'none';
if (success) {
success.style.display = '';
if (ref) {
const refDisplay = document.getElementById('refDisplay');
const refBlock = document.getElementById('refBlock');
if (refDisplay) refDisplay.textContent = ref;
if (refBlock) refBlock.style.display = '';
}
}
}
function showError(msg) {
const loading = document.getElementById('cardLoading');
const error = document.getElementById('cardError');
if (loading) loading.style.display = 'none';
if (error) {
error.style.display = '';
const desc = error.querySelector('p');
if (desc && msg) desc.textContent = msg;
}
}