исправил функцию отправки на почту

This commit is contained in:
Joe_Peach committed 2026-04-02 13:23:27 +03:00
1 parent 5de57cc7ad
commit b205ca9204
1 file changed
+12 -22
@@ -7,6 +7,7 @@ import * as yup from "yup";
import { yupResolver } from "@hookform/resolvers/yup"; import { yupResolver } from "@hookform/resolvers/yup";
import styles from "./ModalRequestForm.module.css"; import styles from "./ModalRequestForm.module.css";
import Button from "../Button/Button"; import Button from "../Button/Button";
import { client } from "../../api/client";
// ✅ Схема валидации // ✅ Схема валидации
const schema = yup.object().shape({ const schema = yup.object().shape({
@@ -64,30 +65,19 @@ const ModalRequestForm: React.FC<Props> = ({ open, onClose }) => {
// ✅ Отправка данных на бэкенд // ✅ Отправка данных на бэкенд
const sendToBackend = async (data: FormData): Promise<boolean> => { const sendToBackend = async (data: FormData): Promise<boolean> => {
try { try {
const response = await fetch(`/api/email`, { const payload = {
method: "POST", ...data,
headers: { };
"Content-Type": "application/json",
},
body: JSON.stringify({
...data,
source: "website-form",
timestamp: new Date().toISOString(),
}),
});
if (!response.ok) { const response = await client.post<{ success: boolean }>("/email", payload);
throw new Error(`HTTP error! status: ${response.status}`);
}
const result = await response.json(); return response.data.success;
return result.success; } catch (error) {
} catch (error) { console.error("Error sending request:", error);
console.error("Error sending request:", error); throw new Error("Не удалось отправить заявку. Попробуйте позже.");
throw new Error("Не удалось отправить заявку. Попробуйте позже."); }
} };
};
// ✅ Submit // ✅ Submit
const onSubmit = async (data: FormData) => { const onSubmit = async (data: FormData) => {