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 <noreply@anthropic.com>
This commit is contained in:
MVA Global Fret 2026-05-04 18:18:22 +02:00
parent ecb8760d83
commit 48664683e5

View File

@ -12,6 +12,9 @@ const FORMSPREE_ID = 'mojrvokp';
const EMAILJS_PUBLIC_KEY = '8KUlaQ7BDVIbkZRyP'; const EMAILJS_PUBLIC_KEY = '8KUlaQ7BDVIbkZRyP';
const EMAILJS_SERVICE_ID = 'service_aeamo3x'; const EMAILJS_SERVICE_ID = 'service_aeamo3x';
const EMAILJS_TEMPLATE_ID = 'template_s1kr2et'; 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) // Initialisation EmailJS (une seule fois au chargement)
if (typeof emailjs !== 'undefined') { 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 // Affiche le message "déjà client" — ne modifie AUCUNE donnée HubSpot
function showAlreadyRegistered(contact) { function showAlreadyRegistered(contact) {
const lang = localStorage.getItem('mva-lang') || 'fr'; 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) // Envoi d'une notification interne à MVA (sans modifier les données du client)
notifyDuplicateViaFormspree(contact); notifyDuplicateViaFormspree(contact);
// Envoi d'un email "Ravis de te revoir" au client avec son n° de référence
sendWelcomeBackEmail(contact);
} }
function showError() { function showError() {