feat(task-management): add functionality to assign tasks to specific groups

- Introduced `addTaskToGroup` action to allow tasks to be added to designated groups based on group IDs.
- Enhanced task management slice to support group assignment for better organization and compatibility with V3 API.
- Updated socket handlers to dispatch `addTaskToGroup` with appropriate group IDs extracted from backend responses.
This commit is contained in:
chamiakJ
2025-06-27 07:06:02 +05:30
parent 3d1cb29a67
commit 84f77940fd
2 changed files with 73 additions and 1 deletions

View File

@@ -226,6 +226,44 @@ const taskManagementSlice = createSlice({
tasksAdapter.addOne(state, action.payload);
},
addTaskToGroup: (state, action: PayloadAction<{ task: Task; groupId?: string }>) => {
const { task, groupId } = action.payload;
// Add to entity adapter
tasksAdapter.addOne(state, task);
// Add to groups array for V3 API compatibility
if (state.groups && state.groups.length > 0) {
console.log('🔍 Looking for group with ID:', groupId);
console.log('📋 Available groups:', state.groups.map(g => ({ id: g.id, title: g.title })));
// Find the target group using the provided UUID
const targetGroup = state.groups.find(group => {
// If a specific groupId (UUID) is provided, use it directly
if (groupId && group.id === groupId) {
return true;
}
return false;
});
if (targetGroup) {
console.log('✅ Found target group:', targetGroup.title);
// Add task ID to the end of the group's taskIds array (newest last)
targetGroup.taskIds.push(task.id);
console.log('✅ Task added to group. New taskIds count:', targetGroup.taskIds.length);
// Also add to the tasks array if it exists (for backward compatibility)
if ((targetGroup as any).tasks) {
(targetGroup as any).tasks.push(task);
}
} else {
console.warn('❌ No matching group found for groupId:', groupId);
}
}
},
updateTask: (state, action: PayloadAction<{ id: string; changes: Partial<Task> }>) => {
tasksAdapter.updateOne(state, {
id: action.payload.id,
@@ -392,6 +430,7 @@ const taskManagementSlice = createSlice({
export const {
setTasks,
addTask,
addTaskToGroup,
updateTask,
deleteTask,
bulkUpdateTasks,