diff --git a/src/layouts/app/SideNav.tsx b/src/layouts/app/SideNav.tsx index 0c6c036..984198b 100644 --- a/src/layouts/app/SideNav.tsx +++ b/src/layouts/app/SideNav.tsx @@ -9,10 +9,8 @@ import { import { FontAwesomeIcon } from '@fortawesome/react-fontawesome'; import { faFilePen, - faBuildingUser, faMedal, faRankingStar, - faClockRotateLeft, faChartColumn, faChalkboardUser, faGraduationCap, @@ -78,11 +76,11 @@ const candidateItems: MenuProps['items'] = [ null ), ]), - getItem( - Organizations , - 'organizations', - - ), + // getItem( + // Organizations , + // 'organizations', + // + // ), getItem( Badges , 'badges', @@ -93,11 +91,11 @@ const candidateItems: MenuProps['items'] = [ 'grading', ), - getItem( - Activity History , - 'activity_history', - - ), + // getItem( + // Activity History , + // 'activity_history', + // + // ), ]; // org admin items diff --git a/src/pages/candidate/CandidateGrading.tsx b/src/pages/candidate/CandidateGrading.tsx index 47d9d5b..16a638b 100644 --- a/src/pages/candidate/CandidateGrading.tsx +++ b/src/pages/candidate/CandidateGrading.tsx @@ -1,79 +1,95 @@ -import { Button, Flex, Table, Typography } from "antd"; - +import{ useEffect, useState } from "react"; +import {Table, Typography, notification } from "antd"; +import axios from "axios"; export const CandidateGrading = () => { - - const grades = [ - { - key: 1, - org_name: 'Java Institute', - exam_name: 'Java programming for beginners - 2024', - grade: 'A', - score: 90, - date: '2024-07-01', - exam_id: 1 - }, - { - key: 2, - org_name: 'UCSC', - exam_name: 'Advanced Java programming - 2024', - grade: 'B', - score: 80, - date: '2024-07-01', - exam_id: 2 - }, - { - key: 3, - org_name: 'SLIIT', - exam_name: 'Python programming - 2024', - grade: 'C', - score: 70, - date: '2024-07-01', - exam_id: 3 - }, - ] + const [grades, setGrades] = useState([]); + const [loading, setLoading] = useState(false); + + // Fetch data from API + const fetchGrades = async () => { + const accessToken = sessionStorage.getItem("accessToken"); + const userString = sessionStorage.getItem('user'); + if (!userString || !accessToken) { + console.error("User information or token not found in session storage."); + return; + } + + const user = JSON.parse(userString); + const candidateId = user?.id; + + if (!accessToken || !candidateId) { + notification.error({ + message: "Error", + description: "Missing authorization token or candidate ID.", + }); + return; + } + + try { + setLoading(true); + const response = await axios.get( + `http://localhost:8080/api/v1/candidate/${candidateId}/exam-details`, + { + headers: { + Authorization: `Bearer ${accessToken}`, + }, + } + ); + + // Map API response to table data + const formattedData = response.data.map((item:any, index:any) => ({ + key: index + 1, + org_name: item.organizationName, + exam_name: item.examName, + grade: item.grade, + score: item.score, + exam_id: index + 1, + })); + + setGrades(formattedData); + } catch (error) { + console.error("Failed to fetch grades:", error); + notification.error({ + message: "Error", + description: "Failed to fetch grading data.", + }); + } finally { + setLoading(false); + } + }; + + useEffect(() => { + fetchGrades(); + }, []); const columns = [ { - title: 'Organization Name', - dataIndex: 'org_name', - key: 'org_name', + title: "Organization Name", + dataIndex: "org_name", + key: "org_name", }, { - title: 'Exam Name', - dataIndex: 'exam_name', - key: 'exam_name', + title: "Exam Name", + dataIndex: "exam_name", + key: "exam_name", }, { - title: 'Grade', - dataIndex: 'grade', - key: 'grade', + title: "Grade", + dataIndex: "grade", + key: "grade", }, { - title: 'Score', - dataIndex: 'score', - key: 'score', + title: "Score", + dataIndex: "score", + key: "score", }, - { - title: 'Date', - dataIndex: 'date', - key: 'date', - }, - { - title: 'Action', - key: 'action', - render: () => ( - - - - ), - }, - ] - + ]; + return (
- Grading - + Exam Grades +
); -}; \ No newline at end of file +};