Files
firma/lib/api.ts
nabijonovdavronbek619@gmail.com f9d27ec11d new web sayt
2025-11-25 21:06:55 +05:00

31 lines
748 B
TypeScript

import axios from "axios";
export const apiClient = axios.create({
baseURL: process.env.NEXT_PUBLIC_SITE_URL || "http://localhost:3000",
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 response = await apiClient.post("/api/contact", 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" };
}
}