|
| 1 | +import React, { useEffect, useState } from 'react'; |
| 2 | + |
| 3 | +const NewsletterPopup = () => { |
| 4 | + const [showPopup, setShowPopup] = useState(false); |
| 5 | + |
| 6 | + useEffect(() => { |
| 7 | + const hasSubscribed = localStorage.getItem('recodehive_newsletter_popup'); |
| 8 | + |
| 9 | + if (hasSubscribed !== 'true') { |
| 10 | + const handleScroll = () => { |
| 11 | + const scrollPosition = window.scrollY + window.innerHeight; |
| 12 | + const pageHeight = document.body.scrollHeight; |
| 13 | + |
| 14 | + if ((scrollPosition / pageHeight) >= 0.8) { |
| 15 | + setShowPopup(true); |
| 16 | + window.removeEventListener('scroll', handleScroll); |
| 17 | + } |
| 18 | + }; |
| 19 | + |
| 20 | + window.addEventListener('scroll', handleScroll); |
| 21 | + return () => window.removeEventListener('scroll', handleScroll); |
| 22 | + } |
| 23 | + }, []); |
| 24 | + |
| 25 | + const handleClose = () => { |
| 26 | + setShowPopup(false); |
| 27 | + localStorage.setItem('recodehive_newsletter_popup', 'true'); |
| 28 | + }; |
| 29 | + |
| 30 | + if (!showPopup) return null; |
| 31 | + |
| 32 | + return ( |
| 33 | + <div className="fixed inset-0 z-50 flex items-center justify-center bg-black/50 px-4"> |
| 34 | + <div className="bg-white/80 backdrop-blur-xl max-w-xl w-full rounded-3xl shadow-2xl p-8 text-center relative border border-gray-200 animate-fade-in"> |
| 35 | + <img |
| 36 | + src="/img/logo.png" |
| 37 | + alt="RecodeHive Logo" |
| 38 | + className="w-16 h-16 mx-auto mb-4 rounded-full shadow-md" |
| 39 | + /> |
| 40 | + |
| 41 | + <h2 className="text-3xl font-extrabold mb-2 text-gray-900">Sanjay’s Substack</h2> |
| 42 | + |
| 43 | + <p className="text-gray-700 text-base leading-relaxed mb-4"> |
| 44 | + Recodehive is an inclusive and welcoming platform where everyone can contribute, |
| 45 | + learn, and grow together. ⚡ <br /> |
| 46 | + Check my ✨ Website: <a href="https://www.recodehive.com" target="_blank" className="text-blue-600 hover:underline font-medium">https://www.recodehive.com </a><br /> |
| 47 | + 📮 How to reach me: <a href="https://github.com/sanjay-kv" target="_blank" className="text-blue-600 hover:underline font-medium">github.com/sanjay-kv</a><br /> |
| 48 | + 👫 Join my opensource community |
| 49 | + </p> |
| 50 | + |
| 51 | + <p className="text-sm font-semibold text-gray-700 mb-4"> |
| 52 | + By <span className="text-gray-900">Sanjay Viswanathan</span> · Over <span className="text-gray-900">31,000 subscribers</span> |
| 53 | + </p> |
| 54 | + |
| 55 | + <form |
| 56 | + className="flex items-stretch w-full border-2 border-gray-300 rounded-xl overflow-hidden bg-white shadow-inner mb-4 focus-within:ring-2 focus-within:ring-blue-500" |
| 57 | + onSubmit={(e) => { |
| 58 | + e.preventDefault(); |
| 59 | + alert('Subscribed! (Integrate with Substack API)'); |
| 60 | + handleClose(); |
| 61 | + }} |
| 62 | + > |
| 63 | + <input |
| 64 | + type="email" |
| 65 | + required |
| 66 | + placeholder="Type your email..." |
| 67 | + className="flex-1 px-4 py-2 text-sm bg-transparent focus:outline-none text-gray-800 placeholder-gray-400" |
| 68 | + /> |
| 69 | + <button |
| 70 | + type="submit" |
| 71 | + className="bg-gradient-to-r from-orange-400 to-orange-600 text-white px-6 text-sm font-bold transition duration-300 hover:from-orange-500 hover:to-orange-700" |
| 72 | + > |
| 73 | + Subscribe |
| 74 | + </button> |
| 75 | + </form> |
| 76 | + |
| 77 | + <p className="text-xs text-gray-500 mb-4"> |
| 78 | + By subscribing, I agree to Substack’s{' '} |
| 79 | + <a href="#" className="underline hover:text-blue-600">Terms of Use</a> and acknowledge its{' '} |
| 80 | + <a href="#" className="underline hover:text-blue-600">Information Collection Notice</a> and{' '} |
| 81 | + <a href="#" className="underline hover:text-blue-600">Privacy Policy</a>. |
| 82 | + </p> |
| 83 | + |
| 84 | + <button |
| 85 | + onClick={handleClose} |
| 86 | + className="text-sm text-gray-600 font-medium hover:text-black transition" aria-label="Close newsletter popup" |
| 87 | + > |
| 88 | + No thanks → |
| 89 | + </button> |
| 90 | + </div> |
| 91 | + </div> |
| 92 | + ); |
| 93 | +}; |
| 94 | + |
| 95 | +export default NewsletterPopup; |
0 commit comments