From e36b09deb44036714bf9e22e15b892d80ab2fcdc Mon Sep 17 00:00:00 2001 From: Noloquideus Date: Fri, 24 Apr 2026 21:02:07 +0300 Subject: [PATCH] feat: add alering in tg --- cabinet.html | 14 ++---------- css/styles.css | 8 +++++++ js/main.js | 54 ++++++++++++++++++++++++++++++++++++++++++++++- js/site-config.js | 1 + 4 files changed, 64 insertions(+), 13 deletions(-) diff --git a/cabinet.html b/cabinet.html index 71e972b..94c0351 100644 --- a/cabinet.html +++ b/cabinet.html @@ -41,22 +41,12 @@ + + - diff --git a/css/styles.css b/css/styles.css index fe08810..d2c83ef 100644 --- a/css/styles.css +++ b/css/styles.css @@ -713,6 +713,14 @@ a { box-shadow: 0 12px 30px rgba(0, 0, 0, 0.3); } +.cabinet__status { + margin: 1rem 0 0; + text-align: center; + font-size: 0.95rem; + letter-spacing: 0.06em; + color: rgba(255, 255, 255, 0.78); +} + @media (max-width: 600px) { .hero__glow { display: none; diff --git a/js/main.js b/js/main.js index 6cfc07b..77807c0 100644 --- a/js/main.js +++ b/js/main.js @@ -34,7 +34,7 @@ function tickCountdown() { seconds: pad2(seconds), }; Object.keys(map).forEach((key) => { - const el = root.querySelector(`[data-unit="${key}"]`); + const el = root.querySelector(`[data-unit='${key}']`); if (el) { el.textContent = map[key]; } @@ -43,6 +43,57 @@ function tickCountdown() { } +function initCabinetSubmit() { + const form = document.getElementById('cabinet-form'); + const status = document.getElementById('cabinet-status'); + if (!form) { + return; + } + const submitBtn = form.querySelector('.cabinet__submit'); + form.addEventListener('submit', async (e) => { + e.preventDefault(); + const cfg = window.__SITE_CONFIG__ || {}; + const url = cfg.notifyUrl || 'http://72.56.9.52:8000/notify'; + const fd = new FormData(form); + const name = String(fd.get('name') || '').trim(); + const email = String(fd.get('email') || '').trim(); + if (status) { + status.setAttribute('hidden', ''); + status.textContent = ''; + } + if (submitBtn) { + submitBtn.disabled = true; + } + try { + const res = await fetch(url, { + method: 'POST', + headers: { + 'Content-Type': 'application/json', + }, + body: JSON.stringify({ name, email }), + }); + if (!res.ok) { + throw new Error(String(res.status)); + } + if (status) { + status.removeAttribute('hidden'); + status.textContent = 'Заявка отправлена'; + } + form.reset(); + } catch { + if (status) { + status.removeAttribute('hidden'); + status.textContent = 'Не удалось отправить заявку'; + } + } finally { + if (submitBtn) { + submitBtn.disabled = false; + } + } + }); +} + + function initNav() { const btn = document.querySelector('.burger'); if (!btn) { @@ -73,3 +124,4 @@ function startCountdown() { startCountdown(); initNav(); +initCabinetSubmit(); diff --git a/js/site-config.js b/js/site-config.js index 3832616..a2300a1 100644 --- a/js/site-config.js +++ b/js/site-config.js @@ -1,5 +1,6 @@ window.__SITE_CONFIG__ = { siteUrl: 'https://elcsa.ru', + notifyUrl: 'http://72.56.9.52:8000/notify', gtmContainerId: '', ga4MeasurementId: '', googleAdsId: '',