'use client'; import { useState, useRef } from 'react'; import { motion, useInView } from 'framer-motion'; import { Phone, CheckCircle2, HelpCircle, AlertCircle } from 'lucide-react'; import { Button } from '@/components/ui/button'; import { Input } from '@/components/ui/input'; import { formatPhoneNumber, validatePhoneNumber } from '@/lib/utils'; import { sendTelegramNotification } from '@/lib/telegram'; import { cn } from '@/lib/utils'; const ContactForm = () => { const [phone, setPhone] = useState(''); const [isSubmitted, setIsSubmitted] = useState(false); const [error, setError] = useState(''); const [isLoading, setIsLoading] = useState(false); const ref = useRef(null); const isInView = useInView(ref, { once: true, margin: '-100px' }); const handlePhoneChange = (e: React.ChangeEvent) => { const formattedPhone = formatPhoneNumber(e.target.value); setPhone(formattedPhone); setError(''); }; const handleSubmit = async (e: React.FormEvent) => { e.preventDefault(); if (!validatePhoneNumber(phone)) { setError('Пожалуйста, введите корректный российский номер телефона'); return; } setIsLoading(true); try { const success = await sendTelegramNotification(phone, 'Форма контактов'); if (success) { setIsSubmitted(true); setError(''); setTimeout(() => { setIsSubmitted(false); setPhone(''); }, 3000); } else { setError( 'Произошла ошибка при отправке заявки. Пожалуйста, попробуйте позже.' ); } } catch { setError( 'Произошла ошибка при отправке заявки. Пожалуйста, попробуйте позже.' ); } finally { setIsLoading(false); } }; const containerVariants = { hidden: { opacity: 0 }, visible: { opacity: 1, transition: { staggerChildren: 0.2, delayChildren: 0.3, }, }, }; const itemVariants = { hidden: { y: 20, opacity: 0 }, visible: { y: 0, opacity: 1, transition: { duration: 0.5, ease: [0.16, 1, 0.3, 1], }, }, }; const listItemVariants = { hidden: { x: -20, opacity: 0 }, visible: { x: 0, opacity: 1, transition: { duration: 0.3, }, }, }; return (
{/* Фоновый паттерн */}
{/* Левая часть с текстом */}

Нужна консультация?

Оставьте свой номер телефона, и наш специалист проконсультирует вас по всем вопросам

Бесплатная консультация Ответим в течение 15 минут Подберём оптимальное решение
{/* Правая часть с формой */}
{error && (
{error}
)}

Нажимая кнопку, вы соглашаетесь с{' '} политикой конфиденциальности

); }; export default ContactForm;