mirror of
https://git.rdcenter.ru/RDCenter/skb-kit.git
synced 2026-12-05 05:09:46 +00:00
исправила баг имени в контактной форме
This commit is contained in:
1 parent
2a0f437744
commit
dd5d54a4e4
2 files changed
+21
-8
No files matched your search
@@ -15,7 +15,11 @@ import {
|
|||||||
} from "@/widgets/ContactForm/variables";
|
} from "@/widgets/ContactForm/variables";
|
||||||
|
|
||||||
const formSchema = z.object({
|
const formSchema = z.object({
|
||||||
name: z.string().min(1, "Обязательное поле"),
|
name: z
|
||||||
|
.string()
|
||||||
|
.trim()
|
||||||
|
.min(1, "Обязательное поле")
|
||||||
|
.regex(/^[a-zA-Zа-яА-ЯёЁ\s-]+$/, "Имя может содержать только буквы и пробелы"),
|
||||||
email: z.string().email("Некорректный email. Пример 123@sfedu.ru"),
|
email: z.string().email("Некорректный email. Пример 123@sfedu.ru"),
|
||||||
phone: z.string()
|
phone: z.string()
|
||||||
.min(1, "Обязательное поле")
|
.min(1, "Обязательное поле")
|
||||||
@@ -145,6 +149,13 @@ function ContactForm() {
|
|||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const handleNameChange = (e: React.ChangeEvent<HTMLInputElement>) => {
|
||||||
|
// Разрешены только буквы (латиница и кириллица), пробелы и дефисы
|
||||||
|
const rawValue = e.target.value;
|
||||||
|
const cleanedValue = rawValue.replace(/[^a-zA-Zа-яА-ЯёЁ\s-]/g, '');
|
||||||
|
setValue("name", cleanedValue, { shouldValidate: true });
|
||||||
|
};
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Form
|
<Form
|
||||||
method="post"
|
method="post"
|
||||||
@@ -158,7 +169,9 @@ function ContactForm() {
|
|||||||
name="name"
|
name="name"
|
||||||
placeholder="Имя"
|
placeholder="Имя"
|
||||||
disabled={isSubmitting || isPending}
|
disabled={isSubmitting || isPending}
|
||||||
register={register("name")}
|
register={register("name", {
|
||||||
|
onChange: handleNameChange,
|
||||||
|
})}
|
||||||
error={errors.name?.message}
|
error={errors.name?.message}
|
||||||
/>
|
/>
|
||||||
<Field
|
<Field
|
||||||
|
|||||||
@@ -12,9 +12,9 @@ const PhotoGallery = ({ images }: PhotoGalleryProps) => {
|
|||||||
const { data: mediaData, isLoading, isError } = useMedia();
|
const { data: mediaData, isLoading, isError } = useMedia();
|
||||||
const [visibleCount] = useState(10);
|
const [visibleCount] = useState(10);
|
||||||
|
|
||||||
const filteredMedia = images
|
const filteredMedia = images
|
||||||
? images.map((src, id) => ({ id, src }))
|
? images.map((src, id) => ({ id, src }))
|
||||||
: mediaData || []; // без фильтра
|
: mediaData || []; // без фильтра
|
||||||
|
|
||||||
if (isLoading)
|
if (isLoading)
|
||||||
return (
|
return (
|
||||||
@@ -27,7 +27,7 @@ const PhotoGallery = ({ images }: PhotoGalleryProps) => {
|
|||||||
|
|
||||||
return (
|
return (
|
||||||
<div className="mainContainer">
|
<div className="mainContainer">
|
||||||
<h1 className="title">Фотогалерея</h1>
|
<h1 className="title">Фотогалерея</h1>
|
||||||
<div className="images">
|
<div className="images">
|
||||||
{filteredMedia.slice(0, visibleCount).map((media) => (
|
{filteredMedia.slice(0, visibleCount).map((media) => (
|
||||||
<div key={media.id} className="image-container">
|
<div key={media.id} className="image-container">
|
||||||
@@ -41,8 +41,8 @@ const PhotoGallery = ({ images }: PhotoGalleryProps) => {
|
|||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div className="btn">
|
<div className="btn">
|
||||||
Показать еще
|
Загрузить ещё
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in new issue
Block a user