"use client"; import { useTranslation } from "react-i18next"; import Text from "../lib_components/text"; import axios from "axios"; import { FormEvent } from "react"; export default function Contact() { const { t } = useTranslation(); const sendMessage = async (event: FormEvent) => { event.preventDefault(); const form = event.currentTarget; const nameInput = form.elements.namedItem("name") as HTMLInputElement; const name = nameInput?.value?.trim(); if (!name) { alert("Iltimos, telefon raqamingizni kiriting!"); return; } try { const token = "7940057045:AAHRFPvgUCo_7pqpXD6uq4li7-_DYx2J96g"; // Use environment variable const chatId = 6134458285; if (!token || !chatId) { throw new Error("Telegram token yoki chat ID topilmadi!"); } const message = `📞 Yangi kontakt: ${name}`; await axios.post(`https://api.telegram.org/bot${token}/sendMessage`, { chat_id: chatId, text: message, }); alert("✅ Muvaffaqiyatli yuborildi!"); form.reset(); } catch (error) { console.error("Yuborishda xatolik:", error); alert("❌ Yuborishda xatolik yuz berdi!"); } }; return (

{/* Form */}
); }