Skip to content

Commit

Permalink
fix: incorrect field validation on the grading page
Browse files Browse the repository at this point in the history
  • Loading branch information
Dima Alipov authored and Dima Alipov committed Mar 25, 2024
1 parent 1dde30a commit adbc8ec
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -42,14 +42,15 @@ const AssignmentItem = ({
{descriptions}
</Form.Control.Feedback>
{errorEffort && (
<Form.Control.Feedback className="feedback-error" type="invalid">
{errorMsg}
</Form.Control.Feedback>
)}
{gradeField?.dropCount !== 0 && gradeField?.dropCount > gradeField?.minCount && (
<Form.Control.Feedback className="feedback-error" type="invalid">
{secondErrorMsg}
</Form.Control.Feedback>
gradeField?.dropCount ? (
<Form.Control.Feedback className="feedback-error" type="invalid">
{gradeField?.dropCount !== 0 && gradeField?.dropCount >= gradeField?.minCount ? secondErrorMsg : errorMsg}
</Form.Control.Feedback>
) : (
<Form.Control.Feedback className="feedback-error" type="invalid">
{errorMsg}
</Form.Control.Feedback>
)
)}
</Form.Group>
</li>
Expand Down
12 changes: 9 additions & 3 deletions src/grading-settings/assignment-section/utils/validation.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,10 +51,11 @@ export const validationAssignmentFields = (
assignmentDropCount,
) => {
const courseGradingTypes = courseGraders?.map(grade => grade.type);
const minCountValue = courseGraders?.find(grade => grade.id === assignmentId).minCount;

switch (assignmentName) {
case assignmentType:
if (assignmentValue === '') {
if (assignmentValue.trim() === '') {
updateAssignmentErrorList(assignmentName, assignmentId, setErrorList, setShowSavePrompt);
return;
}
Expand All @@ -77,7 +78,7 @@ export const validationAssignmentFields = (
);
break;
case weightOfTotalGrade:
if (assignmentValue < 0 || assignmentValue > 100 || assignmentValue === '-0') {
if (assignmentValue === '' || assignmentValue < 0 || assignmentValue > 100 || assignmentValue === '-0') {
updateAssignmentErrorList(
assignmentName,
assignmentId,
Expand Down Expand Up @@ -113,7 +114,12 @@ export const validationAssignmentFields = (
);
break;
case assignmentDropCount:
if (assignmentValue < 0 || assignmentValue === '' || assignmentValue === '-0') {
if (
assignmentValue >= minCountValue
|| assignmentValue < 0
|| assignmentValue === ''
|| assignmentValue === '-0'
) {
updateAssignmentErrorList(
assignmentName,
assignmentId,
Expand Down

0 comments on commit adbc8ec

Please sign in to comment.