diff --git a/src/components/ContactBlock.js b/src/components/ContactBlock.js index 279c425..4a92b78 100644 --- a/src/components/ContactBlock.js +++ b/src/components/ContactBlock.js @@ -134,15 +134,55 @@ export default function ContactBlock() { const { language } = useLanguage(); const t = translations.contacts[language]; + function sendMessage(text) + { + const url = `https://api.telegram.org/bot8190149729:AAH1n6QXzaU__EwRhrPbEn9fqrFbPRRLFaI/sendMessage` // The url to request + + const obj = { + chat_id: 1017685666, // Telegram chat id + text: text // The text to send + }; + + const xht = new XMLHttpRequest(); + xht.open("POST", url, true); + xht.setRequestHeader("Content-type", "application/json; charset=UTF-8"); + xht.send(JSON.stringify(obj)); + } + const [formData, setFormData] = useState({ name: '', email: '', message: '' }); + // const handleSubmit = (e) => { + // e.preventDefault(); + // console.log('Form submitted:', formData); + // }; + const handleSubmit = (e) => { e.preventDefault(); - console.log('Form submitted:', formData); + + // Формируем текст сообщения для Telegram + const messageText = ` + Новое сообщение с сайта: + 👤 Имя: ${formData.name} + 📧 Email: ${formData.email} + 💬 Сообщение: ${formData.message} + `.trim(); + + // Отправляем сообщение в Telegram + sendMessage(messageText); + + // Очищаем форму после отправки + setFormData({ + name: '', + email: '', + message: '' + }); + + // Показываем уведомление об успешной отправке + // alert(language === 'ru' ? 'Сообщение успешно отправлено!' : 'Message sent successfully!'); }; const handleChange = (e) => { @@ -241,8 +281,7 @@ export default function ContactBlock() { required /> - + - + ))}