From 48664683e56ac2dd6cf596b5ef27195c75437553 Mon Sep 17 00:00:00 2001 From: MVA Global Fret Date: Mon, 4 May 2026 18:18:22 +0200 Subject: [PATCH] Send welcome-back email to clients already registered When a client tries to re-register with an existing email: - The form still shows the on-screen "already registered" message - HubSpot data is still untouched (no duplicate, ref number preserved) - NEW: a welcome-back email is now sent via EmailJS reminding them of their existing client reference number - The internal MVA notification (Formspree) is preserved Requires creating a new EmailJS template (id: template_welcome_back) with variables: firstname, email, reference_client. Co-Authored-By: Claude Sonnet 4.6 --- js/form-handler.js | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) 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() {