// ============================================================ // MVA Global Fret — Page de confirmation post-validation email // ============================================================ // Cette page est la cible du lien dans l'email de validation envoyé // par mva-api (= Resend) lors d'une inscription via contact.html. // // URL : https://mva-globalfret.com/confirmation.html?token=XXX // // Étapes : // 1. Lire le token depuis l'URL // 2. POST mva-api /leads/verify-token avec { token } // 3. mva-api INSERT le lead en DB, génère la ref MVA-NNN, envoie le // welcome email (= ref + adresse Paris) via Resend, puis renvoie // { ok: true, firstname, reference_client } // 4. Page affiche "Inscription confirmée !" + la ref // // Si le token est invalide / expiré / déjà consommé : affichage d'un // message d'erreur avec invitation à contacter le support. // // Les inscriptions sont confirmées via les routes leads de l'API. // ============================================================ const API_BASE_URL = 'https://api.mva.mind4solutions.com'; 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(`${API_BASE_URL}/leads/verify-token`, { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify({ token }), }); const data = await res.json(); if (data.ok) { showSuccess(data.reference_client || null); } else { // Token invalide, expiré, ou inconnu const isInvalid = data.code === 'INVALID_OR_EXPIRED' || data.message === 'Token invalide ou expiré'; showError(isInvalid ? '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; } }