From f0bb76d131f5123ee1dd0a103292741de20d4421 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matej=20Glasn=C3=A1k?= Date: Wed, 7 May 2025 15:51:12 +0200 Subject: [PATCH] fix(z-task-modal): fixed employee handling and validation logic, as well as saving subtask to local storage --- .../plugins/tm@modal/task/z-task-modal.vue | 51 +++++++++++++++---- 1 file changed, 40 insertions(+), 11 deletions(-) diff --git a/app/src/plugins/tm@modal/task/z-task-modal.vue b/app/src/plugins/tm@modal/task/z-task-modal.vue index 48d68fd..b51c164 100644 --- a/app/src/plugins/tm@modal/task/z-task-modal.vue +++ b/app/src/plugins/tm@modal/task/z-task-modal.vue @@ -121,6 +121,7 @@ class="dp__icon dp__clear_icon dp__input_icons" data-test="clear-icon" @click.prevent=" + handleOnRemoveEmployee(); subtask.employee_id = null; subtask.employee = null; " @@ -202,7 +203,10 @@ viewBox="0 0 32 32" class="dp__icon dp__clear_icon dp__input_icons" data-test="clear-icon" - @click.prevent="employee.id = null" + @click.prevent=" + handleOnRemoveEmployee(); + employee.id = null; + " > { + this.validateAllFields(); + }, 100); + } + }, + + async save() { + this.wasFormValidationTriggered = true; + if (!(await this.validateAllFields())) return; this.subtask.description = this.$refs['description'].getHTML(); this._mergeDeadlineTimeDate(); @@ -749,17 +767,19 @@ export default { if (!this.subtask.duration) this.employeeValidations[0].duration = true; } else { + // For new subtasks, only validate non-empty employee entries this.subtask.employees.forEach((employee, index) => { - if (index == this.subtask.employees.length - 1 && index > 0) return; // Skip the last which is allways empty + // Skip validation if both id and duration are empty + if (!employee.id && !employee.duration) return; - if (employee.id && employee.duration) return; + // Only validate if either id or duration is filled + if (employee.id || employee.duration) { + this.employeeValidations[index] = {}; - this.employeeValidations[index] = {}; - - if (!employee.id) this.employeeValidations[index].employee = true; - - if (!employee.duration) - this.employeeValidations[index].duration = true; + if (!employee.id) this.employeeValidations[index].employee = true; + if (!employee.duration) + this.employeeValidations[index].duration = true; + } }); } @@ -835,7 +855,16 @@ export default { subtask: { handler(val) { if (this.editMode && !this.subtask?.id) { - localStorage.setItem('subtaskData', JSON.stringify(val)); + const employees = val.employees.filter( + (employee) => employee?.id || employee?.duration, + ) || [{}]; + + const subtaskData = { + ...val, + employees: employees && employees.length > 0 ? employees : [{}], + }; + console.log('subtaskData', subtaskData); + localStorage.setItem('subtaskData', JSON.stringify(subtaskData)); } }, deep: true,