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 887b5df..1992945 100644 --- a/app/src/plugins/tm@modal/task/z-task-modal.vue +++ b/app/src/plugins/tm@modal/task/z-task-modal.vue @@ -366,7 +366,21 @@ export default { 'subtask.employee_id'(value, oldValue) { if (!value || !oldValue) return; - this.subtask.timeblocks = []; + // In edit mode: reassign timeblocks to new employee + if (this.subtask.id) { + this.timeblocks = this.timeblocks.map((tb) => { + if (tb.employee_id === oldValue) { + return { ...tb, employee_id: value }; + } + return tb; + }); + } else { + // In create mode: remove old employee's timeblocks + this.timeblocks = this.timeblocks.filter( + (tb) => tb.employee_id !== oldValue, + ); + } + this.subtask._employee = this.enrichedEmployees.find( (employee) => employee.id == this.subtask.employee_id, ); @@ -434,13 +448,15 @@ export default { }); this.$events.on('add-timeblock', (timeblock) => { - if (!this.subtask?.timeblocks) { + if (!this.subtask) return; + + if (!this.subtask.timeblocks) { this.subtask.timeblocks = []; } - if (!this.subtask?.timesheets) { + if (!this.subtask.timesheets) { this.subtask.timesheets = []; } - if (!this.subtask?.is_finished) { + if (!this.subtask.is_finished) { this.subtask.is_finished = 0; } this.subtask.timeblocks.push(timeblock); @@ -543,17 +559,27 @@ export default { updateEmployeeTimeblocks(updatedTimeblocks, employeeId) { // Track deleted timeblocks (saved timeblocks that are no longer in the updated list) - const updatedIds = new Set(updatedTimeblocks.filter(tb => tb.id).map(tb => tb.id)); + const updatedIds = new Set( + updatedTimeblocks.filter((tb) => tb.id).map((tb) => tb.id), + ); const deletedIds = this.timeblocks - .filter(tb => tb.employee_id === employeeId && tb.id && !updatedIds.has(tb.id)) - .map(tb => tb.id) - .filter(id => !this.deletedTimeblockIds.includes(id)); + .filter( + (tb) => + tb.employee_id === employeeId && tb.id && !updatedIds.has(tb.id), + ) + .map((tb) => tb.id) + .filter((id) => !this.deletedTimeblockIds.includes(id)); this.deletedTimeblockIds.push(...deletedIds); // Replace timeblocks for this employee - const otherEmployeeTimeblocks = this.timeblocks.filter(tb => tb.employee_id !== employeeId); - const updatedWithEmployeeId = updatedTimeblocks.map(tb => ({ ...tb, employee_id: employeeId })); + const otherEmployeeTimeblocks = this.timeblocks.filter( + (tb) => tb.employee_id !== employeeId, + ); + const updatedWithEmployeeId = updatedTimeblocks.map((tb) => ({ + ...tb, + employee_id: employeeId, + })); this.timeblocks = [...otherEmployeeTimeblocks, ...updatedWithEmployeeId]; },