feat: nieuwe component voor de deadline

This commit is contained in:
Joyelle Ndagijimana 2025-03-29 20:27:26 +01:00
parent db7c5409fc
commit 3e00f0eb1f
4 changed files with 84 additions and 11 deletions

View file

@ -5,20 +5,22 @@
* @param selectedLearningPath - The selected learning path, containing hruid and title.
* @param selectedClasses - The selected classes, an array of class objects.
* @param groups - An array of groups, each containing student IDs.
*
* @param deadline - The deadline of the assignment in ISO format.
* Sends a POST request to the backend with the form data.
*/
export const submitForm = async (
assignmentTitle: string,
selectedLearningPath: any,
selectedClasses: any[],
groups: string[][]
groups: string[][],
deadline: string
) => {
const formData = {
title: assignmentTitle,
hruid: selectedLearningPath?.hruid,
classes: selectedClasses.map(cl => cl.value),
groups: groups
groups: groups,
deadline: deadline
};
try {
@ -71,3 +73,21 @@ export const classesRules = [
return 'You must select at least one class.';
},
];
/**
* Validation rule for the deadline field.
*
* Ensures that a valid deadline is selected and is in the future.
*/
export const deadlineRules = [
(value: string) => {
if (!value) return 'You must set a deadline.';
const selectedDate = new Date(value);
const now = new Date();
if (selectedDate <= now) return 'The deadline must be in the future.';
return true;
},
];