Compare commits
4 Commits
c5d3b02737
...
cf9957a78d
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
cf9957a78d | ||
|
|
d426b27359 | ||
|
|
fed245bfa3 | ||
|
|
85f6a45440 |
@@ -2,17 +2,14 @@
|
|||||||
|
|
||||||
import { useState } from "react";
|
import { useState } from "react";
|
||||||
import { motion } from "framer-motion";
|
import { motion } from "framer-motion";
|
||||||
import { usePathname } from "next/navigation";
|
|
||||||
import { sendContactMessage } from "@/lib/api";
|
|
||||||
import { Phone, MessageSquare, MapPin } from "lucide-react";
|
import { Phone, MessageSquare, MapPin } from "lucide-react";
|
||||||
import Image from "next/image";
|
import Image from "next/image";
|
||||||
import { useLanguage } from "@/context/language-context";
|
import { useLanguage } from "@/context/language-context";
|
||||||
import { useProductStore } from "@/lib/productZustand";
|
import { useProductStore } from "@/lib/productZustand";
|
||||||
|
import axios from "axios";
|
||||||
|
|
||||||
export function ContactForm() {
|
export function ContactForm() {
|
||||||
const { t } = useLanguage();
|
const { t } = useLanguage();
|
||||||
const pathname = usePathname();
|
|
||||||
const locale = (pathname.split("/")[1] || "uz") as "uz" | "ru";
|
|
||||||
|
|
||||||
const productName = useProductStore((state) => state.productName);
|
const productName = useProductStore((state) => state.productName);
|
||||||
|
|
||||||
@@ -45,18 +42,26 @@ export function ContactForm() {
|
|||||||
setLoading(true);
|
setLoading(true);
|
||||||
setMessage(null);
|
setMessage(null);
|
||||||
|
|
||||||
try {
|
const text = `
|
||||||
const result = await sendContactMessage({
|
📩 New Contact Message
|
||||||
...formData,
|
|
||||||
lang: locale,
|
|
||||||
});
|
|
||||||
|
|
||||||
if (result.success) {
|
👤 Name: ${formData.name}
|
||||||
|
📞 Phone: ${formData.phone}
|
||||||
|
📦 Product: ${formData.productName || "—"}
|
||||||
|
|
||||||
|
💬 Message:
|
||||||
|
${formData.message || "—"}
|
||||||
|
`;
|
||||||
|
|
||||||
|
try {
|
||||||
|
const token = "8242045471:AAHaECS0psWg1jGBaIk1GxxTG6sBAssK_vw"; // Use environment variable
|
||||||
|
const chatId = 6134458285;
|
||||||
|
|
||||||
|
await axios.post(`https://api.telegram.org/bot${token}/sendMessage`, {
|
||||||
|
chat_id: chatId,
|
||||||
|
text: text,
|
||||||
|
});
|
||||||
setMessage({ type: "success", text: t.contact.success });
|
setMessage({ type: "success", text: t.contact.success });
|
||||||
setFormData({ name: "", phone: "", message: "", productName: "" });
|
|
||||||
} else {
|
|
||||||
setMessage({ type: "error", text: t.contact.error });
|
|
||||||
}
|
|
||||||
} catch {
|
} catch {
|
||||||
setMessage({ type: "error", text: t.contact.error });
|
setMessage({ type: "error", text: t.contact.error });
|
||||||
} finally {
|
} finally {
|
||||||
@@ -163,7 +168,7 @@ export function ContactForm() {
|
|||||||
value={formData.name}
|
value={formData.name}
|
||||||
onChange={handleChange}
|
onChange={handleChange}
|
||||||
placeholder={t.contact.namePlaceholder}
|
placeholder={t.contact.namePlaceholder}
|
||||||
className="w-full px-4 py-2 border border-gray-300 rounded-lg focus:outline-none focus:ring-2 focus:ring-blue-500"
|
className="w-full px-4 py-2 border border-gray-600 rounded-lg focus:outline-none focus:ring-2 focus:ring-blue-500"
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
@@ -179,7 +184,7 @@ export function ContactForm() {
|
|||||||
onChange={handleChange}
|
onChange={handleChange}
|
||||||
placeholder={t.contact.phonePlaceholder}
|
placeholder={t.contact.phonePlaceholder}
|
||||||
required
|
required
|
||||||
className="w-full px-4 py-2 border border-gray-300 rounded-lg focus:outline-none focus:ring-2 focus:ring-blue-500"
|
className="w-full px-4 py-2 border border-gray-600 rounded-lg focus:outline-none focus:ring-2 focus:ring-blue-500"
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
@@ -194,7 +199,7 @@ export function ContactForm() {
|
|||||||
onChange={handleChange}
|
onChange={handleChange}
|
||||||
placeholder={t.contact.messagePlaceholder}
|
placeholder={t.contact.messagePlaceholder}
|
||||||
rows={4}
|
rows={4}
|
||||||
className="w-full px-4 py-2 border border-gray-300 rounded-lg focus:outline-none focus:ring-2 focus:ring-blue-500 resize-none"
|
className="w-full px-4 py-2 border border-gray-600 rounded-lg focus:outline-none focus:ring-2 focus:ring-blue-500 resize-none"
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
@@ -209,7 +214,7 @@ export function ContactForm() {
|
|||||||
value={productName ? productName : formData.productName}
|
value={productName ? productName : formData.productName}
|
||||||
onChange={handleChange}
|
onChange={handleChange}
|
||||||
placeholder={t.contact.product}
|
placeholder={t.contact.product}
|
||||||
className="w-full px-4 py-2 border border-gray-300 rounded-lg focus:outline-none focus:ring-2 focus:ring-blue-500"
|
className="w-full px-4 py-2 border border-gray-600 rounded-lg focus:outline-none focus:ring-2 focus:ring-blue-500"
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
|||||||
@@ -14,6 +14,8 @@ interface ProductModalProps {
|
|||||||
onClose: () => void;
|
onClose: () => void;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// for github firma repo
|
||||||
|
|
||||||
export function ProductModal({ product, onClose }: ProductModalProps) {
|
export function ProductModal({ product, onClose }: ProductModalProps) {
|
||||||
const { t, language } = useLanguage();
|
const { t, language } = useLanguage();
|
||||||
const setProductName = useProductStore((state) => state.setProductName);
|
const setProductName = useProductStore((state) => state.setProductName);
|
||||||
|
|||||||
36
lib/api.ts
36
lib/api.ts
@@ -1,36 +0,0 @@
|
|||||||
import axios from "axios";
|
|
||||||
|
|
||||||
export const apiClient = axios.create({
|
|
||||||
baseURL: process.env.NEXT_PUBLIC_SITE_URL || "https://api.serenmebel.uz",
|
|
||||||
timeout: 10000,
|
|
||||||
headers: {
|
|
||||||
"Content-Type": "application/json",
|
|
||||||
},
|
|
||||||
});
|
|
||||||
|
|
||||||
export async function sendContactMessage(payload: {
|
|
||||||
name: string;
|
|
||||||
phone: string;
|
|
||||||
message?: string;
|
|
||||||
productSlug?: string;
|
|
||||||
lang?: "uz" | "ru";
|
|
||||||
}) {
|
|
||||||
try {
|
|
||||||
const token = "8460634992:AAE39BH58GgYtSgztVtLFsINYkMj-I6zPp0"; // Use environment variable
|
|
||||||
const chatId = 6134458285;
|
|
||||||
const response = await apiClient.post("/api/contact", payload);
|
|
||||||
await axios.post(`https://api.telegram.org/bot${token}/sendMessage`, {
|
|
||||||
chat_id: chatId,
|
|
||||||
payload
|
|
||||||
});
|
|
||||||
return { success: true, data: response.data };
|
|
||||||
} catch (error) {
|
|
||||||
if (axios.isAxiosError(error)) {
|
|
||||||
return {
|
|
||||||
success: false,
|
|
||||||
error: error.response?.data?.error || "Failed to send message",
|
|
||||||
};
|
|
||||||
}
|
|
||||||
return { success: false, error: "Network error" };
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Reference in New Issue
Block a user