Добавил иконку с названием на вкладку, исправил форму для вопроса
This commit is contained in:
1 parent
797d4a091f
commit
b6f66ab4a7
5 files changed
+180
-95
No files matched your search
+2
-2
@@ -2,9 +2,9 @@
|
|||||||
<html lang="en">
|
<html lang="en">
|
||||||
<head>
|
<head>
|
||||||
<meta charset="UTF-8" />
|
<meta charset="UTF-8" />
|
||||||
<link rel="icon" type="image/svg+xml" href="/vite.svg" />
|
<link rel="icon" type="image/jpg" href="/public/MiniLogo.jpg" />
|
||||||
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
||||||
<title>front</title>
|
<title>RK PLASTIC</title>
|
||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
<div id="root"></div>
|
<div id="root"></div>
|
||||||
|
|||||||
Binary file not shown.
|
After Width: | Height: | Size: 11 KiB |
@@ -174,7 +174,7 @@ const ModalRequestForm: React.FC<Props> = ({ open, onClose }) => {
|
|||||||
|
|
||||||
<textarea
|
<textarea
|
||||||
className={styles.textarea}
|
className={styles.textarea}
|
||||||
placeholder="Задайте свой вопрос"
|
placeholder="Сделайте запрос"
|
||||||
{...register("message")}
|
{...register("message")}
|
||||||
disabled={isSubmitting}
|
disabled={isSubmitting}
|
||||||
/>
|
/>
|
||||||
|
|||||||
@@ -2,13 +2,12 @@ import React from "react";
|
|||||||
import styles from "./QuestionsBlock.module.css";
|
import styles from "./QuestionsBlock.module.css";
|
||||||
import Button from "../Button/Button";
|
import Button from "../Button/Button";
|
||||||
import { PhoneOutlined } from "@ant-design/icons";
|
import { PhoneOutlined } from "@ant-design/icons";
|
||||||
import PhoneRequest from "../../features/MainPage/PhoneRequest";
|
import ModalRequestFormQuastion from "../../features/MainPage/PhoneRequest";
|
||||||
|
import { useState } from "react";
|
||||||
|
|
||||||
const QuestionsBlock: React.FC = () => {
|
const QuestionsBlock: React.FC = () => {
|
||||||
|
|
||||||
const handleClick = () => {
|
const [open, setOpen] = useState(false);
|
||||||
console.log('Кнопка нажата!');
|
|
||||||
};
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<section className={styles.wrapper}>
|
<section className={styles.wrapper}>
|
||||||
@@ -45,13 +44,13 @@ const QuestionsBlock: React.FC = () => {
|
|||||||
type="text"
|
type="text"
|
||||||
placeholder="+7 (___) ___-__-__"
|
placeholder="+7 (___) ___-__-__"
|
||||||
className={styles.input}
|
className={styles.input}
|
||||||
/>
|
/>*/}
|
||||||
<Button
|
<Button
|
||||||
label="ОТПРАВИТЬ"
|
label="ЗАДАТЬ ВОПРОС"
|
||||||
onClick={handleClick}
|
onClick={() => setOpen(true)}
|
||||||
/>
|
/>
|
||||||
</div>*/}
|
|
||||||
<PhoneRequest/>
|
<ModalRequestFormQuastion open={open} onClose={() => setOpen(false)}/>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</section>
|
</section>
|
||||||
|
|||||||
@@ -1,105 +1,191 @@
|
|||||||
import React, { useState } from "react";
|
import React from "react";
|
||||||
import styles from "./MainPage.module.css";
|
import { Modal } from "antd";
|
||||||
|
import { motion } from "framer-motion";
|
||||||
|
import InputMask from "react-input-mask";
|
||||||
|
import { useForm } from "react-hook-form";
|
||||||
|
import * as yup from "yup";
|
||||||
|
import { yupResolver } from "@hookform/resolvers/yup";
|
||||||
|
import styles from "../../components/ModalRequestForm/ModalRequestForm.module.css";
|
||||||
import Button from "../../components/Button/Button";
|
import Button from "../../components/Button/Button";
|
||||||
import { client } from "../../api/client";
|
import { client } from "../../api/client";
|
||||||
|
|
||||||
|
// ✅ Схема валидации
|
||||||
|
const schema = yup.object().shape({
|
||||||
|
name: yup.string().required("Введите имя"),
|
||||||
|
email: yup.string().email("Некорректный Email").required("Введите Email"),
|
||||||
|
phone: yup.string().min(18, "Введите корректный номер").required("Введите номер"),
|
||||||
|
message: yup.string().nullable(),
|
||||||
|
});
|
||||||
|
|
||||||
interface Props {
|
interface Props {
|
||||||
onSend?: (phone: string) => Promise<void>;
|
open: boolean;
|
||||||
|
onClose: () => void;
|
||||||
}
|
}
|
||||||
|
|
||||||
const PhoneRequest: React.FC<Props> = ({ onSend }) => {
|
interface FormData {
|
||||||
const [phone, setPhone] = useState("");
|
name: string;
|
||||||
const [loading, setLoading] = useState(false);
|
email: string;
|
||||||
const [success, setSuccess] = useState(false);
|
phone: string;
|
||||||
const [error, setError] = useState("");
|
message?: string | null;
|
||||||
|
}
|
||||||
|
|
||||||
// Автоформатирование "+7 (999) 999-99-99"
|
const ModalRequestFormQuastion: React.FC<Props> = ({ open, onClose }) => {
|
||||||
const formatPhone = (value: string) => {
|
console.log('ModalRequestForm render, open:', open);
|
||||||
const digits = value.replace(/\D/g, "");
|
const {
|
||||||
|
register,
|
||||||
|
handleSubmit,
|
||||||
|
formState: { errors, isSubmitting },
|
||||||
|
reset,
|
||||||
|
} = useForm({ resolver: yupResolver(schema) });
|
||||||
|
|
||||||
let result = "+7 ";
|
const handlePhoneInput = (e: React.ChangeEvent<HTMLInputElement>) => {
|
||||||
if (digits.length > 1) result += "(" + digits.substring(1, 4);
|
let value = e.target.value.replace(/\D/g, '');
|
||||||
if (digits.length >= 4) result += ") " + digits.substring(4, 7);
|
|
||||||
if (digits.length >= 7) result += "-" + digits.substring(7, 9);
|
if (value.startsWith('7') || value.startsWith('8')) {
|
||||||
if (digits.length >= 9) result += "-" + digits.substring(9, 11);
|
value = value.substring(1);
|
||||||
|
}
|
||||||
return result;
|
|
||||||
|
let formattedValue = '+7 ';
|
||||||
|
|
||||||
|
if (value.length > 0) {
|
||||||
|
formattedValue += '(' + value.substring(0, 3);
|
||||||
|
}
|
||||||
|
if (value.length > 3) {
|
||||||
|
formattedValue += ') ' + value.substring(3, 6);
|
||||||
|
}
|
||||||
|
if (value.length > 6) {
|
||||||
|
formattedValue += '-' + value.substring(6, 8);
|
||||||
|
}
|
||||||
|
if (value.length > 8) {
|
||||||
|
formattedValue += '-' + value.substring(8, 10);
|
||||||
|
}
|
||||||
|
|
||||||
|
e.target.value = formattedValue;
|
||||||
};
|
};
|
||||||
|
|
||||||
const handlePhoneChange = (e: React.ChangeEvent<HTMLInputElement>) => {
|
// ✅ Отправка данных на бэкенд
|
||||||
let v = e.target.value;
|
const sendToBackend = async (data: FormData): Promise<boolean> => {
|
||||||
|
try {
|
||||||
|
const payload = {
|
||||||
|
...data,
|
||||||
|
};
|
||||||
|
|
||||||
if (v.replace(/\D/g, "").length === 0) {
|
const response = await client.post<{ success: boolean }>("/email/", payload);
|
||||||
setPhone("");
|
|
||||||
return;
|
return response.data.success;
|
||||||
}
|
} catch (error) {
|
||||||
|
console.error("Error sending request:", error);
|
||||||
if (v[0] !== "+") {
|
throw new Error("Не удалось отправить заявку. Попробуйте позже.");
|
||||||
v = "+7" + v;
|
}
|
||||||
}
|
};
|
||||||
|
|
||||||
setPhone(formatPhone(v));
|
|
||||||
};
|
|
||||||
|
|
||||||
const validatePhone = (p: string) => {
|
|
||||||
return p.replace(/\D/g, "").length === 11;
|
|
||||||
};
|
|
||||||
|
|
||||||
const handleSubmit = async () => {
|
|
||||||
setError("");
|
|
||||||
|
|
||||||
if (!validatePhone(phone)) {
|
|
||||||
setError("Введите корректный номер телефона");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
setLoading(true);
|
|
||||||
|
|
||||||
|
// ✅ Submit
|
||||||
|
const onSubmit = async (data: FormData) => {
|
||||||
try {
|
try {
|
||||||
if (onSend) {
|
await sendToBackend(data);
|
||||||
await onSend(phone);
|
|
||||||
} else {
|
// Показываем уведомление об успехе
|
||||||
|
Modal.success({
|
||||||
await client.post("/email/", { phone });
|
title: "Заявка отправлена!",
|
||||||
}
|
content: "Наш менеджер свяжется с вами в ближайшее время.",
|
||||||
|
okText: "Хорошо",
|
||||||
setSuccess(true);
|
});
|
||||||
setPhone("");
|
|
||||||
|
reset();
|
||||||
setTimeout(() => setSuccess(false), 3000);
|
onClose();
|
||||||
} catch (e) {
|
} catch (error) {
|
||||||
setError("Ошибка отправки. Попробуйте позже.");
|
// Показываем ошибку
|
||||||
|
Modal.error({
|
||||||
|
title: "Ошибка",
|
||||||
|
content: error instanceof Error ? error.message : "Произошла неизвестная ошибка",
|
||||||
|
okText: "Понятно",
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
setLoading(false);
|
|
||||||
};
|
};
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className={styles.form}>
|
<Modal
|
||||||
<input
|
open={open}
|
||||||
className={styles.input}
|
footer={null}
|
||||||
placeholder="+7 (___) ___-__-__"
|
onCancel={onClose}
|
||||||
type="tel"
|
centered
|
||||||
value={phone}
|
width={620}
|
||||||
onChange={handlePhoneChange}
|
closable={!isSubmitting}
|
||||||
maxLength={18}
|
maskClosable={!isSubmitting}
|
||||||
/>
|
>
|
||||||
<Button
|
<motion.div
|
||||||
label="ОТПРАВИТЬ"
|
initial={{ opacity: 0, y: 40 }}
|
||||||
onClick={handleSubmit}
|
animate={{ opacity: 1, y: 0 }}
|
||||||
/>
|
transition={{ duration: 0.35 }}
|
||||||
{/*<button
|
className={styles.modalBox}
|
||||||
className={styles.button}
|
|
||||||
onClick={handleSubmit}
|
|
||||||
disabled={loading}
|
|
||||||
>
|
>
|
||||||
{loading ? "..." : "ОТПРАВИТЬ"}
|
<h2 className={styles.title}>Задайте вопрос</h2>
|
||||||
</button>*/}
|
<p className={styles.subtitle}>
|
||||||
|
Ожидайте ответа на указанную почту
|
||||||
|
</p>
|
||||||
|
|
||||||
{error && <p className={styles.error}>{error}</p>}
|
<form onSubmit={handleSubmit(onSubmit)} className={styles.form}>
|
||||||
{success && <p className={styles.success}>Заявка отправлена!</p>}
|
<div className={styles.field}>
|
||||||
</div>
|
<input
|
||||||
|
className={styles.input}
|
||||||
|
placeholder="Введите имя *"
|
||||||
|
{...register("name")}
|
||||||
|
disabled={isSubmitting}
|
||||||
|
/>
|
||||||
|
{errors.name && <span className={styles.error}>{errors.name.message}</span>}
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div className={styles.field}>
|
||||||
|
<input
|
||||||
|
className={styles.input}
|
||||||
|
placeholder="Введите email *"
|
||||||
|
{...register("email")}
|
||||||
|
disabled={isSubmitting}
|
||||||
|
/>
|
||||||
|
{errors.email && <span className={styles.error}>{errors.email.message}</span>}
|
||||||
|
</div>
|
||||||
|
|
||||||
|
{/*<div className={styles.field}>
|
||||||
|
<InputMask
|
||||||
|
mask="+7 (999) 999-99-99"
|
||||||
|
{...register("phone")}
|
||||||
|
disabled={isSubmitting}
|
||||||
|
>
|
||||||
|
{(inputProps: any) => (
|
||||||
|
<input
|
||||||
|
className={styles.input}
|
||||||
|
placeholder="Введите № телефона *"
|
||||||
|
{...inputProps}
|
||||||
|
/>
|
||||||
|
)}
|
||||||
|
</InputMask>
|
||||||
|
{errors.phone && <span className={styles.error}>{errors.phone.message}</span>}
|
||||||
|
</div>*/}
|
||||||
|
<div className={styles.field}>
|
||||||
|
<input
|
||||||
|
className={styles.input}
|
||||||
|
placeholder="+7 (___) ___-__-__ *"
|
||||||
|
{...register("phone")}
|
||||||
|
onInput={handlePhoneInput}
|
||||||
|
disabled={isSubmitting}
|
||||||
|
/>
|
||||||
|
{errors.phone && <span className={styles.error}>{errors.phone.message}</span>}
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<textarea
|
||||||
|
className={styles.textarea}
|
||||||
|
placeholder="Ваш вопрос"
|
||||||
|
{...register("message")}
|
||||||
|
disabled={isSubmitting}
|
||||||
|
/>
|
||||||
|
|
||||||
|
<Button
|
||||||
|
label={isSubmitting ? "ОТПРАВКА..." : "ОТПРАВИТЬ"}
|
||||||
|
/>
|
||||||
|
</form>
|
||||||
|
</motion.div>
|
||||||
|
</Modal>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
export default PhoneRequest;
|
export default ModalRequestFormQuastion;
|
||||||
Reference in new issue
Block a user