diff --git a/js/form-handler.js b/js/form-handler.js index 2e0e6c6..8754583 100644 --- a/js/form-handler.js +++ b/js/form-handler.js @@ -12,6 +12,9 @@ const FORMSPREE_ID = 'mojrvokp'; const EMAILJS_PUBLIC_KEY = '8KUlaQ7BDVIbkZRyP'; const EMAILJS_SERVICE_ID = 'service_aeamo3x'; const EMAILJS_TEMPLATE_ID = 'template_s1kr2et'; +// Template pour les clients déjà inscrits ("Ravis de te revoir") +// ⚠️ À créer dans EmailJS puis remplacer la valeur ci-dessous +const EMAILJS_TEMPLATE_WELCOME_BACK = 'template_welcome_back'; // Initialisation EmailJS (une seule fois au chargement) if (typeof emailjs !== 'undefined') { @@ -301,6 +304,23 @@ async function sendWelcomeEmail(data) { } } +// ── EMAIL "RAVIS DE TE REVOIR" (client déjà inscrit) ────────────────────────── +// Rappelle au client son numéro de référence existant — n'écrit RIEN dans HubSpot. +async function sendWelcomeBackEmail(contact) { + if (typeof emailjs === 'undefined') return; + if (!contact || !contact.email) return; + try { + await emailjs.send(EMAILJS_SERVICE_ID, EMAILJS_TEMPLATE_WELCOME_BACK, { + firstname: contact.firstname || '', + email: contact.email, + reference_client: contact.reference_client || '', + }); + } catch (err) { + // Si le template n'existe pas encore ou erreur réseau : on n'interrompt rien + console.warn('EmailJS welcome-back email failed:', err); + } +} + // Affiche le message "déjà client" — ne modifie AUCUNE donnée HubSpot function showAlreadyRegistered(contact) { const lang = localStorage.getItem('mva-lang') || 'fr'; @@ -326,6 +346,9 @@ function showAlreadyRegistered(contact) { // Envoi d'une notification interne à MVA (sans modifier les données du client) notifyDuplicateViaFormspree(contact); + + // Envoi d'un email "Ravis de te revoir" au client avec son n° de référence + sendWelcomeBackEmail(contact); } function showError() {