написал логику отправки формы на бэк

This commit is contained in:
Joe_Peach committed 2025-11-24 02:37:32 +03:00
1 parent 7c14baca77
commit 3cd1a9c1e4
1 file changed
+14 -1
@@ -6,6 +6,7 @@ import * as yup from "yup";
import { yupResolver } from "@hookform/resolvers/yup";
import styles from "./ModalRequestForm.module.css";
import Button from "../Button/Button";
import axios from "axios";
// ✅ Схема валидации
const schema = yup.object().shape({
@@ -60,7 +61,19 @@ const PriceLisForm: React.FC<Props> = ({ open, onClose }) => {
};
const sendToBackend = async (data: FormData): Promise<boolean> => {
return true;
try{
const response = await axios.post("/api/requests", {
...data,
source: "website-form",
timestamp: new Date().toISOString(),
})
return response.data.success;
}catch (error: any){
console.error("Error sending request:", error);
throw new Error("Не удалось отправить заявку. Попробуйте позже.");
}
};
const onSubmit = async (data: FormData) => {