исправил функцию отправки на почту
This commit is contained in:
1 parent
5de57cc7ad
commit
b205ca9204
1 file changed
+5
-15
@@ -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({
|
||||||
@@ -65,24 +66,13 @@ 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",
|
|
||||||
headers: {
|
|
||||||
"Content-Type": "application/json",
|
|
||||||
},
|
|
||||||
body: JSON.stringify({
|
|
||||||
...data,
|
...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("Не удалось отправить заявку. Попробуйте позже.");
|
||||||
|
|||||||
Reference in new issue
Block a user