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:
@@ -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,
|
||||
|
||||
@@ -35,6 +35,7 @@ import {
|
||||
} from '@/features/tasks/tasks.slice';
|
||||
import {
|
||||
addTask,
|
||||
addTaskToGroup,
|
||||
updateTask,
|
||||
moveTaskToGroup,
|
||||
selectCurrentGroupingV3,
|
||||
@@ -355,7 +356,39 @@ export const useTaskSocketHandlers = () => {
|
||||
order: data.sort_order || 0,
|
||||
};
|
||||
|
||||
dispatch(addTask(task));
|
||||
// Extract the group UUID from the backend response based on current grouping
|
||||
let groupId: string | undefined;
|
||||
|
||||
console.log('🔍 Quick task received:', {
|
||||
currentGrouping: currentGroupingV3,
|
||||
status: data.status,
|
||||
priority: data.priority,
|
||||
phase_id: data.phase_id
|
||||
});
|
||||
|
||||
// Select the correct UUID based on current grouping
|
||||
// If currentGroupingV3 is null, default to 'status' since that's the most common grouping
|
||||
const grouping = currentGroupingV3 || 'status';
|
||||
console.log('📊 Using grouping:', grouping);
|
||||
|
||||
if (grouping === 'status') {
|
||||
// For status grouping, use status field (which contains the status UUID)
|
||||
groupId = data.status;
|
||||
console.log('✅ Using status UUID:', groupId);
|
||||
} else if (grouping === 'priority') {
|
||||
// For priority grouping, use priority field (which contains the priority UUID)
|
||||
groupId = data.priority;
|
||||
console.log('✅ Using priority UUID:', groupId);
|
||||
} else if (grouping === 'phase') {
|
||||
// For phase grouping, use phase_id
|
||||
groupId = data.phase_id;
|
||||
console.log('✅ Using phase UUID:', groupId);
|
||||
}
|
||||
|
||||
console.log('📤 Dispatching addTaskToGroup with:', { taskId: task.id, groupId });
|
||||
|
||||
// Use addTaskToGroup with the actual group UUID
|
||||
dispatch(addTaskToGroup({ task, groupId }));
|
||||
}
|
||||
},
|
||||
[dispatch]
|
||||
|
||||
Reference in New Issue
Block a user