-
-
Notifications
You must be signed in to change notification settings - Fork 110
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #445 from Sawan-Kushwah/feat/newsletter
✨ Added newsletter functionality to glassy ui ✨
- Loading branch information
Showing
6 changed files
with
179 additions
and
33 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
import NewsLetter from '../model/Newsletter.js'; | ||
import { sendMailToSubscriber } from '../sendSuscribedMail.js'; | ||
|
||
export async function saveNewsletter(req, res) { | ||
try { | ||
const { name, email } = req.body; | ||
|
||
if (!name || !email) { | ||
return res.status(400).json({ message: 'All fields are required.' }); | ||
} | ||
|
||
// Create new contact document | ||
const newNewsLetter = new NewsLetter({ name, email }); | ||
sendMailToSubscriber(newNewsLetter); | ||
await newNewsLetter.save(); | ||
res | ||
.status(201) | ||
.json({ message: 'Contact form submitted successfully!', newNewsLetter }); | ||
} catch (error) { | ||
console.error('Error saving contact form:', error); | ||
res.status(500).json({ message: 'Failed to submit contact form.', error }); | ||
} | ||
} | ||
|
||
export async function getNewsletter(req, res) { | ||
res.send('hello newsletter'); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
import mongoose from 'mongoose'; | ||
|
||
const newsletterSchema = new mongoose.Schema({ | ||
name: { | ||
type: String, | ||
required: true, | ||
trim: true, | ||
}, | ||
email: { | ||
type: String, | ||
required: true, | ||
trim: true, | ||
match: [/^\S+@\S+\.\S+$/, 'Please enter a valid email address'], | ||
}, | ||
subscribedAt: { | ||
type: Date, | ||
default: Date.now, | ||
}, | ||
}); | ||
|
||
const Newsletter = mongoose.model('Newsletter', newsletterSchema); | ||
|
||
export default Newsletter; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
import express from 'express'; | ||
const router = express.Router(); | ||
import { | ||
getNewsletter, | ||
saveNewsletter, | ||
} from '../controllers/newsletterController.js'; | ||
|
||
router.post('/subscribe', saveNewsletter); | ||
router.get('/getNewsletter', getNewsletter); | ||
|
||
export default router; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
import nodemailer from 'nodemailer'; | ||
import dotenv from 'dotenv'; | ||
dotenv.config(); | ||
|
||
const sendMailToSubscriber = userdata => { | ||
const transporter = nodemailer.createTransport({ | ||
service: 'gmail', | ||
host: 'smtp.gmail.com', | ||
port: 587, | ||
secure: false, | ||
auth: { | ||
user: process.env.EMAIL_ID, | ||
pass: process.env.PASS_KEY, | ||
}, | ||
}); | ||
|
||
async function main() { | ||
await transporter.sendMail({ | ||
from: { | ||
name: 'GlassyUI-Components', | ||
address: process.env.EMAIL_ID, | ||
}, | ||
to: userdata.email, | ||
subject: 'Welcome to GlassyUI-Components! 🎉', | ||
text: 'Thank you for subscribing to GlassyUI-Components!', | ||
html: ` | ||
<div style="background-color: #e0f7fa; color: #333; padding: 20px; font-family: Arial, sans-serif;"> | ||
<div style="max-width: 600px; margin: 0 auto; background: rgba(255, 255, 255, 0.8); padding: 20px; border-radius: 15px; box-shadow: 0 8px 16px rgba(0, 0, 0, 0.2); backdrop-filter: blur(10px);"> | ||
<h2 style="text-align: center; color: #00acc1;">Welcome to GlassyUI-Components, ${userdata.name}!</h2> | ||
<p style="font-size: 16px; line-height: 1.6; color: #555;"> | ||
Hi ${userdata.name}, | ||
</p> | ||
<p style="font-size: 16px; line-height: 1.6; color: #555;"> | ||
We’re thrilled to have you join us at GlassyUI-Components, an open-source library that brings you beautiful glassmorphism-themed React components. Our library is perfect for creating sleek, modern web applications, and we can’t wait for you to explore and enjoy it! | ||
</p> | ||
<h3 style="color: #00acc1; margin-top: 20px;">✨ Features</h3> | ||
<ul style="font-size: 16px; line-height: 1.6; color: #555;"> | ||
<li>Glassmorphism-themed React components</li> | ||
<li>Customizable styles with SCSS</li> | ||
<li>Beginner-friendly and easy to contribute</li> | ||
<li>Modular and reusable components</li> | ||
</ul> | ||
<p style="font-size: 16px; line-height: 1.6; color: #555;"> | ||
Stay tuned for the latest updates and don’t hesitate to contribute to make GlassyUI-Components even better! | ||
</p> | ||
<p style="font-size: 16px; line-height: 1.6; color: #555;"> | ||
Best Regards, <br/> | ||
The GlassyUI-Components Team | ||
</p> | ||
</div> | ||
</div> | ||
`, | ||
}); | ||
} | ||
|
||
main().catch(console.error); | ||
}; | ||
|
||
export { sendMailToSubscriber }; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters