FacultyCourses Component Documentation
Overview
The FacultyCourses component displays the courses a faculty member is teaching during the current semester. It handles data fetching, loading, error, and empty states, and provides action links for announcements, assignments, attendance, students, feedback, and detailed views.
File Location
File Name: FacultyCourses.js (or .jsx)
Dependencies
- React: Core UI library.
- React Query (
@tanstack/react-query): For data fetching and caching. - newRequest: Custom HTTP client from
../../utils/newRequest. - React Icons (
react-icons/fa): Icons for UI (e.g.,FaBookOpen,FaBullhorn). - React Router (
react-router-dom):Linkfor navigation.
Data Fetching
- Retrieves
userIdfromlocalStorage(currentUserobject). - Uses
useQuerywith key["faculty-courses"]to fetch/faculty/{userId}/courses. - Sets
isFeedbackAvailablebased onres.data.feedbackOpen.
Component Structure
- Header
- Title and subtitle explaining the view.
- Loading State
- Spinner animation and loading message.
- Error / Empty States
- Styled message with optional return link.
- Courses Grid (
grid-cols-1 lg:grid-cols-2) - Course Card:
- Header: Course name, code, and credits badge.
- Stats Row: Students, assignments, avg. attendance.
- Instructor Actions: Links for announcements, assignments, attendance, students.
- Feedback Link: Conditional link if feedback is available.
- Detail Link: View course details.
- Management Links
- Links to request new course and view teaching schedule.
- Feedback Notice
- Message when feedback is closed.
Usage Example
import FacultyCourses from './FacultyCourses';
function Dashboard() {
return <FacultyCourses />;
}
Notes
- Query Key: Consider including
userIdin the key:['faculty-courses', userId]. - Navigation:
useNavigateimport is unused; can be removed or implemented for redirects. - Accessibility: Add ARIA labels for icons and links.
- Tailwind CSS: Ensure project is configured.