fix(task-modal): fix employee timeblock management during subtask edits to keep timeblocks on employee change

This commit is contained in:
Matej Glasnák committed 2025-12-12 17:10:39 +01:00
1 parent 5ea6f3b93a
commit bb5e97f022
1 file changed
+36 -10
+36 -10
View File
@@ -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];
},