исправил функцию отправки на почту
This commit is contained in:
1 parent
5de57cc7ad
commit
b205ca9204
1 file changed
+6
-16
@@ -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({
|
||||
@@ -65,29 +66,18 @@ 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({
|
||||
const payload = {
|
||||
...data,
|
||||
source: "website-form",
|
||||
timestamp: new Date().toISOString(),
|
||||
}),
|
||||
});
|
||||
};
|
||||
|
||||
if (!response.ok) {
|
||||
throw new Error(`HTTP error! status: ${response.status}`);
|
||||
}
|
||||
const response = await client.post<{ success: boolean }>("/email", payload);
|
||||
|
||||
const result = await response.json();
|
||||
return result.success;
|
||||
return response.data.success;
|
||||
} catch (error) {
|
||||
console.error("Error sending request:", error);
|
||||
throw new Error("Не удалось отправить заявку. Попробуйте позже.");
|
||||
}
|
||||
};
|
||||
};
|
||||
|
||||
// ✅ Submit
|
||||
const onSubmit = async (data: FormData) => {
|
||||
|
||||
Reference in new issue
Block a user