Skip to content

Commit

Permalink
extra validatie
Browse files Browse the repository at this point in the history
  • Loading branch information
DRIESASTER committed May 23, 2024
1 parent a51235c commit 7c96de6
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 0 deletions.
3 changes: 3 additions & 0 deletions frontend/src/i18n/locales/en.ts
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,9 @@ export default {
testfiles: "Testfiles",
requirements_disclaimer: "For info on the usage of requirements please visit our",
to_project: "To Project",
titlereq: "Project title is required.",
date_check: "Deadline or publish date cannot be in the past. Please correct the dates.",
publish_check: "Publish date must be before or on the deadline. Please correct the dates.",
},
navigation: {
home: "Home",
Expand Down
3 changes: 3 additions & 0 deletions frontend/src/i18n/locales/nl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,9 @@ export default {
testfiles: "Testbestanden",
requirements_disclaimer: "Voor info over het gebruik van bestandsvereisten, bezoek onze ",
to_project: "Naar project",
titlereq: "Project titel is verplicht.",
date_check: "Deadline of publiceerdatum kan niet in het verleden liggen.",
publish_check: "Publiceerdatum moet voor de deadline liggen.",
},
navigation: {
home: "Hoofdscherm",
Expand Down
23 changes: 23 additions & 0 deletions frontend/src/views/CreateProjectView.vue
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
:label="$t('project.assignment')"
required
:placeholder="$t('submit.create_title_tip')"
:rules="titleRules"
/>
<v-select
v-if="!isEditMode"
Expand Down Expand Up @@ -297,6 +298,17 @@ function setErrorAlert(message) {
}
async function submitForm() {
if (
isDateInPast(deadline.value) ||
(enrollDeadline.value && isDateInPast(enrollDeadline.value))
) {
setErrorAlert(t("project.date_check"));
return;
}
if (!isPublishDateValid(publishDate.value, deadline.value)) {
setErrorAlert(t("project.publish_check"));
return;
}
const projectData = formatProjectData();
try {
if (isEditMode.value) {
Expand Down Expand Up @@ -431,6 +443,17 @@ function divideStudentsIntoGroups(students: User[], capacity: number) {
return groups;
}
function isDateInPast(date) {
const now = new Date();
return new Date(date) < now;
}
function isPublishDateValid(publishDate, deadline) {
return new Date(publishDate) <= new Date(deadline);
}
const titleRules = computed(() => [(v) => !!v.trim() || t("project.titlereq")]);
</script>

<style>
Expand Down

0 comments on commit 7c96de6

Please sign in to comment.