send telegram

This commit is contained in:
2026-04-18 18:36:51 +03:00
parent 88abd59222
commit 89907284de
5 changed files with 312 additions and 20 deletions

View File

@@ -22,6 +22,7 @@ const mobileToggle = document.getElementById('mobileToggle')
const orderSuccess = document.getElementById('orderSuccess')
const contactSuccess = document.getElementById('contactSuccess')
const wooCommerceConfig = window.test1WooCommerce || null
const leadFormConfig = window.test1LeadForm || null
const cartPageUrl = (wooCommerceConfig && wooCommerceConfig.cartUrl) ? wooCommerceConfig.cartUrl : '/cart/'
const checkoutPageUrl = (wooCommerceConfig && wooCommerceConfig.checkoutUrl) ? wooCommerceConfig.checkoutUrl : '/checkout/'
const cartPanel = cartDrawer?.querySelector('.cart-panel')
@@ -138,6 +139,52 @@ const mobileToggle = document.getElementById('mobileToggle')
})
}
const submitLeadForm = (formElement, successElement, formType, onSuccess) => {
if (!formElement || !successElement) {
return
}
formElement.addEventListener('submit', async event => {
event.preventDefault()
if (!leadFormConfig?.ajaxUrl || !leadFormConfig?.action || !leadFormConfig?.nonce) {
window.alert('Форма временно недоступна. Обновите страницу и попробуйте снова.')
return
}
const formData = new window.FormData(formElement)
formData.append('action', leadFormConfig.action)
formData.append('nonce', leadFormConfig.nonce)
formData.append('form_type', formType)
try {
const response = await window.fetch(leadFormConfig.ajaxUrl, {
method: 'POST',
credentials: 'same-origin',
body: formData,
})
const payload = await response.json().catch(() => null)
if (!response.ok || !payload?.success) {
throw new Error('submit_failed')
}
successElement.classList.add('visible')
if (typeof onSuccess === 'function') {
onSuccess()
}
setTimeout(() => {
formElement.reset()
successElement.classList.remove('visible')
}, 2200)
} catch (error) {
window.alert('Не удалось отправить заявку. Попробуйте еще раз.')
}
})
}
mobileToggle.addEventListener('click', () => {
const isOpen = mobilePanel.classList.contains('active')
if (isOpen) {
@@ -272,26 +319,15 @@ const mobileToggle = document.getElementById('mobileToggle')
})
})
orderForm.addEventListener('submit', event => {
event.preventDefault()
orderSuccess.classList.add('visible')
submitLeadForm(orderForm, orderSuccess, 'landing_order', () => {
cart = []
renderCart()
setTimeout(() => {
closeModal()
orderForm.reset()
orderSuccess.classList.remove('visible')
}, 1800)
}, 700)
})
contactForm.addEventListener('submit', event => {
event.preventDefault()
contactSuccess.classList.add('visible')
setTimeout(() => {
contactForm.reset()
contactSuccess.classList.remove('visible')
}, 2200)
})
submitLeadForm(contactForm, contactSuccess, 'contacts')
document.addEventListener('keydown', event => {
if (event.key !== 'Escape') {