Skip to content

Commit

Permalink
added feedback form
Browse files Browse the repository at this point in the history
  • Loading branch information
AyushSharma72 committed Nov 10, 2024
1 parent 497bc5c commit 3a81f30
Show file tree
Hide file tree
Showing 7 changed files with 298 additions and 36 deletions.
79 changes: 76 additions & 3 deletions backend/controllers/complaintController.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
import nodemailer from "nodemailer";
import Complaint from "../models/Complaint.js";
import Feedback from "../models/feedbackmodal.js";

const transporter = nodemailer.createTransport({
service: "gmail",
auth: {
user: process.env.EMAIL_USER,
pass: process.env.EMAIL_PASS,
user: "taskmaster991@gmail.com",
pass: "kmepakzcabvztekd",
},
});

Expand Down Expand Up @@ -81,4 +82,76 @@ const submitComplaint = async (req, res) => {
}
};

export default submitComplaint;
const sendFeedbackEmail = async (req, res) => {
const { senderEmail, message } = req.body;

// Check if the email and message fields are provided
if (!senderEmail || !message) {
return res.status(400).json({ message: "Email and message are required." });
}

// Save the feedback data into the database
try {
const feedback = new Feedback({
senderEmail,
message,
});

// Save feedback into the database
await feedback.save();

// Prepare the email content
const userMailOptions = {
from: process.env.EMAIL_USER, // Your email address from your environment variables
to: senderEmail, // The email address of the sender (the user who submitted feedback)
subject: "Thank you for your feedback on Station Saarthi",
html: `
<div style="font-family: Arial, sans-serif; color: #333; max-width: 600px; margin: 0 auto; border: 1px solid #e0e0e0; border-radius: 8px;">
<!-- Header with embedded image -->
<div style="background-color: #63afeb; padding: 20px; text-align: center; border-top-left-radius: 8px; border-top-right-radius: 8px; border-bottom: 1px solid #e0e0e0;">
<img src="cid:StationGuide" alt="Station Saarthi Logo" style="max-width: 200px; height: auto; margin-bottom: 10px;" />
<h1 style="color: #000000; margin: 0;">Thank you for your feedback!</h1>
</div>
<!-- Body Content -->
<div style="padding: 20px; text-align: left;">
<p>Dear Customer,</p>
<p>We appreciate you taking the time to give us feedback. Here’s a copy of what you sent us:</p>
<p><strong>Your Feedback:</strong> ${message}</p>
<p>If you have more thoughts, feel free to reach out to us again.</p>
</div>
<!-- Footer -->
<div style="background-color: #f5f5f5; padding: 15px; text-align: center; border-bottom-left-radius: 8px; border-bottom-right-radius: 8px;">
<p style="font-size: 14px; color: #666;">Best Regards,<br><strong>Station Saarthi Team</strong></p>
<p style="font-size: 12px; color: #999;">&copy; ${new Date().getFullYear()} Station Saarthi. All rights reserved.</p>
</div>
</div>
`,
attachments: [
{
filename: "thank-you-image.jpg",
path: "C:/Users/ayush/OneDrive/Desktop/StationGuide/frontend/src/assets/station.png",
cid: "StationGuide",
},
],
};

// Send the email
await transporter.sendMail(userMailOptions);
console.log("Feedback confirmation email sent to the user.");

// Send a success response to the client
res.status(200).json({
message: "Feedback received successfully, confirmation email sent!",
});
} catch (error) {
console.error("Error saving feedback or sending email:", error);
// Send error response if something goes wrong
res.status(500).json({
message: "Error saving feedback or sending confirmation email.",
});
}
};

export { submitComplaint, sendFeedbackEmail };
21 changes: 21 additions & 0 deletions backend/models/feedbackmodal.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import mongoose from "mongoose";

// Define the Feedback schema
const feedbackSchema = new mongoose.Schema(
{
senderEmail: {
type: String,
required: true,
match: [/\S+@\S+\.\S+/, "Please provide a valid email address"],
},
message: {
type: String,
required: true,
maxlength: [500, "Feedback message cannot exceed 500 characters"],
},
},
{ timestamps: true }
);

const Feedback = mongoose.model("Feedback", feedbackSchema);
export default Feedback;
12 changes: 7 additions & 5 deletions backend/routes/complaintRoutes.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
// routes/complaint.js
import express from 'express'
import submitComplaint from '../controllers/complaintController.js';

import express from "express";
import { submitComplaint } from "../controllers/complaintController.js";
import { sendFeedbackEmail } from "../controllers/complaintController.js";

const router = express.Router();

// Handle complaint submission
router.post('/complaint', submitComplaint);
router.post("/complaint", submitComplaint);

router.post("/userfeedback", sendFeedbackEmail);

export default router
export default router;
66 changes: 51 additions & 15 deletions frontend/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions frontend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
"@mui/material": "^6.1.6",
"@react-oauth/google": "^0.12.1",
"antd": "^5.21.6",
"aos": "^2.3.4",
"axios": "^1.7.7",
"dotenv": "^16.4.5",
"firebase": "^11.0.1",
Expand Down
22 changes: 9 additions & 13 deletions frontend/src/App.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,12 @@ import User from "./Pages/User"; // Added from the other version
import ComplainBox from "./Pages/ComplainBox";
import Metadata from "./metadata";
import SettingsPage from "./Pages/Settings";
import Faq from './Pages/Faq';

import Faq from "./Pages/Faq";
import Feedback from "./Pages/feedback";
import TicketSearchComponent from "./Pages/TicketsAvailability";

import ProfilePage from "./Pages/Profile";


function App() {
return (
<>
Expand All @@ -54,12 +53,9 @@ function App() {
<Route path="/Notification" element={<NotificationPage />} />
<Route path="/chatbot" element={<Chatbot />} />
<Route path="/ContactUs" element={<ContactUs />} />

<Route path="/Tickets" element={<TicketSearchComponent/>} />

<Route path="/Tickets" element={<TicketSearchComponent />} />
<Route path="/Feedback" element={<Feedback />} />
<Route path="/profile" element={<ProfilePage />} />


<Route path="/GoogleTranslate" element={<GoogleTranslate />} />
<Route path="/help" element={<Help />} />
<Route path="/about" element={<AboutUs />} />
Expand All @@ -70,7 +66,7 @@ function App() {
<Route path="/help-and-support" element={<HelpAndSupport />} />
<Route path="/settings" element={<SettingsPage />} />
<Route path="/Faq" element={<Faq />} />
<Route path="/complain" element={<ComplainBox/>} />
<Route path="/complain" element={<ComplainBox />} />
<Route path="/privacy-policy" element={<PrivacyPolicy />} />{" "}
{/* Restored PrivacyPolicy */}
<Route path="/user" element={<User />} /> {/* Added User */}
Expand Down Expand Up @@ -105,15 +101,15 @@ export function ProtectedRoute() {
console.log("Token Verification error:", data.error);

if (data.error || res.status === 400 || res.status === 500) {
navigate('/Login');
navigate("/Login");
}

if (res.status === 400 || res.status === 500) {
navigate('/Login');
navigate("/Login");
}
} catch (error) {
console.error('Error verifying token:', error);
navigate('/Login');
console.error("Error verifying token:", error);
navigate("/Login");
}
};

Expand Down
Loading

0 comments on commit 3a81f30

Please sign in to comment.