Skip to content

Commit

Permalink
Merge pull request #464 from nishant0708/Feedbacks
Browse files Browse the repository at this point in the history
Feat:Canteen Should able to see Feedback Given to Them by User (UI +Integration) #448
  • Loading branch information
hustlerZzZ authored Jul 30, 2024
2 parents 9606082 + bc01f15 commit efae5be
Show file tree
Hide file tree
Showing 4 changed files with 87 additions and 44 deletions.
29 changes: 20 additions & 9 deletions server/controllers/feedbackController.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,20 @@
const asyncHandler = require('express-async-handler');
const Feedback = require('../models/studentfeedback');
const { validationResult } = require('express-validator'); // For input validation
// Middleware for input validation (example using express-validator)
const validateFeedback = [
check('message').notEmpty().withMessage('Message is required'),
check('canteenId').notEmpty().withMessage('Canteen ID is required'),
check('userId').notEmpty().withMessage('User ID is required')
];
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) => {
// Validate request inputs
const errors = validationResult(req);
Expand All @@ -23,4 +31,7 @@ const submitFeedback = asyncHandler(async (req, res) => {
res.status(500).json({ error: 'Server error, could not submit feedback' });
}
});
module.exports = { submitFeedback, validateFeedback };


module.exports = { submitFeedback ,getFeedbacksByCanteen };

7 changes: 1 addition & 6 deletions server/routes/student.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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,
Expand Down
48 changes: 48 additions & 0 deletions src/pages/FeedbackList.jsx
Original file line number Diff line number Diff line change
@@ -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 <Loader />;

return (
<div className={`min-h-screen ${theme === "dark" ? "bg-[#131b33] text-white" : "bg-white text-gray-900"}`}>
<h1 className="text-4xl font-bold mb-8 text-center">Feedbacks</h1>
{feedbacks.length > 0 ? (
feedbacks.map((feedback) => (
<div key={feedback._id} className="border border-gray-300 rounded p-4 mb-4">
<p>{feedback.message}</p>
<p className="text-gray-500">User ID: {feedback.userId}</p>
</div>
))
) : (
<p className="text-center">No feedback available.</p>
)}
</div>
);
};

export default FeedbackList;
47 changes: 18 additions & 29 deletions src/pages/SectionPage.jsx
Original file line number Diff line number Diff line change
@@ -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);
Expand All @@ -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 (
<div
className={`text-center ${
Expand All @@ -76,7 +54,6 @@ const SectionPage = () => {
<Navbar />

<div className="relative bg-white">

{loading ? (
<Loader />
) : (
Expand Down Expand Up @@ -114,9 +91,21 @@ const SectionPage = () => {
>
Product List <CiBoxList />
</button>
<button
className={`mx-4 mt-2 py-3 px-4 flex items-center w-fit rounded-full border-green-400 border-2 ${
view === "feedback"
? " bg-transparent text-green-500"
: "bg-transparent text-green-500"
} flex gap-2 `}
onClick={() => setView("feedback")}
>
Feedbacks <FaComments />
</button>
</div>
<div className={ ` py-[10%] ${theme === 'dark' ? 'bg-[#131b33]' : 'bg-white'}` }>
{view === "add" ? <AddFoodItem /> : <Foodlist />}
<div className={`py-[10%] ${theme === "dark" ? "bg-[#131b33]" : "bg-white"}`}>
{view === "add" && <AddFoodItem />}
{view === "list" && <Foodlist />}
{view === "feedback" && <FeedbackList />} {/* Render FeedbackList */}
</div>
</>
)}
Expand Down

0 comments on commit efae5be

Please sign in to comment.