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

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