feat(ReserverController): Crée la logique d'enregistrement client et envoie un email de bienvenue.
```
This commit is contained in:
Serreau Jovann
2026-01-23 09:25:11 +01:00
parent ab3fba7a9c
commit 59a1989076
4 changed files with 272 additions and 97 deletions

View File

@@ -1,111 +1,77 @@
import './reserve.scss';
// On ne fait plus d'import statique de Sentry ici
import {UtmEvent, UtmAccount} from "./tools/UtmEvent.js";
import { UtmEvent, UtmAccount } from "./tools/UtmEvent.js";
import * as Turbo from "@hotwired/turbo";
// --- DÉTECTION BOT / PERFORMANCE ---
const isLighthouse = () => {
// Check if navigator and userAgent are available
if (!navigator || !navigator.userAgent) {
return false;
}
// Normalize the user agent to lowercase for robust matching
if (typeof navigator === 'undefined' || !navigator.userAgent) return false;
const userAgent = navigator.userAgent.toLowerCase();
// Comprehensive array of Lighthouse-related user agent patterns
const lighthousePatterns = [
'chrome-lighthouse',
'google/lighthouse',
'lighthouse',
'pagespeed',
'pagespeedinsights',
'googleads-lighthouse',
'headless',
'webdriver'
];
// Use some() to check if any pattern exists in the user agent
return lighthousePatterns.some(pattern =>
userAgent.includes(pattern)
);
const patterns = ['chrome-lighthouse', 'google/lighthouse', 'lighthouse', 'pagespeed', 'headless', 'webdriver'];
return patterns.some(pattern => userAgent.includes(pattern));
};
// --- INITIALISATION SENTRY (OPTIMISÉE BOT/LIGHTHOUSE) ---
const initSentry = async () => {
// On vérifie si on n'est pas un bot (la variable est passée par le PHP/Twig ou détectée en JS)
if (!isLighthouse()) {
// --- INITIALISATION SENTRY ---
const initSentry = async () => {
if (!isLighthouse() && !window.SentryInitialized) {
try {
const Sentry = await import("@sentry/browser");
Sentry.init({
dsn: "https://803814be6540031b1c37bf92ba9c0f79@sentry.esy-web.dev/24",
tunnel: "/sentry-tunnel",
integrations: [Sentry.browserTracingIntegration()],
tracesSampleRate: 1.0,
});
window.SentryInitialized = true; // Empêche la ré-initialisation
} catch (e) {
console.warn("Sentry load failed", e);
}
}
};
// --- LOGIQUE DU REDIRECT ---
const initAutoRedirect = () => {
const container = document.getElementById('payment-check-container');
if (container && container.dataset.autoRedirect) {
const url = container.dataset.autoRedirect;
setTimeout(() => {
if (document.getElementById('payment-check-container')) {
Turbo.visit(url);
}
}, 10000);
}
}
// --- LOGIQUE DU LOADER TURBO ---
// --- LOGIQUE DU LOADER TURBO (Unique à travers les pages) ---
const initLoader = () => {
let loaderEl = document.getElementById('turbo-loader');
if (!loaderEl) {
loaderEl = document.createElement('div');
loaderEl.id = 'turbo-loader';
loaderEl.className = 'fixed inset-0 z-[9999] flex items-center justify-center bg-white transition-opacity duration-300 opacity-0 pointer-events-none';
loaderEl.innerHTML = `
<div class="relative flex items-center justify-center">
<div class="absolute w-24 h-24 border-4 border-blue-600 border-t-transparent rounded-full animate-spin"></div>
<img src="/provider/images/favicon.webp" class="w-12 h-12 relative z-10 animate-pulse" alt="Logo">
</div>
`;
document.body.appendChild(loaderEl);
}
if (document.getElementById('turbo-loader')) return;
const showLoader = () => {
loaderEl.classList.remove('opacity-0', 'pointer-events-none');
loaderEl.classList.add('opacity-100');
};
const loaderEl = document.createElement('div');
loaderEl.id = 'turbo-loader';
loaderEl.className = 'fixed inset-0 z-[9999] flex items-center justify-center bg-white transition-opacity duration-300 opacity-0 pointer-events-none';
loaderEl.innerHTML = `
<div class="relative flex items-center justify-center">
<div class="absolute w-24 h-24 border-4 border-blue-600 border-t-transparent rounded-full animate-spin"></div>
<img src="/provider/images/favicon.webp" class="w-12 h-12 relative z-10 animate-pulse" alt="Logo">
</div>
`;
document.body.appendChild(loaderEl);
document.addEventListener("turbo:click", () => {
loaderEl.classList.replace('opacity-0', 'opacity-100');
loaderEl.classList.remove('pointer-events-none');
});
const hideLoader = () => {
setTimeout(() => {
loaderEl.classList.remove('opacity-100');
loaderEl.classList.add('opacity-0', 'pointer-events-none');
loaderEl.classList.replace('opacity-100', 'opacity-0');
loaderEl.classList.add('pointer-events-none');
}, 300);
};
document.addEventListener("turbo:click", showLoader);
document.addEventListener("turbo:submit-start", showLoader);
document.addEventListener("turbo:load", hideLoader);
document.addEventListener("turbo:render", hideLoader);
};
// --- LOGIQUE DU MENU MOBILE ---
// --- LOGIQUE DU MENU MOBILE (Compatible Turbo) ---
const initMobileMenu = () => {
const btn = document.getElementById('menu-button');
const menu = document.getElementById('mobile-menu');
if (btn && menu) {
btn.onclick = () => {
// On enlève l'ancien listener pour éviter les doublons au retour arrière
btn.onclick = null;
btn.addEventListener('click', () => {
const isExpanded = btn.getAttribute('aria-expanded') === 'true';
btn.setAttribute('aria-expanded', !isExpanded);
menu.classList.toggle('hidden');
};
});
}
};
@@ -115,56 +81,90 @@ const initCatalogueSearch = () => {
const products = document.querySelectorAll('.product-item');
const emptyMsg = document.getElementById('empty-msg');
if (!filters.length) return;
if (filters.length === 0) return;
filters.forEach(btn => {
btn.onclick = () => {
const category = btn.getAttribute('data-filter').toLowerCase();
let count = 0;
filters.forEach(f => {
f.classList.remove('bg-slate-900', 'text-white');
f.classList.add('bg-white', 'text-slate-500');
});
btn.classList.add('bg-slate-900', 'text-white');
btn.classList.remove('bg-white', 'text-slate-500');
// Update UI des filtres
filters.forEach(f => f.classList.replace('bg-slate-900', 'bg-white'));
filters.forEach(f => f.classList.replace('text-white', 'text-slate-500'));
btn.classList.replace('bg-white', 'bg-slate-900');
btn.classList.replace('text-slate-500', 'text-white');
// Filtrage des produits
products.forEach(item => {
const itemCat = item.getAttribute('data-category').toLowerCase();
if (category === 'all' || itemCat.includes(category)) {
item.style.display = 'block';
count++;
} else {
item.style.display = 'none';
}
const isVisible = category === 'all' || itemCat.includes(category);
item.style.display = isVisible ? 'block' : 'none';
if (isVisible) count++;
});
if (emptyMsg) {
count === 0 ? emptyMsg.classList.remove('hidden') : emptyMsg.classList.add('hidden');
}
if (emptyMsg) count === 0 ? emptyMsg.classList.remove('hidden') : emptyMsg.classList.add('hidden');
};
});
};
// --- INITIALISATION ---
document.addEventListener('DOMContentLoaded', () => {
initSentry(); // Appel asynchrone de Sentry
initLoader();
initMobileMenu();
initCatalogueSearch();
initAutoRedirect();
// --- LOGIQUE DU REDIRECT ---
const initAutoRedirect = () => {
const container = document.getElementById('payment-check-container');
if (container && container.dataset.autoRedirect) {
const url = container.dataset.autoRedirect;
setTimeout(() => {
// On vérifie que l'utilisateur est toujours sur la page de paiement
if (document.getElementById('payment-check-container')) {
Turbo.visit(url);
}
}, 10000);
}
}
const initRegisterLogic = () => {
const siretContainer = document.getElementById('siret-container');
const typeRadios = document.querySelectorAll('input[name="type"]');
if (!siretContainer || typeRadios.length === 0) return;
const updateSiretVisibility = () => {
const selectedType = document.querySelector('input[name="type"]:checked')?.value;
if (selectedType === 'buisness') {
siretContainer.classList.remove('hidden');
siretContainer.querySelector('input')?.setAttribute('required', 'required');
} else {
siretContainer.classList.add('hidden');
siretContainer.querySelector('input')?.removeAttribute('required');
}
};
typeRadios.forEach(radio => {
radio.addEventListener('change', updateSiretVisibility);
});
// Initialisation au chargement (si redirection avec erreur par exemple)
updateSiretVisibility();
};
// --- INITIALISATION GLOBALE ---
document.addEventListener('DOMContentLoaded', () => {
initSentry();
initLoader();
// Custom Elements (une seule fois suffit)
if (!customElements.get('utm-event')) customElements.define('utm-event', UtmEvent);
if (!customElements.get('utm-account')) customElements.define('utm-account', UtmAccount);
});
// À chaque changement de page Turbo
document.addEventListener('turbo:load', () => {
initMobileMenu();
initCatalogueSearch();
initAutoRedirect();
initRegisterLogic();
});
// Nettoyage avant la mise en cache de Turbo (évite les bugs visuels au retour arrière)
document.addEventListener("turbo:before-cache", () => {
document.querySelectorAll('.product-item').forEach(i => i.style.display = 'block');
if (document.getElementById('empty-msg')) document.getElementById('empty-msg').classList.add('hidden');
const emptyMsg = document.getElementById('empty-msg');
if (emptyMsg) emptyMsg.classList.add('hidden');
});