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 | 1x 16x 16x 16x 16x 16x 16x 1x 1x 1x 1x 1x 16x 2x 2x 2x 2x 2x 2x 2x 16x 2x 2x 2x 2x 2x 2x 16x 2x 1x 1x 22x 22x 22x 22x 28x 22x 22x 22x 22x 22x 22x 6x 6x 6x 6x 6x 6x 6x 22x 6x 6x 22x 3x 22x 2x 22x 22x 8x | /**
* EI-1210 — Late Submission Teacher Approval: review queue.
*
* Reachable from AssignmentSettings ("Late Submissions" button) via the route
* /teacher/classes/:classCode/late-submissions/:assignmentTitle
* State: { assignmentUUID }
*
* Fetches the list of student late submissions awaiting teacher review and
* allows the teacher to approve (with an optional late penalty 0–100 %) or
* reject (with an optional reason) each entry. On success it removes the
* row from the pending list so the view self-refreshes without a full reload.
*/
import React, { useCallback, useEffect, useState } from "react";
import {
Alert,
AppBar,
Box,
Button,
Card,
CardContent,
CircularProgress,
Container,
Divider,
InputAdornment,
Stack,
TextField,
Toolbar,
Typography,
} from "@mui/material";
import CheckCircleIcon from "@mui/icons-material/CheckCircle";
import CancelIcon from "@mui/icons-material/Cancel";
import PendingActionsIcon from "@mui/icons-material/PendingActions";
import PersonIcon from "@mui/icons-material/Person";
import CalendarTodayIcon from "@mui/icons-material/CalendarToday";
import GradeIcon from "@mui/icons-material/Grade";
import { useLocation, useNavigate, useParams } from "react-router-dom";
import { useDispatch, useSelector } from "react-redux";
import { enqueueSnackbar } from "notistack";
import axios from "axios";
import BasicBreadcrumbs from "@/utils/components/breadcrumbs/basic-breadcrumbs/BasicBreadcrumbs";
import SimpleLoading from "@/utils/components/SimpleLoading";
import { _fetchSpecificClassByCode } from "@/store/slices/teacher/TeacherSpecificClass";
import { API_ENDPOINTS } from "@/api/endpoints";
import { utcToLocalTime } from "@/utils/helpers/utcToLocalTime";
// ---------------------------------------------------------------------------
// Sub-component: one pending-submission row
// ---------------------------------------------------------------------------
const PendingSubmissionRow = ({ submission, onApproved, onRejected }) => {
const [latePenalty, setLatePenalty] = useState(0);
const [rejectReason, setRejectReason] = useState("");
const [isApprovingLoading, setIsApprovingLoading] = useState(false);
const [isRejectingLoading, setIsRejectingLoading] = useState(false);
const [showRejectInput, setShowRejectInput] = useState(false);
const handlePenaltyChange = (e) => {
const raw = e.target.value;
Iif (raw === "") {
setLatePenalty("");
return;
}
const num = Number(raw);
Eif (!isNaN(num) && num >= 0 && num <= 100) {
setLatePenalty(num);
}
};
const handleApprove = async () => {
const penalty = latePenalty === "" ? 0 : Number(latePenalty);
setIsApprovingLoading(true);
try {
const response = await axios.post(
API_ENDPOINTS.teacher.assignment.approveLateSubmission(submission.submission_id),
{ late_penalty: penalty }
);
enqueueSnackbar(`Approved: ${submission.student_name} — penalty ${penalty}%`, { variant: "success" });
onApproved(submission.submission_id, response.data);
} catch (error) {
enqueueSnackbar(error.response?.data?.detail || "Failed to approve submission", { variant: "error" });
} finally {
setIsApprovingLoading(false);
}
};
const handleReject = async () => {
setIsRejectingLoading(true);
try {
const response = await axios.post(
API_ENDPOINTS.teacher.assignment.rejectLateSubmission(submission.submission_id),
{ reason: rejectReason.trim() || null }
);
enqueueSnackbar(`Rejected: ${submission.student_name}`, { variant: "info" });
onRejected(submission.submission_id, response.data);
} catch (error) {
enqueueSnackbar(error.response?.data?.detail || "Failed to reject submission", { variant: "error" });
} finally {
setIsRejectingLoading(false);
}
};
return (
<Card
elevation={2}
sx={{ mb: 2 }}
data-testid="pending-submission-row"
data-submission-id={submission.submission_id}
>
<CardContent>
<Box sx={{ display: "flex", flexWrap: "wrap", gap: 3, alignItems: "flex-start" }}>
{/* Student info */}
<Box sx={{ flex: "1 1 220px", minWidth: 200 }}>
<Box sx={{ display: "flex", alignItems: "center", gap: 1, mb: 0.5 }}>
<PersonIcon fontSize="small" color="primary" />
<Typography variant="subtitle1" fontWeight={600}>
{submission.student_name}
</Typography>
</Box>
<Box sx={{ display: "flex", alignItems: "center", gap: 1, mb: 0.5 }}>
<CalendarTodayIcon fontSize="small" color="action" />
<Typography variant="body2" color="text.secondary">
Submitted: {utcToLocalTime(submission.date_submitted)}
</Typography>
</Box>
<Box sx={{ display: "flex", alignItems: "center", gap: 1 }}>
<GradeIcon fontSize="small" color="action" />
<Typography variant="body2" color="text.secondary">
Pre-penalty grade:{" "}
<strong>
{submission.pre_penalty_grade != null
? `${Number(submission.pre_penalty_grade).toFixed(2)}%`
: "—"}
</strong>
{submission.total_score != null && (
<span style={{ marginLeft: 8 }}>({submission.total_score} pts)</span>
)}
</Typography>
</Box>
</Box>
{/* Approve controls */}
<Box sx={{ flex: "0 0 auto" }}>
<Typography variant="caption" color="text.secondary" sx={{ display: "block", mb: 0.5 }}>
Late penalty (%)
</Typography>
<Stack direction="row" spacing={1} alignItems="center">
<TextField
data-testid={`late-penalty-input-${submission.submission_id}`}
size="small"
type="number"
value={latePenalty}
onChange={handlePenaltyChange}
inputProps={{ min: 0, max: 100, step: 1 }}
InputProps={{
endAdornment: <InputAdornment position="end">%</InputAdornment>,
}}
sx={{ width: 110 }}
/>
<Button
data-testid={`approve-btn-${submission.submission_id}`}
variant="contained"
color="success"
size="small"
startIcon={
isApprovingLoading ? <CircularProgress size={14} color="inherit" /> : <CheckCircleIcon />
}
onClick={handleApprove}
disabled={isApprovingLoading || isRejectingLoading}
>
Approve
</Button>
</Stack>
</Box>
{/* Reject controls */}
<Box sx={{ flex: "0 0 auto" }}>
{!showRejectInput ? (
<Button
data-testid={`reject-btn-${submission.submission_id}`}
variant="outlined"
color="error"
size="small"
startIcon={<CancelIcon />}
onClick={() => setShowRejectInput(true)}
disabled={isApprovingLoading || isRejectingLoading}
sx={{ mt: 3 }}
>
Reject
</Button>
) : (
<Stack spacing={1} sx={{ minWidth: 220 }}>
<TextField
data-testid={`reject-reason-input-${submission.submission_id}`}
size="small"
label="Reason (optional)"
multiline
minRows={2}
value={rejectReason}
onChange={(e) => setRejectReason(e.target.value)}
fullWidth
/>
<Stack direction="row" spacing={1}>
<Button
data-testid={`reject-confirm-btn-${submission.submission_id}`}
variant="contained"
color="error"
size="small"
startIcon={
isRejectingLoading ? (
<CircularProgress size={14} color="inherit" />
) : (
<CancelIcon />
)
}
onClick={handleReject}
disabled={isApprovingLoading || isRejectingLoading}
>
Confirm Reject
</Button>
<Button
size="small"
variant="text"
onClick={() => setShowRejectInput(false)}
disabled={isRejectingLoading}
>
Cancel
</Button>
</Stack>
</Stack>
)}
</Box>
</Box>
</CardContent>
</Card>
);
};
// ---------------------------------------------------------------------------
// Main component
// ---------------------------------------------------------------------------
const LateSubmissionsQueue = () => {
const { classCode, assignmentTitle } = useParams();
const location = useLocation();
const navigate = useNavigate();
const dispatch = useDispatch();
const { specificClassData } = useSelector((state) => state.TeacherSpecificClass);
const assignmentUUID = location.state?.assignmentUUID;
const [pendingList, setPendingList] = useState([]);
const [isFetching, setIsFetching] = useState(false);
const [fetchError, setFetchError] = useState(null);
const breadcrumb = [
{ name: "Classes", isLink: true, path: "/teacher/classes" },
{ name: specificClassData?.title, isLink: true, path: `/teacher/classes/${classCode}` },
{
name: assignmentTitle,
isLink: true,
path: `/teacher/classes/${classCode}/assignment/${assignmentTitle}`,
state: { assignmentUUID },
},
{ name: "Late Submissions", isLink: false },
];
const fetchPending = useCallback(async () => {
Iif (!assignmentUUID) return;
setIsFetching(true);
setFetchError(null);
try {
const response = await axios.get(API_ENDPOINTS.teacher.assignment.latePendingFetch(assignmentUUID));
setPendingList(response.data?.pending ?? []);
} catch (error) {
setFetchError(error.response?.data?.detail || "Failed to load late submissions");
} finally {
setIsFetching(false);
}
}, [assignmentUUID]);
useEffect(() => {
dispatch(_fetchSpecificClassByCode(classCode));
fetchPending();
}, []);
const handleApproved = (submissionId) => {
setPendingList((prev) => prev.filter((s) => s.submission_id !== submissionId));
};
const handleRejected = (submissionId) => {
setPendingList((prev) => prev.filter((s) => s.submission_id !== submissionId));
};
Iif (!assignmentUUID) {
return (
<Box sx={{ p: 4, textAlign: "center" }}>
<Typography variant="h6" color="text.secondary">
Please open this page from the assignment detail view.
</Typography>
<Button sx={{ mt: 2 }} variant="outlined" onClick={() => navigate(-1)}>
Go Back
</Button>
</Box>
);
}
return (
<React.Fragment>
<SimpleLoading showLoading={isFetching} />
<AppBar position="relative" color="primary">
<Toolbar>
<PendingActionsIcon sx={{ mr: 2 }} />
<Typography variant="h6">Late Submissions — Pending Approval</Typography>
</Toolbar>
</AppBar>
<BasicBreadcrumbs links={breadcrumb} />
<Container maxWidth="lg" sx={{ py: 3, mb: 8 }}>
{fetchError && (
<Alert severity="error" sx={{ mb: 3 }}>
{fetchError}
</Alert>
)}
{!isFetching && !fetchError && (
<>
<Box sx={{ display: "flex", alignItems: "center", gap: 1, mb: 3 }}>
<PendingActionsIcon color="warning" />
<Typography variant="h6" fontWeight={600}>
{pendingList.length === 0
? "No pending late submissions"
: `${pendingList.length} submission${pendingList.length !== 1 ? "s" : ""} awaiting review`}
</Typography>
</Box>
<Divider sx={{ mb: 3 }} />
{pendingList.length === 0 ? (
<Alert
severity="success"
data-testid="no-pending-submissions-message"
sx={{ maxWidth: 600 }}
>
All late submissions have been reviewed. No pending submissions remain.
</Alert>
) : (
<Box data-testid="pending-submissions-list">
{pendingList.map((submission) => (
<PendingSubmissionRow
key={submission.submission_id}
submission={submission}
onApproved={handleApproved}
onRejected={handleRejected}
/>
))}
</Box>
)}
</>
)}
</Container>
</React.Fragment>
);
};
export default LateSubmissionsQueue;
|