feat(project-view-board): implement task priority change handling
- Added a new function to handle task priority changes via socket events. - Integrated priority change logic into the drag-and-drop functionality for improved task management. - Cleaned up unused imports and improved code organization for better readability.
This commit is contained in:
@@ -1,4 +1,4 @@
|
|||||||
import { useEffect, useState, useRef, useMemo, useCallback } from 'react';
|
import { useEffect, useState, useRef, useCallback } from 'react';
|
||||||
import { useAppSelector } from '@/hooks/useAppSelector';
|
import { useAppSelector } from '@/hooks/useAppSelector';
|
||||||
import TaskListFilters from '../taskList/task-list-filters/task-list-filters';
|
import TaskListFilters from '../taskList/task-list-filters/task-list-filters';
|
||||||
import { Flex, Skeleton } from 'antd';
|
import { Flex, Skeleton } from 'antd';
|
||||||
@@ -22,14 +22,10 @@ import {
|
|||||||
TouchSensor,
|
TouchSensor,
|
||||||
useSensor,
|
useSensor,
|
||||||
useSensors,
|
useSensors,
|
||||||
MeasuringStrategy,
|
|
||||||
getFirstCollision,
|
getFirstCollision,
|
||||||
pointerWithin,
|
pointerWithin,
|
||||||
rectIntersection,
|
rectIntersection,
|
||||||
UniqueIdentifier,
|
UniqueIdentifier,
|
||||||
DragOverlayProps,
|
|
||||||
DragOverlay as DragOverlayType,
|
|
||||||
closestCorners,
|
|
||||||
} from '@dnd-kit/core';
|
} from '@dnd-kit/core';
|
||||||
import BoardViewTaskCard from './board-section/board-task-card/board-view-task-card';
|
import BoardViewTaskCard from './board-section/board-task-card/board-view-task-card';
|
||||||
import { fetchStatusesCategories } from '@/features/taskAttributes/taskStatusSlice';
|
import { fetchStatusesCategories } from '@/features/taskAttributes/taskStatusSlice';
|
||||||
@@ -45,7 +41,8 @@ import { statusApiService } from '@/api/taskAttributes/status/status.api.service
|
|||||||
import logger from '@/utils/errorLogger';
|
import logger from '@/utils/errorLogger';
|
||||||
import { checkTaskDependencyStatus } from '@/utils/check-task-dependency-status';
|
import { checkTaskDependencyStatus } from '@/utils/check-task-dependency-status';
|
||||||
import { debounce } from 'lodash';
|
import { debounce } from 'lodash';
|
||||||
|
import { ITaskListPriorityChangeResponse } from '@/types/tasks/task-list-priority.types';
|
||||||
|
import { updateTaskPriority as updateBoardTaskPriority } from '@/features/board/board-slice';
|
||||||
interface DroppableContainer {
|
interface DroppableContainer {
|
||||||
id: UniqueIdentifier;
|
id: UniqueIdentifier;
|
||||||
data: {
|
data: {
|
||||||
@@ -272,6 +269,21 @@ const ProjectViewBoard = () => {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const handlePriorityChange = (taskId: string, priorityId: string) => {
|
||||||
|
if (!taskId || !priorityId || !socket) return;
|
||||||
|
|
||||||
|
const payload = {
|
||||||
|
task_id: taskId,
|
||||||
|
priority_id: priorityId,
|
||||||
|
team_id: currentSession?.team_id,
|
||||||
|
};
|
||||||
|
|
||||||
|
socket.emit(SocketEvents.TASK_PRIORITY_CHANGE.toString(), JSON.stringify(payload));
|
||||||
|
socket.once(SocketEvents.TASK_PRIORITY_CHANGE.toString(), (data: ITaskListPriorityChangeResponse) => {
|
||||||
|
dispatch(updateBoardTaskPriority(data));
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
const handleDragEnd = async (event: DragEndEvent) => {
|
const handleDragEnd = async (event: DragEndEvent) => {
|
||||||
isDraggingRef.current = false;
|
isDraggingRef.current = false;
|
||||||
const { active, over } = event;
|
const { active, over } = event;
|
||||||
@@ -316,6 +328,7 @@ const ProjectViewBoard = () => {
|
|||||||
originalSourceGroupIdRef.current = null; // Reset the ref
|
originalSourceGroupIdRef.current = null; // Reset the ref
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (targetGroupId !== sourceGroupId) {
|
if (targetGroupId !== sourceGroupId) {
|
||||||
const canContinue = await checkTaskDependencyStatus(task.id, targetGroupId);
|
const canContinue = await checkTaskDependencyStatus(task.id, targetGroupId);
|
||||||
if (!canContinue) {
|
if (!canContinue) {
|
||||||
@@ -375,8 +388,6 @@ const ProjectViewBoard = () => {
|
|||||||
team_id: currentSession?.team_id
|
team_id: currentSession?.team_id
|
||||||
};
|
};
|
||||||
|
|
||||||
// logger.error('Emitting socket event with payload (task not found in source):', body);
|
|
||||||
|
|
||||||
// Emit socket event
|
// Emit socket event
|
||||||
if (socket) {
|
if (socket) {
|
||||||
socket.emit(SocketEvents.TASK_SORT_ORDER_CHANGE.toString(), body);
|
socket.emit(SocketEvents.TASK_SORT_ORDER_CHANGE.toString(), body);
|
||||||
@@ -389,6 +400,11 @@ const ProjectViewBoard = () => {
|
|||||||
socket.emit(SocketEvents.GET_TASK_PROGRESS.toString(), task.id);
|
socket.emit(SocketEvents.GET_TASK_PROGRESS.toString(), task.id);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// Handle priority change if groupBy is priority
|
||||||
|
if (groupBy === IGroupBy.PRIORITY) {
|
||||||
|
handlePriorityChange(task.id, targetGroupId);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Track analytics event
|
// Track analytics event
|
||||||
|
|||||||
Reference in New Issue
Block a user