Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added Newsletter-Form #375

Merged
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion backend/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@ require("dotenv").config();
const cors = require("cors");
const mongoose = require("mongoose");
const logger = require("./config/logger");
const errorMiddleware = require("./middlewares/errorMiddleware"); // Corrected typo
const newsletterRoute = require('./routes/newsletterRoute');
const errorMiddleware = require("./middlewares/errrorMiddleware"); // Corrected typo
const passport = require("passport");
const { handleGoogleOAuth } = require("./controller/googleOAuth.controller");
const app = express();
Expand All @@ -18,6 +19,7 @@ const corsOptions = {
app.use(cors(corsOptions));

app.use(express.json());
app.use('/api', newsletterRoute);

// MongoDB connection
mongoose
Expand Down
47 changes: 47 additions & 0 deletions frontend/src/components/Shared/footer/Content.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,57 @@ export default function Content() {
<div className="bg-black pt-16 py-8 px-12 h-full w-full flex flex-col justify-between md:pt-24`">
<Nav />
<Section2 />
<NewsletterForm />
</div>
);
}

const NewsletterForm = () => {
const [email, setEmail] = useState('');
const [message, setMessage] = useState('');

const handleSubmit = async (e) => {
e.preventDefault();
try {
const response = await fetch('/api/newsletterRouter', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify({ email }),
});

if (response.ok) {
setMessage('Thank you for subscribing!');
setEmail('');
} else {
setMessage('Something went wrong. Please try again.');
}
} catch (error) {
setMessage('An error occurred. Please try again.');
}
};

return (
<div className="absolute top-4 right-4 bg-gray-800 p-4 rounded-lg shadow-lg">
<h3 className="text-white text-lg mb-2">Subscribe to our Newsletter</h3>
<form onSubmit={handleSubmit} className="flex">
<input
type="email"
className="p-2 rounded-l-md"
placeholder="Enter your email"
value={email}
onChange={(e) => setEmail(e.target.value)}
required
/>
<button type="submit" className="p-2 bg-green-500 text-white rounded-r-md">
Subscribe
</button>
</form>
{message && <p className="mt-2 text-sm text-green-500">{message}</p>}
</div>
);
};
const Section2 = () => {
const [isWide, setIsWide] = useState(null);

Expand Down