diff --git a/src/components/Footer.tsx b/src/components/Footer.tsx index c8033f4..bd0299c 100644 --- a/src/components/Footer.tsx +++ b/src/components/Footer.tsx @@ -5,10 +5,18 @@ const Footer: React.FC = () => { const [email, setEmail] = useState(''); const [isSubmitting, setIsSubmitting] = useState(false); const [submitted, setSubmitted] = useState(false); + const [emailError, setEmailError] = useState(''); const handleSubmit = async (e: FormEvent) => { e.preventDefault(); - if (!email) return; + const isValidEmail = (email: string) => + /^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(email); + + if (!isValidEmail(email)) { + setEmailError('Please enter a valid email address.'); + return; + } + setEmailError(''); setIsSubmitting(true); try { const response = await fetch( @@ -136,18 +144,26 @@ const Footer: React.FC = () => {

{submitted ? (
- You're subscribed — thanks! + You're subscribed — thanks!
) : (
setEmail(e.target.value)} + onChange={e => { + setEmail(e.target.value); + setEmailError(''); + }} placeholder='your@email.com' required className='footer-input' /> + {emailError && ( +

+ {emailError} +

+ )}