'use client'; import { useState } from 'react'; import { motion, AnimatePresence } from 'framer-motion'; import { Phone, CheckCircle2, X, 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'; interface ContactModalProps { isOpen: boolean; onClose: () => void; } const ContactModal = ({ isOpen, onClose }: ContactModalProps) => { const [phone, setPhone] = useState(''); const [isSubmitted, setIsSubmitted] = useState(false); const [error, setError] = useState(''); const [isLoading, setIsLoading] = useState(false); 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(''); onClose(); }, 2000); } else { setError( 'Произошла ошибка при отправке заявки. Пожалуйста, попробуйте позже.' ); } } catch (error) { setError( 'Произошла ошибка при отправке заявки. Пожалуйста, попробуйте позже.' ); } finally { setIsLoading(false); } }; const modalVariants = { hidden: { opacity: 0, scale: 0.8 }, visible: { opacity: 1, scale: 1, transition: { duration: 0.2, ease: [0.16, 1, 0.3, 1], }, }, exit: { opacity: 0, scale: 0.8, transition: { duration: 0.2, }, }, }; return ( {isOpen && ( e.stopPropagation()} >

Оставить заявку

Оставьте свой номер телефона, и мы свяжемся с вами в ближайшее время

{error && (
{error}
)}

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

)}
); }; export default ContactModal;