Улучшить мобильное меню и форму заявки, добавить номер лида и заменить middleware на proxy
All checks were successful
Auto Deploy / deploy (push) Successful in 22s

This commit is contained in:
deonisii
2026-04-18 00:20:24 +03:00
parent 9b86175929
commit 45ae26e213
9 changed files with 571 additions and 322 deletions

View File

@@ -0,0 +1,25 @@
import type { SVGProps } from "react";
export default function BarrierIcon(props: SVGProps<SVGSVGElement>) {
return (
<svg
viewBox="0 0 24 24"
fill="none"
stroke="currentColor"
strokeWidth="2"
strokeLinecap="round"
strokeLinejoin="round"
aria-hidden="true"
{...props}
>
<path d="M3 20h18" />
<path d="M6 20v-7a2 2 0 0 1 2-2h1" />
<path d="M9 11h10.5" />
<path d="M9 11 20 5" />
<path d="M11.3 9.75 13 10.7" />
<path d="M14.8 7.85 16.5 8.8" />
<path d="M18.3 5.95 20 6.9" />
<path d="M6 16h2" />
</svg>
);
}

View File

@@ -2,8 +2,68 @@
import { useState } from "react";
type FieldErrors = {
company?: string;
phone?: string;
email?: string;
};
function getPhoneDigits(input: string) {
return input.replace(/\D/g, "").slice(0, 11);
}
function formatRussianPhoneInput(input: string) {
const digits = getPhoneDigits(input);
if (!digits) {
return "";
}
let normalized = digits;
if (normalized[0] === "8") {
normalized = `7${normalized.slice(1)}`;
}
if (normalized[0] !== "7") {
normalized = `7${normalized.slice(0, 10)}`;
}
normalized = normalized.slice(0, 11);
const country = "+7";
const part1 = normalized.slice(1, 4);
const part2 = normalized.slice(4, 7);
const part3 = normalized.slice(7, 9);
const part4 = normalized.slice(9, 11);
let result = country;
if (part1) {
result += ` (${part1}`;
}
if (part1.length === 3) {
result += ")";
}
if (part2) {
result += ` ${part2}`;
}
if (part3) {
result += `-${part3}`;
}
if (part4) {
result += `-${part4}`;
}
return result;
}
function normalizePhone(input: string) {
const digits = input.replace(/\D/g, "");
const digits = getPhoneDigits(input);
if (digits.length === 11 && (digits.startsWith("7") || digits.startsWith("8"))) {
return `7${digits.slice(1)}`;
@@ -20,29 +80,70 @@ function isValidEmail(email: string) {
return /^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(email);
}
export default function LeadForm() {
type LeadFormProps = {
id?: string;
title?: string;
description?: string;
compact?: boolean;
};
export default function LeadForm({
id,
title,
description,
compact = false,
}: LeadFormProps) {
const [company, setCompany] = useState("");
const [phone, setPhone] = useState("");
const [email, setEmail] = useState("");
const [message, setMessage] = useState("");
const [isSubmitting, setIsSubmitting] = useState(false);
const [resultMessage, setResultMessage] = useState("");
const [submitError, setSubmitError] = useState(false);
const [errors, setErrors] = useState<FieldErrors>({});
function validateFields() {
const nextErrors: FieldErrors = {};
const normalizedPhone = normalizePhone(phone);
const trimmedCompany = company.trim();
const trimmedEmail = email.trim();
if (trimmedCompany.length < 2) {
nextErrors.company = "Укажите название объекта или компании";
}
if (!normalizedPhone) {
nextErrors.phone = "Введите российский номер в формате +7";
}
if (!trimmedEmail) {
nextErrors.email = "Введите email";
} else if (!isValidEmail(trimmedEmail)) {
nextErrors.email = "Проверьте корректность email";
}
return {
nextErrors,
normalizedPhone,
trimmedCompany,
trimmedEmail,
};
}
async function handleSubmit(e: React.FormEvent<HTMLFormElement>) {
e.preventDefault();
setResultMessage("");
setSubmitError(false);
const normalizedPhone = normalizePhone(phone);
if (!normalizedPhone) {
setResultMessage("Введите корректный российский телефон");
return;
}
if (!isValidEmail(email.trim())) {
setResultMessage("Введите корректный email");
const { nextErrors, normalizedPhone, trimmedCompany, trimmedEmail } =
validateFields();
if (Object.keys(nextErrors).length > 0 || !normalizedPhone) {
setErrors(nextErrors);
return;
}
setErrors({});
setIsSubmitting(true);
try {
@@ -52,79 +153,165 @@ export default function LeadForm() {
"Content-Type": "application/json",
},
body: JSON.stringify({
company,
company: trimmedCompany,
phone: normalizedPhone,
email,
message,
email: trimmedEmail,
message: message.trim(),
}),
});
const data = await response.json();
if (!response.ok) {
setSubmitError(true);
setResultMessage(data.error || "Ошибка отправки");
return;
}
setSubmitError(false);
setResultMessage("Заявка отправлена. Мы свяжемся с вами.");
setCompany("");
setPhone("");
setEmail("");
setMessage("");
} catch {
setSubmitError(true);
setResultMessage("Не удалось сохранить заявку");
} finally {
setIsSubmitting(false);
}
}
const fieldClassName =
"w-full rounded-2xl border bg-black/30 px-4 py-3.5 text-white outline-none transition-colors placeholder:text-neutral-500 focus:border-emerald-500 sm:px-5 sm:py-4";
const labelClassName = "mb-2 block text-sm font-medium text-neutral-200";
const helperClassName = "mt-2 text-xs text-neutral-500";
const errorClassName = "mt-2 text-xs text-rose-300";
return (
<form onSubmit={handleSubmit} className="mt-8 grid gap-4 sm:gap-5">
<input
type="text"
placeholder="Название ЖК, ТСЖ или УК"
value={company}
onChange={(e) => setCompany(e.target.value)}
className="w-full rounded-2xl border border-white/10 bg-black/30 px-5 py-4 outline-none placeholder:text-neutral-500 focus:border-emerald-500"
required
/>
<input
type="tel"
placeholder="+7 (999) 123-45-67"
value={phone}
onChange={(e) => setPhone(e.target.value)}
className="w-full rounded-2xl border border-white/10 bg-black/30 px-5 py-4 outline-none placeholder:text-neutral-500 focus:border-emerald-500"
required
/>
<input
type="email"
placeholder="Email"
value={email}
onChange={(e) => setEmail(e.target.value)}
className="w-full rounded-2xl border border-white/10 bg-black/30 px-5 py-4 outline-none placeholder:text-neutral-500 focus:border-emerald-500"
required
/>
<textarea
placeholder="Опишите текущий шлагбаум и что хотите добавить"
value={message}
onChange={(e) => setMessage(e.target.value)}
className="min-h-32 w-full rounded-2xl border border-white/10 bg-black/30 px-5 py-4 outline-none placeholder:text-neutral-500 focus:border-emerald-500"
/>
<button
type="submit"
disabled={isSubmitting}
className="inline-flex items-center justify-center rounded-2xl bg-emerald-600 px-6 py-4 text-base font-semibold hover:bg-emerald-500 transition-colors disabled:opacity-60"
>
{isSubmitting ? "Отправка..." : "Отправить заявку"}
</button>
{resultMessage && (
<p className="text-sm text-neutral-300">{resultMessage}</p>
<div id={id}>
{(title || description) && (
<div className={compact ? "mb-6" : "mb-8"}>
{title && (
<h3 className="text-2xl font-semibold tracking-[-0.03em] sm:text-3xl">
{title}
</h3>
)}
{description && (
<p className="mt-3 max-w-2xl text-sm leading-relaxed text-neutral-400 sm:text-base">
{description}
</p>
)}
</div>
)}
</form>
<form onSubmit={handleSubmit} className="grid gap-4 sm:gap-5" noValidate>
<div>
<label htmlFor="lead-company" className={labelClassName}>
Объект или компания
</label>
<input
id="lead-company"
type="text"
placeholder="Например: ЖК Сокол, ТСЖ Север, УК Домсервис"
value={company}
onChange={(e) => {
setCompany(e.target.value);
if (errors.company) {
setErrors((current) => ({ ...current, company: undefined }));
}
}}
className={`${fieldClassName} ${errors.company ? "border-rose-400/70" : "border-white/10"}`}
autoComplete="organization"
required
/>
{errors.company ? (
<p className={errorClassName}>{errors.company}</p>
) : (
<p className={helperClassName}>Укажите ЖК, ТСЖ, УК или адрес объекта</p>
)}
</div>
<div>
<label htmlFor="lead-phone" className={labelClassName}>
Телефон
</label>
<input
id="lead-phone"
type="tel"
placeholder="+7 (999) 123-45-67"
value={phone}
onChange={(e) => {
setPhone(formatRussianPhoneInput(e.target.value));
if (errors.phone) {
setErrors((current) => ({ ...current, phone: undefined }));
}
}}
className={`${fieldClassName} ${errors.phone ? "border-rose-400/70" : "border-white/10"}`}
inputMode="numeric"
autoComplete="tel"
required
/>
{errors.phone ? (
<p className={errorClassName}>{errors.phone}</p>
) : (
<p className={helperClassName}>Только мобильные и городские номера РФ</p>
)}
</div>
<div>
<label htmlFor="lead-email" className={labelClassName}>
Email
</label>
<input
id="lead-email"
type="email"
placeholder="name@company.ru"
value={email}
onChange={(e) => {
setEmail(e.target.value);
if (errors.email) {
setErrors((current) => ({ ...current, email: undefined }));
}
}}
className={`${fieldClassName} ${errors.email ? "border-rose-400/70" : "border-white/10"}`}
autoComplete="email"
required
/>
{errors.email ? (
<p className={errorClassName}>{errors.email}</p>
) : (
<p className={helperClassName}>Отправим ответ и детали по этому адресу</p>
)}
</div>
<div>
<label htmlFor="lead-message" className={labelClassName}>
Комментарий
</label>
<textarea
id="lead-message"
placeholder="Коротко опишите объект, текущий шлагбаум и что хотите улучшить"
value={message}
onChange={(e) => setMessage(e.target.value)}
className="min-h-32 w-full rounded-2xl border border-white/10 bg-black/30 px-4 py-3.5 text-white outline-none transition-colors placeholder:text-neutral-500 focus:border-emerald-500 sm:px-5 sm:py-4"
/>
</div>
<button
type="submit"
disabled={isSubmitting}
className="inline-flex items-center justify-center rounded-2xl bg-emerald-600 px-6 py-4 text-base font-semibold transition-colors hover:bg-emerald-500 disabled:cursor-not-allowed disabled:opacity-60"
>
{isSubmitting ? "Отправка..." : "Оставить заявку"}
</button>
{resultMessage && (
<p className={`text-sm ${submitError ? "text-rose-300" : "text-emerald-300"}`}>
{resultMessage}
</p>
)}
</form>
</div>
);
}
}

View File

@@ -4,6 +4,7 @@ import Link from "next/link";
import { Menu, X, Send, MessageCircle, FileText } from "lucide-react";
import { useEffect, useState } from "react";
import { usePathname } from "next/navigation";
import { createPortal } from "react-dom";
type NavLink = {
href: string;
@@ -17,6 +18,7 @@ export default function MobileMenu({
}) {
const [mobileOpen, setMobileOpen] = useState(false);
const pathname = usePathname();
const canUsePortal = typeof window !== "undefined";
useEffect(() => {
if (mobileOpen) {
@@ -38,128 +40,137 @@ export default function MobileMenu({
<button
type="button"
onClick={() => setMobileOpen(true)}
className="md:hidden inline-flex items-center justify-center rounded-xl border border-white/10 bg-white/5 px-3 py-2 hover:bg-white/10 transition-colors"
className="inline-flex items-center justify-center rounded-xl border border-white/10 bg-white/5 px-3 py-2 transition-colors hover:bg-white/10 md:hidden"
aria-label="Открыть меню"
>
<Menu className="w-5 h-5" />
</button>
{mobileOpen && (
<div className="fixed inset-0 z-[999] md:hidden bg-black">
<div className="flex h-full flex-col bg-black">
<div className="flex items-center justify-between px-4 py-4 border-b border-white/10">
<div>
<div className="text-2xl font-bold leading-none">WorkParking</div>
<div className="mt-2 text-sm text-neutral-500">
Апгрейд дворовых шлагбаумов
{canUsePortal &&
mobileOpen &&
createPortal(
<div className="fixed inset-0 z-[999] w-screen overflow-x-hidden bg-black/90 backdrop-blur-xl md:hidden">
<div className="flex min-h-dvh w-full flex-col bg-[radial-gradient(circle_at_top,#133222_0%,#090909_42%,#050505_100%)]">
<div className="flex items-center justify-between border-b border-white/10 px-4 py-3">
<div className="min-w-0">
<div className="text-xl font-semibold leading-none tracking-[-0.03em]">
WorkParking
</div>
<div className="mt-1 text-xs uppercase tracking-[0.18em] text-neutral-500">
Smart entry systems
</div>
</div>
<button
type="button"
onClick={() => setMobileOpen(false)}
className="inline-flex items-center justify-center rounded-xl border border-white/10 p-2 text-neutral-300 transition-colors hover:bg-white/5 hover:text-white"
aria-label="Закрыть меню"
>
<X className="w-5 h-5" />
</button>
</div>
<button
type="button"
onClick={() => setMobileOpen(false)}
className="inline-flex items-center justify-center rounded-xl border border-white/10 p-2 text-neutral-300 hover:bg-white/5 hover:text-white transition-colors"
aria-label="Закрыть меню"
>
<X className="w-5 h-5" />
</button>
</div>
<div className="flex-1 overflow-y-auto px-4 py-5">
<div className="mx-auto w-full max-w-none">
<Link
href="/contacts#lead-form"
onClick={() => setMobileOpen(false)}
className="mb-6 flex w-full items-center justify-center gap-2 rounded-2xl bg-emerald-600 px-4 py-4 text-sm font-semibold text-white transition-colors hover:bg-emerald-500"
>
<FileText className="w-5 h-5" />
Оставить заявку
</Link>
<div className="flex-1 overflow-y-auto px-4 py-6">
<Link
href="/contacts"
onClick={() => setMobileOpen(false)}
className="mb-8 inline-flex w-full items-center justify-center gap-2 rounded-2xl bg-emerald-600 px-4 py-4 text-base font-semibold text-white hover:bg-emerald-500 transition-colors"
>
<FileText className="w-5 h-5" />
Оставить заявку
</Link>
<nav className="flex w-full flex-col rounded-3xl border border-white/10 bg-white/[0.03] px-4 py-1">
{navLinks.map((link) => {
const isActive = pathname === link.href;
<nav className="flex flex-col">
{navLinks.map((link) => {
const isActive = pathname === link.href;
return (
<Link
key={link.href}
href={link.href}
onClick={() => setMobileOpen(false)}
className={[
"block w-full border-b border-white/10 py-3.5 text-base transition-colors last:border-b-0",
isActive
? "text-emerald-300"
: "text-white hover:text-emerald-300",
].join(" ")}
>
{link.label}
</Link>
);
})}
</nav>
return (
<Link
key={link.href}
href={link.href}
onClick={() => setMobileOpen(false)}
className={[
"border-b border-white/10 py-4 text-lg transition-colors",
isActive
? "text-emerald-300"
: "text-white hover:text-emerald-300",
].join(" ")}
>
{link.label}
</Link>
);
})}
</nav>
<div className="mt-6 grid w-full gap-4">
<div className="w-full rounded-3xl border border-white/10 bg-white/[0.03] p-4">
<div className="mb-3 text-[11px] uppercase tracking-[0.22em] text-neutral-500">
Контакты
</div>
<div className="mt-10">
<div className="text-xs uppercase tracking-[0.2em] text-neutral-500 mb-4">
Контакты
<div className="flex flex-col gap-2 text-sm">
<a
href="tel:+79999698149"
className="text-neutral-200 transition-colors hover:text-emerald-300"
>
+7 (999) 969-81-49
</a>
<a
href="mailto:sale@parkflow.ru"
className="text-neutral-200 transition-colors hover:text-emerald-300"
>
sale@parkflow.ru
</a>
<a
href="mailto:info@parkflow.ru"
className="text-neutral-200 transition-colors hover:text-emerald-300"
>
info@parkflow.ru
</a>
</div>
</div>
<div className="w-full rounded-3xl border border-white/10 bg-white/[0.03] p-4">
<div className="mb-3 text-[11px] uppercase tracking-[0.22em] text-neutral-500">
Мы в сети
</div>
<div className="flex flex-wrap gap-3 text-sm">
<a
href="#"
className="rounded-full border border-white/10 px-3 py-2 text-neutral-200 transition-colors hover:text-emerald-300"
>
VK
</a>
<a
href="#"
className="inline-flex items-center gap-2 rounded-full border border-white/10 px-3 py-2 text-neutral-200 transition-colors hover:text-emerald-300"
>
<Send className="h-4 w-4" />
Telegram
</a>
<a
href="#"
className="inline-flex items-center gap-2 rounded-full border border-white/10 px-3 py-2 text-neutral-200 transition-colors hover:text-emerald-300"
>
<MessageCircle className="h-4 w-4" />
MAX
</a>
</div>
</div>
<div className="px-1 text-xs text-neutral-500">
ООО «Пракфлоу» ИНН 7777773333
</div>
</div>
</div>
<div className="flex flex-col gap-3 text-base">
<a
href="tel:+79999698149"
className="text-neutral-200 hover:text-emerald-300 transition-colors"
>
+7 (999) 969-81-49
</a>
<a
href="mailto:sale@parkflow.ru"
className="text-neutral-200 hover:text-emerald-300 transition-colors"
>
sale@parkflow.ru
</a>
<a
href="mailto:info@parkflow.ru"
className="text-neutral-200 hover:text-emerald-300 transition-colors"
>
info@parkflow.ru
</a>
</div>
</div>
<div className="mt-10">
<div className="text-xs uppercase tracking-[0.2em] text-neutral-500 mb-4">
Мы в сети
</div>
<div className="flex flex-col gap-3 text-base">
<a
href="#"
className="inline-flex items-center gap-3 text-neutral-200 hover:text-emerald-300 transition-colors"
>
VK
</a>
<a
href="#"
className="inline-flex items-center gap-3 text-neutral-200 hover:text-emerald-300 transition-colors"
>
<Send className="w-4 h-4" />
Telegram
</a>
<a
href="#"
className="inline-flex items-center gap-3 text-neutral-200 hover:text-emerald-300 transition-colors"
>
<MessageCircle className="w-4 h-4" />
MAX
</a>
</div>
</div>
<div className="mt-10 pb-6 text-sm text-neutral-500">
ООО «Пракфлоу» ИНН 7777773333
</div>
</div>
</div>
</div>
)}
</div>,
document.body,
)}
</>
);
}
}