From 32e4428a673d4e2bc25ee9691c26587416642058 Mon Sep 17 00:00:00 2001 From: Nishant Kaushal <101548649+nishant0708@users.noreply.github.com> Date: Sun, 28 Jul 2024 20:39:55 +0530 Subject: [PATCH] Added Feedback system --- server/controllers/feedbackController.js | 15 +++++++- server/routes/student.js | 7 +--- src/pages/FeedbackList.jsx | 48 ++++++++++++++++++++++++ src/pages/SectionPage.jsx | 47 +++++++++-------------- 4 files changed, 81 insertions(+), 36 deletions(-) create mode 100644 src/pages/FeedbackList.jsx diff --git a/server/controllers/feedbackController.js b/server/controllers/feedbackController.js index 89f12f1..dd30542 100644 --- a/server/controllers/feedbackController.js +++ b/server/controllers/feedbackController.js @@ -1,6 +1,19 @@ const asyncHandler = require('express-async-handler'); const Feedback = require("../models/studentfeeback"); +const getFeedbacksByCanteen = asyncHandler(async (req, res) => { + const { canteenId } = req.params; + + if (!canteenId) { + res.status(400); + throw new Error('Canteen ID is required'); + } + + const feedbacks = await Feedback.find({ canteenId }); + + res.status(200).json(feedbacks); +}); + const submitFeedback = asyncHandler(async (req, res) => { const { message, canteenId ,userId} = req.body; @@ -15,4 +28,4 @@ const submitFeedback = asyncHandler(async (req, res) => { res.status(201).json({ message: 'Feedback submitted successfully' }); }); -module.exports = { submitFeedback }; \ No newline at end of file +module.exports = { submitFeedback ,getFeedbacksByCanteen }; \ No newline at end of file diff --git a/server/routes/student.js b/server/routes/student.js index bd70acc..0bf0a7b 100644 --- a/server/routes/student.js +++ b/server/routes/student.js @@ -2,11 +2,8 @@ const express = require("express"); const { auth, studentAuth, isCanteen } = require("../middlewares/auth"); const router = express.Router(); const authController = require("../controllers/Auth"); -<<<<<<< HEAD const { getCanteenData } = require("../controllers/canteenController"); -======= const feedbackController = require("../controllers/feedbackController"); ->>>>>>> 56cd98b40c82e9849270fe2c43ef735b8fe058bc router.post("/studentSignup", authController.studentSignup); router.post("/studentLogin", authController.studentLogin); @@ -17,12 +14,10 @@ router.get("/resetPassword/:id/:token", authController.verifyLink); router.post("/newPassword/:id/:token", authController.resetPassword); router.get("/studentLogout", studentAuth, authController.studentLogout); router.get("/canteenLogout", auth, authController.canteenLogout); -<<<<<<< HEAD router.get("/canteen/:id", getCanteenData); -======= router.post('/submitFeedback', feedbackController.submitFeedback); +router.get('/feedbacks/:canteenId', feedbackController.getFeedbacksByCanteen); ->>>>>>> 56cd98b40c82e9849270fe2c43ef735b8fe058bc router.post( "/changeStudentPassword", studentAuth, diff --git a/src/pages/FeedbackList.jsx b/src/pages/FeedbackList.jsx new file mode 100644 index 0000000..e75811e --- /dev/null +++ b/src/pages/FeedbackList.jsx @@ -0,0 +1,48 @@ +import React, { useState, useEffect, useContext } from "react"; +import { useParams } from "react-router-dom"; +import axios from "axios"; +import Loader from "../components/Loader/Loader"; +import { ThemeContext } from "../themeContext"; + +const FeedbackList = () => { + const { _id } = useParams(); + const { theme } = useContext(ThemeContext); + const [feedbacks, setFeedbacks] = useState([]); + const [loading, setLoading] = useState(false); + + useEffect(() => { + const fetchFeedbacks = async () => { + setLoading(true); + try { + const response = await axios.get(`${process.env.REACT_APP_BASE_URL}/feedbacks/${_id}`); + setFeedbacks(response.data); + } catch (error) { + console.error("Error fetching feedbacks:", error); + } finally { + setLoading(false); + } + }; + + fetchFeedbacks(); + }, [_id]); + + if (loading) return ; + + return ( +
+

Feedbacks

+ {feedbacks.length > 0 ? ( + feedbacks.map((feedback) => ( +
+

{feedback.message}

+

User ID: {feedback.userId}

+
+ )) + ) : ( +

No feedback available.

+ )} +
+ ); +}; + +export default FeedbackList; diff --git a/src/pages/SectionPage.jsx b/src/pages/SectionPage.jsx index a54d249..d5930f3 100644 --- a/src/pages/SectionPage.jsx +++ b/src/pages/SectionPage.jsx @@ -1,30 +1,25 @@ import React, { useState, useEffect, useContext } from "react"; import { useParams, useNavigate } from "react-router-dom"; -import Modal from "../components/Modal"; import Navbar from "../components/Navbar"; import Loader from "../components/Loader/Loader"; import Footer from "../components/Footer"; import AddFoodItem from "./AddFoodItem"; -import EditProfile from "./EditProfile"; import Foodlist from "./Foodlist"; +import FeedbackList from "./FeedbackList"; // Import the new component import { ThemeContext } from "../themeContext"; import { FaRegEdit } from "react-icons/fa"; import { CiBoxList } from "react-icons/ci"; import { IoMdAdd } from "react-icons/io"; +import { FaComments } from "react-icons/fa"; // Import an icon for feedback + const SectionPage = () => { const { _id } = useParams(); const navigate = useNavigate(); const { theme } = useContext(ThemeContext); - const [showModal, setShowModal] = useState(false); - const [selectedSection, setSelectedSection] = useState(""); - const [formData, setFormData] = useState(null); - const [selectedBreakfastRecipes, setSelectedBreakfastRecipes] = useState([]); - const [selectedLunchRecipes, setSelectedLunchRecipes] = useState([]); - const [selectedDinnerRecipes, setSelectedDinnerRecipes] = useState([]); const [loading, setLoading] = useState(false); const [canteenData, setCanteenData] = useState(); const [view, setView] = useState("add"); - + const getCanteenData = async () => { try { setLoading(true); @@ -50,23 +45,6 @@ const SectionPage = () => { getCanteenData(); }, [_id]); - const handleSectionClick = (sectionName) => { - setSelectedSection(sectionName); - setShowModal(true); - }; - - const handleFormSubmit = (data) => { - if (selectedSection === "Breakfast") { - setSelectedBreakfastRecipes([...selectedBreakfastRecipes, data]); - } else if (selectedSection === "Lunch") { - setSelectedLunchRecipes([...selectedLunchRecipes, data]); - } else if (selectedSection === "Dinner") { - setSelectedDinnerRecipes([...selectedDinnerRecipes, data]); - } - setFormData(data); - setShowModal(false); - }; - return (
{
- {loading ? ( ) : ( @@ -114,9 +91,21 @@ const SectionPage = () => { > Product List +
-
- {view === "add" ? : } +
+ {view === "add" && } + {view === "list" && } + {view === "feedback" && } {/* Render FeedbackList */}
)}