feat(site): route contact form to crm direct
This commit is contained in:
@@ -41,7 +41,6 @@ const defaultMailtoHref = `mailto:contact@lelectronrare.fr?subject=${encodeURICo
|
|||||||
Réponse sous 48h avec un premier retour technique.
|
Réponse sous 48h avec un premier retour technique.
|
||||||
</p>
|
</p>
|
||||||
|
|
||||||
<!-- Tab switcher -->
|
|
||||||
<div class="contact-minitel-tabs">
|
<div class="contact-minitel-tabs">
|
||||||
<button
|
<button
|
||||||
type="button"
|
type="button"
|
||||||
@@ -59,7 +58,6 @@ const defaultMailtoHref = `mailto:contact@lelectronrare.fr?subject=${encodeURICo
|
|||||||
</button>
|
</button>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<!-- Tab: mailto draft -->
|
|
||||||
<div data-contact-panel="email">
|
<div data-contact-panel="email">
|
||||||
<div class="contact-minitel-textarea-wrap">
|
<div class="contact-minitel-textarea-wrap">
|
||||||
<label for="contact-draft" class="contact-minitel-label">> MESSAGE :</label>
|
<label for="contact-draft" class="contact-minitel-label">> MESSAGE :</label>
|
||||||
@@ -99,33 +97,65 @@ const defaultMailtoHref = `mailto:contact@lelectronrare.fr?subject=${encodeURICo
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<!-- Tab: Web3Forms contact form -->
|
|
||||||
<div data-contact-panel="form" style="display:none;">
|
<div data-contact-panel="form" style="display:none;">
|
||||||
<!-- Form (idle/sending/error states) -->
|
|
||||||
<div id="contact-form-container">
|
<div id="contact-form-container">
|
||||||
<form id="contact-web3form">
|
<form id="contact-crm-form" class="contact-minitel-form">
|
||||||
<div class="contact-minitel-textarea-wrap">
|
<div class="contact-minitel-field">
|
||||||
<label for="contact-form-name" class="contact-minitel-label">> NOM :</label>
|
<label for="contact-form-name" class="contact-minitel-label">> NOM :</label>
|
||||||
<input
|
<input
|
||||||
id="contact-form-name"
|
id="contact-form-name"
|
||||||
type="text"
|
type="text"
|
||||||
required
|
required
|
||||||
class="contact-minitel-textarea"
|
class="contact-minitel-input"
|
||||||
style="height:auto;min-height:2.4em;resize:none"
|
autocomplete="name"
|
||||||
placeholder="Votre nom"
|
placeholder="Votre nom"
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
<div class="contact-minitel-textarea-wrap">
|
|
||||||
|
<div class="contact-minitel-field">
|
||||||
<label for="contact-form-email" class="contact-minitel-label">> EMAIL :</label>
|
<label for="contact-form-email" class="contact-minitel-label">> EMAIL :</label>
|
||||||
<input
|
<input
|
||||||
id="contact-form-email"
|
id="contact-form-email"
|
||||||
type="email"
|
type="email"
|
||||||
required
|
required
|
||||||
class="contact-minitel-textarea"
|
class="contact-minitel-input"
|
||||||
style="height:auto;min-height:2.4em;resize:none"
|
autocomplete="email"
|
||||||
placeholder="votre@email.com"
|
placeholder="votre@email.com"
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
<div class="contact-minitel-field">
|
||||||
|
<label for="contact-form-phone" class="contact-minitel-label">> TELEPHONE :</label>
|
||||||
|
<input
|
||||||
|
id="contact-form-phone"
|
||||||
|
type="tel"
|
||||||
|
class="contact-minitel-input"
|
||||||
|
autocomplete="tel"
|
||||||
|
placeholder="Optionnel"
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="contact-minitel-field">
|
||||||
|
<label for="contact-form-organization" class="contact-minitel-label">> STRUCTURE :</label>
|
||||||
|
<input
|
||||||
|
id="contact-form-organization"
|
||||||
|
type="text"
|
||||||
|
class="contact-minitel-input"
|
||||||
|
autocomplete="organization"
|
||||||
|
placeholder="Entreprise, atelier, compagnie, studio..."
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="contact-minitel-field">
|
||||||
|
<label for="contact-form-need-type" class="contact-minitel-label">> BESOIN :</label>
|
||||||
|
<select id="contact-form-need-type" class="contact-minitel-select" required>
|
||||||
|
<option value="" selected disabled>Choisir le type de besoin</option>
|
||||||
|
<option value="technique">Projet technique</option>
|
||||||
|
<option value="formation">Formation</option>
|
||||||
|
<option value="mixte">Projet mixte</option>
|
||||||
|
</select>
|
||||||
|
</div>
|
||||||
|
|
||||||
<div class="contact-minitel-textarea-wrap">
|
<div class="contact-minitel-textarea-wrap">
|
||||||
<label for="contact-form-message" class="contact-minitel-label">> MESSAGE :</label>
|
<label for="contact-form-message" class="contact-minitel-label">> MESSAGE :</label>
|
||||||
<textarea
|
<textarea
|
||||||
@@ -136,6 +166,14 @@ const defaultMailtoHref = `mailto:contact@lelectronrare.fr?subject=${encodeURICo
|
|||||||
rows="8"
|
rows="8"
|
||||||
>{DEFAULT_MESSAGE}</textarea>
|
>{DEFAULT_MESSAGE}</textarea>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
<label class="contact-minitel-consent" for="contact-form-consent">
|
||||||
|
<input id="contact-form-consent" type="checkbox" required />
|
||||||
|
<span class="contact-minitel-consent-text">
|
||||||
|
J'accepte que mes coordonnees soient utilisees pour traiter cette demande.
|
||||||
|
</span>
|
||||||
|
</label>
|
||||||
|
|
||||||
<div class="contact-minitel-actions">
|
<div class="contact-minitel-actions">
|
||||||
<button
|
<button
|
||||||
type="submit"
|
type="submit"
|
||||||
@@ -155,10 +193,9 @@ const defaultMailtoHref = `mailto:contact@lelectronrare.fr?subject=${encodeURICo
|
|||||||
</form>
|
</form>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<!-- Success state -->
|
|
||||||
<div id="contact-form-success" style="display:none;">
|
<div id="contact-form-success" style="display:none;">
|
||||||
<p class="contact-minitel-line" style="text-align:center;padding:2rem 0">
|
<p class="contact-minitel-line" style="text-align:center;padding:2rem 0">
|
||||||
> MESSAGE ENVOYÉ ✓
|
> MESSAGE ENVOYE ✓
|
||||||
</p>
|
</p>
|
||||||
<p class="contact-minitel-line contact-minitel-line--dim" style="text-align:center">
|
<p class="contact-minitel-line contact-minitel-line--dim" style="text-align:center">
|
||||||
Merci ! Je reviens vers vous sous 48h.
|
Merci ! Je reviens vers vous sous 48h.
|
||||||
@@ -180,7 +217,7 @@ const defaultMailtoHref = `mailto:contact@lelectronrare.fr?subject=${encodeURICo
|
|||||||
─────────────────────────────────────────
|
─────────────────────────────────────────
|
||||||
</p>
|
</p>
|
||||||
<p class="contact-minitel-line contact-minitel-line--dim">
|
<p class="contact-minitel-line contact-minitel-line--dim">
|
||||||
Électronique · automatisme · énergie · diagnostic · formation
|
Electronique · automatisme · energie · diagnostic · formation
|
||||||
</p>
|
</p>
|
||||||
<p class="contact-minitel-line">
|
<p class="contact-minitel-line">
|
||||||
Mail direct : <a href="mailto:contact@lelectronrare.fr" class="contact-minitel-link">contact@lelectronrare.fr</a>
|
Mail direct : <a href="mailto:contact@lelectronrare.fr" class="contact-minitel-link">contact@lelectronrare.fr</a>
|
||||||
@@ -191,8 +228,7 @@ const defaultMailtoHref = `mailto:contact@lelectronrare.fr?subject=${encodeURICo
|
|||||||
</section>
|
</section>
|
||||||
|
|
||||||
<script>
|
<script>
|
||||||
const WEB3FORMS_ACCESS_KEY = 'YOUR_ACCESS_KEY_HERE';
|
const CRM_INTAKE_ENDPOINT = 'https://electron.saillant.cc/api/intake/lead';
|
||||||
const WEB3FORMS_ENDPOINT = 'https://api.web3forms.com/submit';
|
|
||||||
const DEFAULT_MESSAGE = `Bonjour Clément,
|
const DEFAULT_MESSAGE = `Bonjour Clément,
|
||||||
|
|
||||||
J'ai un projet / besoin autour d'un système électronique spécifique.
|
J'ai un projet / besoin autour d'un système électronique spécifique.
|
||||||
@@ -201,19 +237,34 @@ Contexte :
|
|||||||
Ce que j'attends :
|
Ce que j'attends :
|
||||||
Contraintes (délai, budget) :`;
|
Contraintes (délai, budget) :`;
|
||||||
|
|
||||||
// --- Tab switching ---
|
const trackingWindow = window as Window & { dataLayer?: Array<Record<string, unknown>> };
|
||||||
|
|
||||||
|
const pushTrackingEvent = (eventName: string, payload: Record<string, unknown> = {}) => {
|
||||||
|
trackingWindow.dataLayer = trackingWindow.dataLayer || [];
|
||||||
|
trackingWindow.dataLayer.push({
|
||||||
|
event: eventName,
|
||||||
|
event_category: 'engagement',
|
||||||
|
event_label: eventName,
|
||||||
|
page_path: window.location.pathname || '/',
|
||||||
|
page_title: document.title || '',
|
||||||
|
da_variant: document.documentElement.getAttribute('data-da-variant') || 'v12',
|
||||||
|
...payload,
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
const tabButtons = document.querySelectorAll<HTMLButtonElement>('[data-contact-tab]');
|
const tabButtons = document.querySelectorAll<HTMLButtonElement>('[data-contact-tab]');
|
||||||
const panels = document.querySelectorAll<HTMLElement>('[data-contact-panel]');
|
const panels = document.querySelectorAll<HTMLElement>('[data-contact-panel]');
|
||||||
|
|
||||||
tabButtons.forEach((btn) => {
|
tabButtons.forEach((btn) => {
|
||||||
btn.addEventListener('click', () => {
|
btn.addEventListener('click', () => {
|
||||||
const target = btn.dataset.contactTab!;
|
const target = btn.dataset.contactTab!;
|
||||||
tabButtons.forEach((b) => b.classList.toggle('contact-minitel-tab--active', b.dataset.contactTab === target));
|
tabButtons.forEach((button) => button.classList.toggle('contact-minitel-tab--active', button.dataset.contactTab === target));
|
||||||
panels.forEach((p) => { p.style.display = p.dataset.contactPanel === target ? '' : 'none'; });
|
panels.forEach((panel) => {
|
||||||
|
panel.style.display = panel.dataset.contactPanel === target ? '' : 'none';
|
||||||
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
// --- Mailto draft ---
|
|
||||||
const draftArea = document.getElementById('contact-draft') as HTMLTextAreaElement;
|
const draftArea = document.getElementById('contact-draft') as HTMLTextAreaElement;
|
||||||
const mailtoLink = document.getElementById('contact-mailto-link') as HTMLAnchorElement;
|
const mailtoLink = document.getElementById('contact-mailto-link') as HTMLAnchorElement;
|
||||||
|
|
||||||
@@ -225,69 +276,108 @@ Contraintes (délai, budget) :`;
|
|||||||
|
|
||||||
draftArea.addEventListener('input', updateMailtoHref);
|
draftArea.addEventListener('input', updateMailtoHref);
|
||||||
|
|
||||||
// --- Clipboard copy ---
|
|
||||||
const copyBtn = document.getElementById('contact-copy-btn') as HTMLButtonElement;
|
const copyBtn = document.getElementById('contact-copy-btn') as HTMLButtonElement;
|
||||||
copyBtn.addEventListener('click', async () => {
|
copyBtn.addEventListener('click', async () => {
|
||||||
try {
|
try {
|
||||||
await navigator.clipboard.writeText(draftArea.value);
|
await navigator.clipboard.writeText(draftArea.value);
|
||||||
copyBtn.textContent = '[OK] Message copié ✓';
|
copyBtn.textContent = '[OK] Message copie ✓';
|
||||||
setTimeout(() => { copyBtn.textContent = '[COPIE] Copier le message'; }, 1800);
|
setTimeout(() => {
|
||||||
|
copyBtn.textContent = '[COPIE] Copier le message';
|
||||||
|
}, 1800);
|
||||||
} catch {
|
} catch {
|
||||||
// Silently fail — clipboard API may not be available
|
// Silently fail — clipboard API may not be available.
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
// --- Web3Forms submission ---
|
const form = document.getElementById('contact-crm-form') as HTMLFormElement;
|
||||||
const form = document.getElementById('contact-web3form') as HTMLFormElement;
|
|
||||||
const formContainer = document.getElementById('contact-form-container') as HTMLElement;
|
const formContainer = document.getElementById('contact-form-container') as HTMLElement;
|
||||||
const formSuccess = document.getElementById('contact-form-success') as HTMLElement;
|
const formSuccess = document.getElementById('contact-form-success') as HTMLElement;
|
||||||
const formError = document.getElementById('contact-form-error') as HTMLElement;
|
const formError = document.getElementById('contact-form-error') as HTMLElement;
|
||||||
const submitBtn = document.getElementById('contact-form-submit') as HTMLButtonElement;
|
const submitBtn = document.getElementById('contact-form-submit') as HTMLButtonElement;
|
||||||
const nameInput = document.getElementById('contact-form-name') as HTMLInputElement;
|
const nameInput = document.getElementById('contact-form-name') as HTMLInputElement;
|
||||||
const emailInput = document.getElementById('contact-form-email') as HTMLInputElement;
|
const emailInput = document.getElementById('contact-form-email') as HTMLInputElement;
|
||||||
|
const phoneInput = document.getElementById('contact-form-phone') as HTMLInputElement;
|
||||||
|
const organizationInput = document.getElementById('contact-form-organization') as HTMLInputElement;
|
||||||
|
const needTypeInput = document.getElementById('contact-form-need-type') as HTMLSelectElement;
|
||||||
const messageArea = document.getElementById('contact-form-message') as HTMLTextAreaElement;
|
const messageArea = document.getElementById('contact-form-message') as HTMLTextAreaElement;
|
||||||
|
const consentInput = document.getElementById('contact-form-consent') as HTMLInputElement;
|
||||||
|
|
||||||
form.addEventListener('submit', async (e) => {
|
const resetContactForm = () => {
|
||||||
e.preventDefault();
|
nameInput.value = '';
|
||||||
|
emailInput.value = '';
|
||||||
|
phoneInput.value = '';
|
||||||
|
organizationInput.value = '';
|
||||||
|
needTypeInput.value = '';
|
||||||
|
messageArea.value = DEFAULT_MESSAGE;
|
||||||
|
consentInput.checked = false;
|
||||||
|
};
|
||||||
|
|
||||||
|
form.addEventListener('submit', async (event) => {
|
||||||
|
event.preventDefault();
|
||||||
formError.style.display = 'none';
|
formError.style.display = 'none';
|
||||||
|
formError.textContent = "> Erreur d'envoi. Essayez via l'onglet [1] ou par mail direct.";
|
||||||
submitBtn.disabled = true;
|
submitBtn.disabled = true;
|
||||||
submitBtn.textContent = '[...] Envoi en cours...';
|
submitBtn.textContent = '[...] Envoi en cours...';
|
||||||
|
|
||||||
|
const payload = {
|
||||||
|
name: nameInput.value.trim(),
|
||||||
|
email: emailInput.value.trim(),
|
||||||
|
phone: phoneInput.value.trim() || undefined,
|
||||||
|
organization: organizationInput.value.trim() || undefined,
|
||||||
|
message: messageArea.value.trim(),
|
||||||
|
sourceChannel: 'site',
|
||||||
|
sourceDetail: 'contact_form',
|
||||||
|
needType: needTypeInput.value,
|
||||||
|
pagePath: `${window.location.pathname || '/'}${window.location.hash || ''}`,
|
||||||
|
consent: consentInput.checked,
|
||||||
|
};
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const res = await fetch(WEB3FORMS_ENDPOINT, {
|
const response = await fetch(CRM_INTAKE_ENDPOINT, {
|
||||||
method: 'POST',
|
method: 'POST',
|
||||||
headers: { 'Content-Type': 'application/json' },
|
headers: { 'Content-Type': 'application/json' },
|
||||||
body: JSON.stringify({
|
body: JSON.stringify(payload),
|
||||||
access_key: WEB3FORMS_ACCESS_KEY,
|
|
||||||
subject: `Contact lelectronrare.fr — ${nameInput.value}`,
|
|
||||||
from_name: nameInput.value,
|
|
||||||
email: emailInput.value,
|
|
||||||
message: messageArea.value,
|
|
||||||
}),
|
|
||||||
});
|
});
|
||||||
|
const result = await response.json().catch(() => null);
|
||||||
|
|
||||||
if (res.ok) {
|
if (response.ok) {
|
||||||
formContainer.style.display = 'none';
|
formContainer.style.display = 'none';
|
||||||
formSuccess.style.display = '';
|
formSuccess.style.display = '';
|
||||||
// Reset fields for next use
|
pushTrackingEvent('contact_form_submit', {
|
||||||
nameInput.value = '';
|
destination: CRM_INTAKE_ENDPOINT,
|
||||||
emailInput.value = '';
|
source_detail: payload.sourceDetail,
|
||||||
messageArea.value = DEFAULT_MESSAGE;
|
need_type: payload.needType,
|
||||||
|
});
|
||||||
|
resetContactForm();
|
||||||
} else {
|
} else {
|
||||||
|
const detail = result?.error?.message || result?.error?.code;
|
||||||
|
formError.textContent = detail
|
||||||
|
? `> ${detail}. Essayez via l'onglet [1] ou par mail direct.`
|
||||||
|
: "> Erreur d'envoi. Essayez via l'onglet [1] ou par mail direct.";
|
||||||
formError.style.display = '';
|
formError.style.display = '';
|
||||||
|
pushTrackingEvent('contact_form_error', {
|
||||||
|
destination: CRM_INTAKE_ENDPOINT,
|
||||||
|
source_detail: payload.sourceDetail,
|
||||||
|
status_code: response.status,
|
||||||
|
});
|
||||||
}
|
}
|
||||||
} catch {
|
} catch {
|
||||||
formError.style.display = '';
|
formError.style.display = '';
|
||||||
|
pushTrackingEvent('contact_form_error', {
|
||||||
|
destination: CRM_INTAKE_ENDPOINT,
|
||||||
|
source_detail: payload.sourceDetail,
|
||||||
|
status_code: 'network_error',
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
submitBtn.disabled = false;
|
submitBtn.disabled = false;
|
||||||
submitBtn.textContent = '[ENVOI] Envoyer le message';
|
submitBtn.textContent = '[ENVOI] Envoyer le message';
|
||||||
});
|
});
|
||||||
|
|
||||||
// --- Reset form (back from success) ---
|
|
||||||
const resetBtn = document.getElementById('contact-form-reset') as HTMLButtonElement;
|
const resetBtn = document.getElementById('contact-form-reset') as HTMLButtonElement;
|
||||||
resetBtn.addEventListener('click', () => {
|
resetBtn.addEventListener('click', () => {
|
||||||
formSuccess.style.display = 'none';
|
formSuccess.style.display = 'none';
|
||||||
formContainer.style.display = '';
|
formContainer.style.display = '';
|
||||||
|
formError.style.display = 'none';
|
||||||
});
|
});
|
||||||
</script>
|
</script>
|
||||||
|
|||||||
@@ -5010,6 +5010,28 @@ input.contact-minitel-textarea:focus {
|
|||||||
margin-bottom: 0.8rem;
|
margin-bottom: 0.8rem;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.contact-minitel-consent {
|
||||||
|
display: flex;
|
||||||
|
gap: 0.7rem;
|
||||||
|
align-items: flex-start;
|
||||||
|
margin-top: 0.2rem;
|
||||||
|
color: rgba(224, 247, 247, 0.82);
|
||||||
|
font-size: 0.82rem;
|
||||||
|
line-height: 1.5;
|
||||||
|
}
|
||||||
|
|
||||||
|
.contact-minitel-consent input {
|
||||||
|
inline-size: 1rem;
|
||||||
|
block-size: 1rem;
|
||||||
|
margin-top: 0.15rem;
|
||||||
|
accent-color: #5bd1d8;
|
||||||
|
flex: 0 0 auto;
|
||||||
|
}
|
||||||
|
|
||||||
|
.contact-minitel-consent-text {
|
||||||
|
flex: 1 1 auto;
|
||||||
|
}
|
||||||
|
|
||||||
.contact-minitel-input,
|
.contact-minitel-input,
|
||||||
.contact-minitel-select {
|
.contact-minitel-select {
|
||||||
width: 100%;
|
width: 100%;
|
||||||
|
|||||||
Reference in New Issue
Block a user