feat: add alering in tg

This commit is contained in:
2026-04-24 21:02:07 +03:00
parent 06a35b10cf
commit e36b09deb4
4 changed files with 64 additions and 13 deletions

View File

@@ -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();