From 88f258b54a5dd1713f3c3d87d3a23549bc343e57 Mon Sep 17 00:00:00 2001 From: Sawan Date: Wed, 6 Nov 2024 22:42:09 +0530 Subject: [PATCH] Added subscribe us feature --- client/src/App.jsx | 7 +-- client/src/component/Footer.jsx | 23 +++++++--- server/Controllers/OtherController.js | 39 +++------------- server/Models/Newsletter.js | 35 ++++++++------- server/sendSubscribeMail.js | 65 +++++++++++++++++++++++++++ 5 files changed, 110 insertions(+), 59 deletions(-) create mode 100644 server/sendSubscribeMail.js diff --git a/client/src/App.jsx b/client/src/App.jsx index d4a50f2..d34bec9 100644 --- a/client/src/App.jsx +++ b/client/src/App.jsx @@ -29,7 +29,6 @@ import Contributors from "./component/Contributors"; import Discussion from "./component/Discussion"; import ForgotPassword from "./component/ForgotPassword"; import ResetPassword from "./component/ResetPassword"; -import Feedback from "./component/Feedback"; // import VerifyEmail from "./component/Verify"; // import ProtectedRoute from '../../client/src/component/ProtectedRoute' import NotFound from "./component/NotFound"; @@ -133,9 +132,7 @@ function App() { progress={progress} onLoaderFinished={() => setProgress(0)} /> -
- -
+
@@ -273,7 +270,7 @@ function App() { } /> } /> } /> - } /> {/* Add this line */} + } /> {/* Add this line */} } /> {/* Add this line */} } /> {/* Add this line */} } /> diff --git a/client/src/component/Footer.jsx b/client/src/component/Footer.jsx index f5987e2..d7c3017 100644 --- a/client/src/component/Footer.jsx +++ b/client/src/component/Footer.jsx @@ -8,6 +8,7 @@ import VisitorCounter from './Footers/VisitorCount'; const Footer = (props) => { const [email, setEmail] = useState(""); + const [name, setName] = useState(""); const [message, setMessage] = useState(""); const [isError, setIsError] = useState(false); // Flag to handle message color const [stars, setStars] = useState(0); @@ -16,9 +17,9 @@ const Footer = (props) => { e.preventDefault(); setMessage(""); // Reset message - if (!email) { + if (!email || !name) { setIsError(true); - setMessage("Please enter a valid email."); + setMessage("Please enter valid details."); clearMessageAndResetEmail(); return; } @@ -29,13 +30,15 @@ const Footer = (props) => { headers: { "Content-Type": "application/json", }, - body: JSON.stringify({ email }), + body: JSON.stringify({ name, email }), }); const data = await response.json(); if (response.ok) { setIsError(false); + setEmail(''); + setName('') setMessage("Thank you for subscribing!"); } else { setIsError(true); @@ -55,6 +58,7 @@ const Footer = (props) => { setTimeout(() => { setMessage(""); setEmail(""); + setName("") }, 7000); }; useEffect(() => { @@ -101,16 +105,25 @@ const Footer = (props) => {

Subscribe to our Newsletter

+ setName(e.target.value)} + required + className="px-4 py-2 border border-gray-300 rounded-md w-full max-w-xs focus:outline-none text-black" + + /> setEmail(e.target.value)} required - className="px-4 py-2 border border-gray-300 rounded-md w-full max-w-xs focus:outline-none" + className="px-4 py-2 border border-gray-300 rounded-md w-full max-w-xs focus:outline-none text-black mb-0" />