refactor(task-modal): enhance validation logic for concept tasks to support incomplete data

This commit is contained in:
Matej Glasnák committed 2025-12-07 17:21:28 +01:00
1 parent b70c0ceb8b
commit 415392eb9f
1 file changed
+19 -5
+19 -5
View File
@@ -779,7 +779,8 @@ export default {
this.$router.replace({ name: this.$route.name }); this.$router.replace({ name: this.$route.name });
}, },
async validateAllFields() { async validateAllFields(concept = false) {
if (concept === false) {
const employeesValid = await this._validateEmployees(); const employeesValid = await this._validateEmployees();
const timeblocksValid = await this._validateTimeblocks(); const timeblocksValid = await this._validateTimeblocks();
@@ -787,6 +788,12 @@ export default {
if (!employeesValid || !timeblocksValid) return; if (!employeesValid || !timeblocksValid) return;
return true; return true;
} else {
const employeesValid = await this._validateEmployees();
if (!employeesValid) return;
return true;
}
}, },
async handleOnRemoveEmployee() { async handleOnRemoveEmployee() {
@@ -799,16 +806,18 @@ export default {
async save(concept = false) { async save(concept = false) {
this.wasFormValidationTriggered = true; this.wasFormValidationTriggered = true;
if (!(await this.validateAllFields())) return; if (!(await this.validateAllFields(concept))) return;
this.subtask.description = this.$refs['description'].getHTML(); this.subtask.description = this.$refs['description'].getHTML();
this._mergeDeadlineTimeDate(); this._mergeDeadlineTimeDate();
try { try {
this.isSaving = true; this.isSaving = true;
this.subtask.deadline = moment(this.subtask.deadline).format(
'YYYY-MM-DD HH:mm:SS', // Concept tasks may not have a deadline time set
); this.subtask.deadline = this.subtask.deadline
? moment(this.subtask.deadline).format('YYYY-MM-DD HH:mm:SS')
: null;
if (this.subtask?.id) { if (this.subtask?.id) {
const timesheets = this.subtask.timesheets.map((timesheet) => { const timesheets = this.subtask.timesheets.map((timesheet) => {
@@ -920,6 +929,10 @@ export default {
}, },
_mergeDeadlineTimeDate() { _mergeDeadlineTimeDate() {
// Override for concept tasks which may not have a deadline time set (check for invalid date)
if (isNaN(new Date(this.subtask.deadline).getTime())) {
this.subtask.deadline = null;
} else {
const date = new Date(this.subtask.deadline); const date = new Date(this.subtask.deadline);
const timeParts = this.subtask._deadline_time.split(':'); const timeParts = this.subtask._deadline_time.split(':');
@@ -927,6 +940,7 @@ export default {
date.setMinutes(parseInt(timeParts[1])); date.setMinutes(parseInt(timeParts[1]));
this.subtask.deadline = date; this.subtask.deadline = date;
}
}, },
_validateEmployees() { _validateEmployees() {