diff --git a/src/course-manipulation/TemplateEditor.jsx b/src/course-manipulation/TemplateEditor.jsx index 34fe470..acaca3d 100644 --- a/src/course-manipulation/TemplateEditor.jsx +++ b/src/course-manipulation/TemplateEditor.jsx @@ -74,6 +74,7 @@ const TemplateEditor = (props) => { const [errorText, setErrorText] = React.useState(""); const [loading, setLoading] = React.useState(false); const [closeDialog, setCloseDialog] = React.useState(false); + const [confirmDialog, setConfirmDialog] = React.useState(false); const [isKeyPress, setIsKeyPress] = React.useState(false); const openR = React.useRef(); openR.current = open; @@ -250,6 +251,7 @@ const TemplateEditor = (props) => { }); setLoading(false); + setConfirmDialog(false); }; /** @@ -288,6 +290,7 @@ const TemplateEditor = (props) => { }); setLoading(false); + setConfirmDialog(false); }; /** Closes the creator dialog. */ @@ -296,6 +299,14 @@ const TemplateEditor = (props) => { onClose(false, keyPressed); }, [isKeyPress, onClose]); + /** Checks if the assessment weights sum up to more than 100. */ + const needConfirmation = () => { + let sum = assessments.map((assessment) => assessment.weight).reduce((a, b) => parseFloat(a) + parseFloat(b), 0); + + if (sum < 100) setConfirmDialog(true); + else editCode !== "" ? updateCourse() : createCourse(); + } + /** * Closes the editor unless changes have been made in the * current editor session, in which case a confirmation dialog @@ -367,7 +378,7 @@ const TemplateEditor = (props) => { { editCode !== "" ? "Editing " + editCode : "Create New Course for Trimester " + activeTri.tri } - @@ -442,6 +453,10 @@ const TemplateEditor = (props) => { {setCloseDialog(false)}} buttonText={"Stop"} message={"Stop template creation?"} subMessage={"Any inputted data will be lost."} confirmAction={stopCreating} /> + + setConfirmDialog(false)} buttonText={"Proceed"} message={"Assessment weights"} + subMessage={"The assessment weights don't add up to 100%. Are you sure you want to proceed?"} confirmAction={editCode !== "" ? updateCourse : createCourse} + /> setSnackbar("none")} anchorOrigin={{ vertical:"bottom", horizontal: isMobile ? "center" : "left" }} sx={{zIndex: 1, mb: !isMobile && editCode !== "" ? 10 : 0}} diff --git a/src/course-viewer/CourseViewerHeader.jsx b/src/course-viewer/CourseViewerHeader.jsx index e42b687..ce859fa 100644 --- a/src/course-viewer/CourseViewerHeader.jsx +++ b/src/course-viewer/CourseViewerHeader.jsx @@ -28,12 +28,14 @@ import { Typography, } from "@mui/material"; +import ConfirmDialog from "../ConfirmDialog"; import dayjs from "dayjs"; import { isMobile } from "react-device-detect"; import DeleteIcon from "@mui/icons-material/Delete"; import LaunchIcon from "@mui/icons-material/Launch"; import CourseViewerMobileActionButtons from "./CourseViewerMobileActionButtons"; +import WarningRoundedIcon from '@mui/icons-material/WarningRounded'; /** * The main header for the course viewer, changes based on @@ -119,13 +121,34 @@ const CurrentlyAchievedDisplay = (props) => { courseLetter, } = props; + let sum = courseData.assessments.map((assessment) => assessment.weight).reduce((a, b) => a + b, 0); + + const [incompleteDialogOpen, setIncompleteDialogOpen] = React.useState(false); + return ( Currently Achieved: - - + + + + {sum < 100 && ( + isMobile ? ( + <> + } color="secondary" sx={{ py: 3, fontSize:30, backgroundColor:"error.main", borderRadius: 1 }} onClick={() => setIncompleteDialogOpen(true)} /> + + setIncompleteDialogOpen(false)} buttonText={"Ok"} message={"Assessment weights"} + subMessage={"The assessment weights don't add up to 100%. This likely means that the course may have incomplete assessments."} + /> + + ) : ( + The assessment weights don't add up to 100%. This likely means that the course may have incomplete assessments.} arrow> + } color="secondary" sx={{ py: 3, fontSize:30, backgroundColor:"error.main", borderRadius: 1 }} /> + + ) + )} +