FeedbackFaculty Component
Overview
FeedbackFaculty is a React functional component that displays a feedback report for a specific course taught by a faculty member. It shows two main views: - A summary of ratings on different course aspects. - A list of student comments. The component uses course data passed through route navigation state and pulls feedback details from a backend API.
Dependencies
import React, { useState, useEffect } from 'react';
import { useNavigate, useParams, useLocation } from 'react-router-dom';
import newRequest from '../../utils/newRequest';
import { FaArrowLeft, FaChartBar, FaCommentDots, FaStar } from "react-icons/fa";
- React (useState, useEffect): for component lifecycle and state handling.
- React Router DOM: useLocation – to access course details passed via navigation. useNavigate – to go back to the previous page. useParams – unused but imported.
- newRequest: an Axios-like instance used for API calls.
- React-icons: for UI icons (FaArrowLeft, FaChartBar, etc.).
Event Handlers
- setActiveTab: Switches between the "Summary" and "Comments" tab.
onClick={() => setActiveTab('summary')}
onClick={() => setActiveTab('comments')}
- navigate: Navigates back to the course list page.
onClick={() => navigate(-1)}
Data Fetching
useEffect(() => {
if (!selectedCourseCode) {
setError('No course code provided.');
setLoading(false);
return;
}
const fetchFeedbackData = async () => {
try {
const res = await newRequest.get(`/feedback/faculty/${facultyId}/${selectedCourseCode}`);
const { statistics, feedback } = res.data;
setFeedbackStats(statistics);
setFeedbacks(feedback);
setLoading(false);
} catch (err) {
setError('Failed to load feedback data');
setLoading(false);
}
};
fetchFeedbackData();
}, [selectedCourseCode]);
UI Structure
-
Header & Navigation:
<button onClick={() => navigate(-1)} className="..."> <FaArrowLeft /> Back to Courses </button> -
Course Info:
<h1>{selectedCourseName}</h1> <p>{selectedCourseCode} | {selectedDepartment}</p> -
Tab Buttons
<button className={activeTab === 'summary' ? '...' : '...'}>Summary</button> <button className={activeTab === 'comments' ? '...' : '...'}>Comments</button>
Summary Tab: Loops over feedback sections and shows: Comments Tab: Lists all feedback comments with date and student label.
{feedbackStats?.sections?.map((section) => (
<div key={section.id}>
<h2>{section.title}</h2>
{Object.entries(section.questions).map(([questionId, question]) => (
<div key={questionId}>
<h3>{feedbackQuestions[questionId]}</h3>
<div>Avg: {question.average}/5</div>
...
</div>
))}
</div>
))}
{feedbacks.map((feedback, index) => (
<div key={index}>
<div>{new Date(feedback.createdAt).toLocaleDateString()}</div>
<div>Student: {feedback.student || 'Anonymous'}</div>
<p>"{feedback.comments}"</p>
</div>
))}
Loading and Error States
- Loading Spinner:
if (loading) return (
<div>
<div className="animate-spin ..."></div>
<p>Loading feedback report...</p>
</div>
);
- Error Handling:
if (error) return ( <div className="text-red-600"> {error} <button onClick={() => navigate(-1)}>Back</button> </div> ); - Invalid Course Fallback:
if (!courseCode) return (
<div className="text-red-600">
Invalid course information
<button onClick={() => navigate(-1)}>Back</button>
</div>
);
Scope of Improvement
Area Suggestions ---------------- ------------------ Code Reuse Move repeated navigation buttons into a reusable component. UI Framework Use a UI library like Tailwind UI, Material UI, or Chakra for consistency. Charting Use bar charts or radar graphs (e.g., chart.js) for feedback summary. Pagination/Filtering Add filters or pagination for long feedback comment lists. Error Feedback Show specific API errors or validation issues. Accessibility Add ARIA labels for screen readers.
Usage
This component is intended to be used in a faculty dashboard where an instructor clicks on a course to view its feedback.