diff --git a/client/src/component/Footers/Feedback.jsx b/client/src/component/Footers/Feedback.jsx index d706813..ab0118f 100644 --- a/client/src/component/Footers/Feedback.jsx +++ b/client/src/component/Footers/Feedback.jsx @@ -38,6 +38,8 @@ function Feedback(props) { // Check if the request was successful if (response.status === 200) { // Updated to check response status properly toast.success('Feedback Sent Successfully!'); + e.target.reset(); + setRating(0); setIsSubmitting(false) } else { toast.error(result.message || 'Error in submission!'); diff --git a/server/.env.sample b/server/.env.sample index 576e136..e69fe55 100644 --- a/server/.env.sample +++ b/server/.env.sample @@ -22,4 +22,8 @@ EMAIL_USER = "" EMAIL_PASS = "" GOOGLE_CLIENT_ID = "" -JWT_SECRET = "" \ No newline at end of file +JWT_SECRET = "" + +EMAIL_ID= +PASS_KEY= +ADMIN_EMAIL_ID= \ No newline at end of file diff --git a/server/Controllers/Feedback.js b/server/Controllers/Feedback.js index 4c4269d..385b418 100644 --- a/server/Controllers/Feedback.js +++ b/server/Controllers/Feedback.js @@ -1,4 +1,5 @@ const FeedbackForm = require('../Models/feedback'); +const { sendMailToAdmin } = require('../sendFeedbackToAdmin'); const submitFeedback = async (req, res) => { // Extract data from the request body @@ -27,6 +28,8 @@ const submitFeedback = async (req, res) => { rating: Rating, }; + sendMailToAdmin(feedbackData) + try { const feed = new FeedbackForm(feedbackData); diff --git a/server/sendFeedbackToAdmin.js b/server/sendFeedbackToAdmin.js new file mode 100644 index 0000000..bcd551e --- /dev/null +++ b/server/sendFeedbackToAdmin.js @@ -0,0 +1,80 @@ +const nodemailer = require('nodemailer'); +require("dotenv").config(); + +const sendMailToAdmin = (userData) => { + const transporter = nodemailer.createTransport({ + service: "gmail", + host: "smtp.gmail.com", + port: 587, + secure: false, // Use `true` for port 465, `false` for other ports + auth: { + user: process.env.EMAIL_ID, // Your email address + pass: process.env.PASS_KEY, // Your email password or app-specific password + }, + }); + + async function main() { + await transporter.sendMail({ + from: { + name: `Bitbox Feedback - ${new Date().toLocaleString()}`, + address: process.env.EMAIL_ID, + }, + to: process.env.ADMIN_EMAIL_ID, // Admin email address + subject: "New Feedback Submission from Bitbox ✔", // Email subject + text: "Bitbox Feedback Form", // Plain text body + html: `
Field | +Value | +
---|---|
Name | +${userData.name} | +
${userData.email} | +|
Subject | +${userData.subject} | +
Date of Visit | +${new Date(userData.dateOfVisit).toLocaleString()} | +
Device Used | +${userData.deviceUsed} | +
Priority Level | +${userData.priorityLevel} | +
Suggestions | +${userData.suggestions} | +
Feedback | +${userData.feedback} | +
Rating | +${userData.rating} | +
Submitted At | +${new Date().toLocaleString()} | +