fix: bug in assignment vertalingen

This commit is contained in:
Joyelle Ndagijimana 2025-05-17 19:07:52 +02:00
parent f67e3f5a1a
commit 0abe9b1bce
4 changed files with 37 additions and 119 deletions

View file

@ -1,6 +1,5 @@
<script setup lang="ts">
import { ref, watch } from "vue";
import { deadlineRules } from "@/utils/assignment-rules.ts";
const emit = defineEmits<(e: "update:deadline", value: Date | null) => void>();
const props = defineProps<{ deadline: Date | null }>();
@ -19,6 +18,24 @@
emit("update:deadline", null);
}
});
const deadlineRules = [
(value: string): string | boolean => {
const selectedDateTime = new Date(value);
const now = new Date();
if (isNaN(selectedDateTime.getTime())) {
return t("deadline-invalid");
}
if (selectedDateTime <= now) {
return t("deadline-past");
}
return true;
},
];
</script>
<template>

View file

@ -1,20 +1,9 @@
import {useI18n} from "vue-i18n";
const { t } = useI18n();
/**
* Validation rule for the assignment title.
*
* Ensures that the title is not empty.
*/
export const assignmentTitleRules = [
(value: string): string | boolean => {
if (value?.length >= 1) {
return true;
} // Title must not be empty
return t("title-required");
},
];
/**
@ -22,34 +11,10 @@ export const assignmentTitleRules = [
*
* Ensures that at least one class is selected.
*/
export const classRules = [
(value: string): string | boolean => {
if (value) {
return true;
}
return t("class-required");
},
];
/**
* Validation rule for the deadline field.
*
* Ensures that a valid deadline is selected and is in the future.
*/
export const deadlineRules = [
(value: string): string | boolean => {
const selectedDateTime = new Date(value);
const now = new Date();
if (isNaN(selectedDateTime.getTime())) {
return t("deadline-invalid");
}
if (selectedDateTime <= now) {
return t("deadline-past");
}
return true;
},
];

View file

@ -1,7 +1,6 @@
<script setup lang="ts">
import { useI18n } from "vue-i18n";
import { computed, onMounted, ref, watch } from "vue";
import { assignmentTitleRules, classRules } from "@/utils/assignment-rules.ts";
import auth from "@/services/auth/auth-service.ts";
import { useTeacherClassesQuery } from "@/queries/teachers.ts";
import { useRouter, useRoute } from "vue-router";
@ -96,6 +95,25 @@ const learningPathRules = [
}
];
const assignmentTitleRules = [
(value: string): string | boolean => {
if (value?.length >= 1) {
return true;
} // Title must not be empty
return t("title-required");
},
];
const classRules = [
(value: string): string | boolean => {
if (value) {
return true;
}
return t("class-required");
},
];
</script>
<template>