feat: add alering in tg
This commit is contained in:
14
cabinet.html
14
cabinet.html
@@ -41,22 +41,12 @@
|
|||||||
</label>
|
</label>
|
||||||
<button class='cabinet__submit' type='submit'>Оставить заявку</button>
|
<button class='cabinet__submit' type='submit'>Оставить заявку</button>
|
||||||
</form>
|
</form>
|
||||||
|
<p class='cabinet__status' id='cabinet-status' hidden></p>
|
||||||
</section>
|
</section>
|
||||||
</div>
|
</div>
|
||||||
</main>
|
</main>
|
||||||
</div>
|
</div>
|
||||||
|
<script src='js/site-config.js'></script>
|
||||||
<script src='js/main.js' defer></script>
|
<script src='js/main.js' defer></script>
|
||||||
<script>
|
|
||||||
document.addEventListener('DOMContentLoaded', () => {
|
|
||||||
const f = document.getElementById('cabinet-form');
|
|
||||||
if (!f) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
f.addEventListener('submit', (e) => {
|
|
||||||
e.preventDefault();
|
|
||||||
f.reset();
|
|
||||||
});
|
|
||||||
});
|
|
||||||
</script>
|
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
||||||
|
|||||||
@@ -713,6 +713,14 @@ a {
|
|||||||
box-shadow: 0 12px 30px rgba(0, 0, 0, 0.3);
|
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) {
|
@media (max-width: 600px) {
|
||||||
.hero__glow {
|
.hero__glow {
|
||||||
display: none;
|
display: none;
|
||||||
|
|||||||
54
js/main.js
54
js/main.js
@@ -34,7 +34,7 @@ function tickCountdown() {
|
|||||||
seconds: pad2(seconds),
|
seconds: pad2(seconds),
|
||||||
};
|
};
|
||||||
Object.keys(map).forEach((key) => {
|
Object.keys(map).forEach((key) => {
|
||||||
const el = root.querySelector(`[data-unit="${key}"]`);
|
const el = root.querySelector(`[data-unit='${key}']`);
|
||||||
if (el) {
|
if (el) {
|
||||||
el.textContent = map[key];
|
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() {
|
function initNav() {
|
||||||
const btn = document.querySelector('.burger');
|
const btn = document.querySelector('.burger');
|
||||||
if (!btn) {
|
if (!btn) {
|
||||||
@@ -73,3 +124,4 @@ function startCountdown() {
|
|||||||
|
|
||||||
startCountdown();
|
startCountdown();
|
||||||
initNav();
|
initNav();
|
||||||
|
initCabinetSubmit();
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
window.__SITE_CONFIG__ = {
|
window.__SITE_CONFIG__ = {
|
||||||
siteUrl: 'https://elcsa.ru',
|
siteUrl: 'https://elcsa.ru',
|
||||||
|
notifyUrl: 'http://72.56.9.52:8000/notify',
|
||||||
gtmContainerId: '',
|
gtmContainerId: '',
|
||||||
ga4MeasurementId: '',
|
ga4MeasurementId: '',
|
||||||
googleAdsId: '',
|
googleAdsId: '',
|
||||||
|
|||||||
Reference in New Issue
Block a user