Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 | 1x 7x 7x 7x 7x 7x 14x 14x 14x 7x 7x 7x 7x 7x 7x 7x 7x 7x 7x 7x 7x 12x 12x 12x 7x 7x 7x | import Box from "@mui/material/Box";
import Typography from "@mui/material/Typography";
import {
Alert,
AppBar,
Button,
Card,
CardContent,
Chip,
Container,
Divider,
Grid,
LinearProgress,
Paper,
Stack,
Toolbar,
} from "@mui/material";
import HourglassTopIcon from "@mui/icons-material/HourglassTop";
import BlockIcon from "@mui/icons-material/Block";
import React, { useEffect } from "react";
import { useLocation, useNavigate, useParams } from "react-router-dom";
import { useSelector, useDispatch } from "react-redux";
import { _studentFetchSpecificAssignmentById } from "@/store/slices/student/StudentSpecificAssignment";
import BasicBreadcrumbs from "@/utils/components/breadcrumbs/basic-breadcrumbs/BasicBreadcrumbs";
import { _fetchSpecificClassByCode } from "@/store/slices/student/StudentSpecificClass";
import SimpleLoading from "@/utils/components/SimpleLoading";
import { utcToLocalTime } from "@/utils/helpers/utcToLocalTime";
import SubmissionAnswersList from "@/utils/components/submission-review/SubmissionAnswersList";
import { _studentFetchSubmission } from "@/store/slices/student/StudentSubmission";
import AssignmentIcon from "@mui/icons-material/Assignment";
import ArticleIcon from "@mui/icons-material/Article";
import CalendarTodayIcon from "@mui/icons-material/CalendarToday";
import CheckCircleIcon from "@mui/icons-material/CheckCircle";
import GradeIcon from "@mui/icons-material/Grade";
import TimerIcon from "@mui/icons-material/Timer";
import ReplayIcon from "@mui/icons-material/Replay";
import TaskAltIcon from "@mui/icons-material/TaskAlt";
import CommentIcon from "@mui/icons-material/Comment";
import RubricTable from "@/app/student-page/components/assignments/RubricTable";
const ViewAssignment = () => {
const navigate = useNavigate();
const location = useLocation();
const dispatch = useDispatch();
const { classCode, assignmentTitle } = useParams();
// location.state is only populated when navigating here via an in-app Link/navigate
// call — a direct URL visit or hard refresh loses it, so this must stay optional.
const assignmentId = location.state?.assignmentId;
const { specificClassData } = useSelector((state) => state.StudentSpecificClass);
const { specificAssignmentData } = useSelector((state) => state.StudentSpecificAssignment);
const { submissionData, isLoading } = useSelector((state) => state.StudentSubmission);
const breadcrumbs = [
{
name: "Classes",
isLink: true,
path: "/student/classes",
},
{
name: specificClassData?.title,
isLink: true,
path: `/student/classes/${classCode}`,
},
{
name: assignmentTitle,
isLink: true,
path: `/student/classes/${classCode}/assignment/${assignmentTitle}`,
state: { assignmentId },
},
{
name: "My Submission",
isLink: false,
},
];
function lowercaseQuestionTypes(questions) {
return questions?.map((entry) => {
if (entry.questionType && typeof entry.questionType === "string") {
return {
...entry,
questionType: entry.questionType.toLowerCase(),
};
}
return entry;
});
}
// True only when the student actually submitted answers at least once.
// studentAnswers comes from last_student_answers stored at submit time.
const hasActualSubmission = submissionData?.isSubmitted && (submissionData?.studentAnswers?.length ?? 0) > 0;
useEffect(() => {
dispatch(_fetchSpecificClassByCode(classCode));
Eif (assignmentId) {
dispatch(_studentFetchSpecificAssignmentById(assignmentId));
dispatch(_studentFetchSubmission(assignmentId));
}
}, []);
const getGradePercentage = () => {
const grade = Number(submissionData?.grade);
return isNaN(grade) ? 0 : grade;
};
const getRemarksColor = (remarks) => {
Iif (!remarks) return "default";
const lower = remarks.toLowerCase();
Eif (lower === "passed" || lower === "pass" || lower === "excellent") return "success";
if (lower === "failed" || lower === "fail") return "error";
return "warning";
};
const gradePercentage = getGradePercentage();
const totalPossiblePoints = Number(submissionData?.totalPoints) || 0;
return (
<React.Fragment>
<SimpleLoading showLoading={isLoading} />
{!isLoading && (
<Box sx={{ bgcolor: "background.default", minHeight: "100vh" }}>
<AppBar position="relative" color="primary">
<Toolbar>
<Typography variant="h6">Submission Details</Typography>
</Toolbar>
</AppBar>
<BasicBreadcrumbs links={breadcrumbs} />
<Container maxWidth="lg" sx={{ py: 3 }}>
{!assignmentId && (
<Alert severity="warning" sx={{ mb: 3 }}>
We couldn't determine which assignment to load. Please navigate here from the
assignments list.
</Alert>
)}
{specificAssignmentData && (
<>
<Paper
elevation={0}
sx={{ p: 3, mb: 3, borderRadius: 2, border: "1px solid", borderColor: "divider" }}
>
<Box sx={{ display: "flex", alignItems: "flex-start", gap: 2, mb: 2 }}>
<AssignmentIcon color="primary" sx={{ fontSize: 32, mt: 0.5 }} />
<Box sx={{ flex: 1 }}>
<Typography variant="h5" fontWeight={600} gutterBottom>
{specificAssignmentData.details.title}
</Typography>
<Typography variant="body1" color="text.secondary">
{specificAssignmentData.details.description}
</Typography>
</Box>
</Box>
<Divider sx={{ my: 2 }} />
<Box sx={{ display: "flex", gap: 3, flexWrap: "wrap" }}>
<Box sx={{ display: "flex", alignItems: "center", gap: 1 }}>
<CalendarTodayIcon fontSize="small" color="action" />
<Typography variant="body2" color="text.secondary">
Opened:{" "}
<strong>
{utcToLocalTime(specificAssignmentData.details.date_open)}
</strong>
</Typography>
</Box>
<Box sx={{ display: "flex", alignItems: "center", gap: 1 }}>
<CalendarTodayIcon fontSize="small" color="action" />
<Typography variant="body2" color="text.secondary">
Closed:{" "}
<strong>
{utcToLocalTime(specificAssignmentData.details.date_close)}
</strong>
</Typography>
</Box>
</Box>
</Paper>
{/* EI-3182: Instructions panel — only rendered when the assignment carries instructions */}
{specificAssignmentData.details.instructions && (
<Paper
elevation={0}
sx={{
p: 3,
mb: 3,
borderRadius: 2,
border: "1px solid",
borderColor: "divider",
}}
data-testid="submission-instructions-panel"
>
<Box sx={{ display: "flex", alignItems: "center", mb: 1.5 }}>
<ArticleIcon color="primary" sx={{ fontSize: 24, mr: 1 }} />
<Typography variant="h6" fontWeight={600}>
Instructions
</Typography>
</Box>
<Divider sx={{ mb: 2 }} />
<Typography
variant="body1"
data-testid="submission-instructions-text"
sx={{ whiteSpace: "pre-wrap" }}
>
{specificAssignmentData.details.instructions}
</Typography>
</Paper>
)}
{/* EI-3182: Rubric table — self-guards when rubric absent */}
<RubricTable rubric={specificAssignmentData.details.rubric} />
</>
)}
{submissionData && (
<React.Fragment>
<Typography
variant="h6"
fontWeight={600}
sx={{ mb: 2, display: "flex", alignItems: "center", gap: 1 }}
>
<GradeIcon color="primary" />
Submission Summary
</Typography>
{/* EI-1210: late-submission review-status banners */}
{submissionData.reviewStatus === "pending" && (
<Alert
severity="warning"
icon={<HourglassTopIcon />}
data-testid="late-submission-pending-banner"
sx={{ mb: 3 }}
>
<Typography fontWeight={600}>Awaiting Teacher Approval</Typography>
<Typography variant="body2" sx={{ mt: 0.5 }}>
Your late submission has been received and is pending review by your
teacher. Your grade will be available once approved.
</Typography>
</Alert>
)}
{submissionData.reviewStatus === "rejected" && (
<Alert
severity="error"
icon={<BlockIcon />}
data-testid="late-submission-rejected-banner"
sx={{ mb: 3 }}
>
<Typography fontWeight={600}>Late Submission Rejected</Typography>
<Typography variant="body2" sx={{ mt: 0.5 }}>
Your teacher has not accepted this late submission. Please contact your
teacher for more information.
</Typography>
</Alert>
)}
{/* Grade and Remarks Banner — only when the student actually submitted and not pending */}
{hasActualSubmission &&
submissionData.reviewStatus !== "pending" &&
(submissionData.grade || submissionData.remarks) && (
<Paper
elevation={0}
sx={{
p: 2.5,
mb: 3,
borderRadius: 2,
}}
>
<Box
sx={{
display: "flex",
alignItems: "center",
justifyContent: "space-between",
flexWrap: "wrap",
gap: 2,
}}
>
<Box sx={{ display: "flex", alignItems: "center", gap: 2 }}>
<GradeIcon
sx={{
fontSize: 40,
color:
getRemarksColor(submissionData.remarks) === "success"
? "success.dark"
: getRemarksColor(submissionData.remarks) ===
"error"
? "error.dark"
: "warning.dark",
}}
/>
<Box>
<Typography variant="body2" color="text.secondary">
Final Grade
</Typography>
<Typography
variant="h3"
fontWeight={700}
color={
getRemarksColor(submissionData.remarks) === "success"
? "success.dark"
: getRemarksColor(submissionData.remarks) ===
"error"
? "error.dark"
: "warning.dark"
}
>
{Number(submissionData.grade).toFixed(2)}%
</Typography>
</Box>
</Box>
{submissionData.remarks && (
<Chip
icon={<CommentIcon />}
label={
submissionData.remarks.charAt(0).toUpperCase() +
submissionData.remarks.slice(1)
}
color={getRemarksColor(submissionData.remarks)}
size="medium"
sx={{ fontWeight: 600, fontSize: "0.9rem", py: 2.5 }}
/>
)}
</Box>
{submissionData.grade && (
<Box sx={{ mt: 2 }}>
<LinearProgress
variant="determinate"
value={gradePercentage}
color={getRemarksColor(submissionData.remarks)}
sx={{ height: 8, borderRadius: 4 }}
/>
</Box>
)}
</Paper>
)}
<Grid container spacing={2} sx={{ mb: 4 }}>
{/* Score Card */}
{submissionData.totalScore !== undefined && (
<Grid size={{ xs: 6, sm: 4, md: 2 }}>
<Card variant="outlined" sx={{ height: "100%", borderRadius: 2 }}>
<CardContent sx={{ textAlign: "center" }}>
<TaskAltIcon color="primary" sx={{ fontSize: 28, mb: 1 }} />
<Typography
variant="overline"
color="text.secondary"
sx={{ display: "block" }}
>
Score
</Typography>
<Typography variant="h5" fontWeight={700}>
{submissionData.totalScore}
{totalPossiblePoints > 0 && (
<Typography
component="span"
variant="body2"
color="text.secondary"
>
{" "}
/ {totalPossiblePoints}
</Typography>
)}
</Typography>
</CardContent>
</Card>
</Grid>
)}
{/* Correct Answers Card */}
{submissionData.totalCorrectAnswers !== undefined && (
<Grid size={{ xs: 6, sm: 4, md: 2 }}>
<Card variant="outlined" sx={{ height: "100%", borderRadius: 2 }}>
<CardContent sx={{ textAlign: "center" }}>
<CheckCircleIcon color="success" sx={{ fontSize: 28, mb: 1 }} />
<Typography
variant="overline"
color="text.secondary"
sx={{ display: "block" }}
>
Correct
</Typography>
<Typography variant="h5" fontWeight={700}>
{submissionData.totalCorrectAnswers}
{submissionData.totalQuestions !== undefined && (
<Typography
component="span"
variant="body2"
color="text.secondary"
>
{" "}
/ {submissionData.totalQuestions}
</Typography>
)}
</Typography>
</CardContent>
</Card>
</Grid>
)}
{/* Answers Submitted Card */}
<Grid size={{ xs: 6, sm: 4, md: 2 }}>
<Card variant="outlined" sx={{ height: "100%", borderRadius: 2 }}>
<CardContent sx={{ textAlign: "center" }}>
<AssignmentIcon color="secondary" sx={{ fontSize: 28, mb: 1 }} />
<Typography
variant="overline"
color="text.secondary"
sx={{ display: "block" }}
>
Submitted
</Typography>
<Typography variant="h5" fontWeight={700}>
{submissionData.totalAnswersSubmitted}
{submissionData.totalQuestions !== undefined && (
<Typography
component="span"
variant="body2"
color="text.secondary"
>
{" "}
/ {submissionData.totalQuestions}
</Typography>
)}
</Typography>
</CardContent>
</Card>
</Grid>
{/* Attempts Used Card */}
<Grid size={{ xs: 6, sm: 4, md: 2 }}>
<Card variant="outlined" sx={{ height: "100%", borderRadius: 2 }}>
<CardContent sx={{ textAlign: "center" }}>
<ReplayIcon color="warning" sx={{ fontSize: 28, mb: 1 }} />
<Typography
variant="overline"
color="text.secondary"
sx={{ display: "block" }}
>
Attempts
</Typography>
<Typography variant="h5" fontWeight={700}>
{submissionData.totalAttemptsUsed}
{submissionData.totalAttemptsAllowed !== undefined && (
<Typography
component="span"
variant="body2"
color="text.secondary"
>
{" "}
/ {submissionData.totalAttemptsAllowed}
</Typography>
)}
</Typography>
</CardContent>
</Card>
</Grid>
{/* Remaining Time Card */}
{submissionData.remainingTime && (
<Grid size={{ xs: 6, sm: 4, md: 2 }}>
<Card variant="outlined" sx={{ height: "100%", borderRadius: 2 }}>
<CardContent sx={{ textAlign: "center" }}>
<TimerIcon color="action" sx={{ fontSize: 28, mb: 1 }} />
<Typography
variant="overline"
color="text.secondary"
sx={{ display: "block" }}
>
Time Left
</Typography>
<Typography variant="h6" fontWeight={700}>
{submissionData.remainingTime}
</Typography>
</CardContent>
</Card>
</Grid>
)}
</Grid>
{hasActualSubmission ? (
<>
<Box sx={{ mb: 3 }}>
<Typography
variant="h6"
fontWeight={600}
sx={{ mb: 2, display: "flex", alignItems: "center", gap: 1 }}
>
<AssignmentIcon color="primary" />
Your Answers
</Typography>
</Box>
<Box sx={{ mb: 6 }}>
<SubmissionAnswersList
questions={lowercaseQuestionTypes(submissionData?.details)}
answers={submissionData?.studentAnswers}
comments={submissionData?.teacherComments}
settings={submissionData?.settings}
readOnly
/>
</Box>
</>
) : (
<Alert severity="info" sx={{ mb: 6 }}>
No answers were submitted for this assignment. You used all your available
attempts without completing a submission.
</Alert>
)}
</React.Fragment>
)}
</Container>
</Box>
)}
</React.Fragment>
);
};
export default ViewAssignment;
|