feat(board): enhance task and subtask management in board components
- Updated boardSlice to allow updating task assignees and names for both main tasks and subtasks. - Improved BoardSubTaskCard to include context menu options for assigning tasks, deleting subtasks, and handling errors. - Refactored BoardViewTaskCard to integrate dropdown menus for better task interaction and organization. - Enhanced user experience by adding loading states and error handling for task actions.
This commit is contained in:
@@ -459,10 +459,24 @@ const boardSlice = createSlice({
|
|||||||
const { body, sectionId, taskId } = action.payload;
|
const { body, sectionId, taskId } = action.payload;
|
||||||
const section = state.taskGroups.find(sec => sec.id === sectionId);
|
const section = state.taskGroups.find(sec => sec.id === sectionId);
|
||||||
if (section) {
|
if (section) {
|
||||||
const task = section.tasks.find(task => task.id === taskId);
|
// First try to find the task in main tasks
|
||||||
if (task) {
|
const mainTask = section.tasks.find(task => task.id === taskId);
|
||||||
task.assignees = body.assignees;
|
if (mainTask) {
|
||||||
task.names = body.names;
|
mainTask.assignees = body.assignees;
|
||||||
|
mainTask.names = body.names;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// If not found in main tasks, look in subtasks
|
||||||
|
for (const parentTask of section.tasks) {
|
||||||
|
if (!parentTask.sub_tasks) continue;
|
||||||
|
|
||||||
|
const subtask = parentTask.sub_tasks.find(st => st.id === taskId);
|
||||||
|
if (subtask) {
|
||||||
|
subtask.assignees = body.assignees;
|
||||||
|
subtask.names = body.names;
|
||||||
|
return;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -1,11 +1,25 @@
|
|||||||
import { useState } from 'react';
|
import { useCallback, useState } from 'react';
|
||||||
import dayjs, { Dayjs } from 'dayjs';
|
import dayjs, { Dayjs } from 'dayjs';
|
||||||
import { Col, Flex, Typography, List } from 'antd';
|
import { Col, Flex, Typography, List, Dropdown, MenuProps, Popconfirm } from 'antd';
|
||||||
|
import { UserAddOutlined, DeleteOutlined, ExclamationCircleFilled, InboxOutlined } from '@ant-design/icons';
|
||||||
import CustomAvatarGroup from '@/components/board/custom-avatar-group';
|
import CustomAvatarGroup from '@/components/board/custom-avatar-group';
|
||||||
import CustomDueDatePicker from '@/components/board/custom-due-date-picker';
|
import CustomDueDatePicker from '@/components/board/custom-due-date-picker';
|
||||||
import { IProjectTask } from '@/types/project/projectTasksViewModel.types';
|
import { IProjectTask } from '@/types/project/projectTasksViewModel.types';
|
||||||
import { useAppDispatch } from '@/hooks/useAppDispatch';
|
import { useAppDispatch } from '@/hooks/useAppDispatch';
|
||||||
import { setSelectedTaskId, setShowTaskDrawer } from '@/features/task-drawer/task-drawer.slice';
|
import { setSelectedTaskId, setShowTaskDrawer } from '@/features/task-drawer/task-drawer.slice';
|
||||||
|
import { useTranslation } from 'react-i18next';
|
||||||
|
import { colors } from '@/styles/colors';
|
||||||
|
import { taskListBulkActionsApiService } from '@/api/tasks/task-list-bulk-actions.api.service';
|
||||||
|
import { useMixpanelTracking } from '@/hooks/useMixpanelTracking';
|
||||||
|
import {
|
||||||
|
evt_project_task_list_context_menu_assign_me,
|
||||||
|
evt_project_task_list_context_menu_delete,
|
||||||
|
evt_project_task_list_context_menu_archive,
|
||||||
|
} from '@/shared/worklenz-analytics-events';
|
||||||
|
import logger from '@/utils/errorLogger';
|
||||||
|
import { useAppSelector } from '@/hooks/useAppSelector';
|
||||||
|
import { deleteBoardTask, updateBoardTaskAssignee } from '@features/board/board-slice';
|
||||||
|
import { IBulkAssignRequest } from '@/types/tasks/bulk-action-bar.types';
|
||||||
|
|
||||||
interface IBoardSubTaskCardProps {
|
interface IBoardSubTaskCardProps {
|
||||||
subtask: IProjectTask;
|
subtask: IProjectTask;
|
||||||
@@ -14,48 +28,153 @@ interface IBoardSubTaskCardProps {
|
|||||||
|
|
||||||
const BoardSubTaskCard = ({ subtask, sectionId }: IBoardSubTaskCardProps) => {
|
const BoardSubTaskCard = ({ subtask, sectionId }: IBoardSubTaskCardProps) => {
|
||||||
const dispatch = useAppDispatch();
|
const dispatch = useAppDispatch();
|
||||||
|
const { t } = useTranslation('kanban-board');
|
||||||
|
const { trackMixpanelEvent } = useMixpanelTracking();
|
||||||
|
const projectId = useAppSelector(state => state.projectReducer.projectId);
|
||||||
|
const [updatingAssignToMe, setUpdatingAssignToMe] = useState(false);
|
||||||
const [subtaskDueDate, setSubtaskDueDate] = useState<Dayjs | null>(
|
const [subtaskDueDate, setSubtaskDueDate] = useState<Dayjs | null>(
|
||||||
subtask?.end_date ? dayjs(subtask?.end_date) : null
|
subtask?.end_date ? dayjs(subtask?.end_date) : null
|
||||||
);
|
);
|
||||||
|
|
||||||
const handleCardClick = (e: React.MouseEvent, id: string) => {
|
const handleCardClick = (e: React.MouseEvent, id: string) => {
|
||||||
// Prevent the event from propagating to parent elements
|
|
||||||
e.stopPropagation();
|
e.stopPropagation();
|
||||||
|
|
||||||
// Add a small delay to ensure it's a click and not the start of a drag
|
|
||||||
const clickTimeout = setTimeout(() => {
|
const clickTimeout = setTimeout(() => {
|
||||||
dispatch(setSelectedTaskId(id));
|
dispatch(setSelectedTaskId(id));
|
||||||
dispatch(setShowTaskDrawer(true));
|
dispatch(setShowTaskDrawer(true));
|
||||||
}, 50);
|
}, 50);
|
||||||
|
|
||||||
return () => clearTimeout(clickTimeout);
|
return () => clearTimeout(clickTimeout);
|
||||||
};
|
};
|
||||||
|
|
||||||
return (
|
const handleAssignToMe = useCallback(async () => {
|
||||||
<List.Item
|
if (!projectId || !subtask.id || updatingAssignToMe) return;
|
||||||
key={subtask.id}
|
|
||||||
className="group"
|
try {
|
||||||
style={{
|
setUpdatingAssignToMe(true);
|
||||||
width: '100%',
|
const body: IBulkAssignRequest = {
|
||||||
}}
|
tasks: [subtask.id],
|
||||||
onClick={e => handleCardClick(e, subtask.id || '')}
|
project_id: projectId,
|
||||||
>
|
};
|
||||||
<Col span={10}>
|
const res = await taskListBulkActionsApiService.assignToMe(body);
|
||||||
<Typography.Text
|
if (res.done) {
|
||||||
style={{ fontWeight: 500, fontSize: 14 }}
|
trackMixpanelEvent(evt_project_task_list_context_menu_assign_me);
|
||||||
delete={subtask.status === 'done'}
|
dispatch(
|
||||||
ellipsis={{ expanded: false }}
|
updateBoardTaskAssignee({
|
||||||
|
body: res.body,
|
||||||
|
sectionId,
|
||||||
|
taskId: subtask.id,
|
||||||
|
})
|
||||||
|
);
|
||||||
|
}
|
||||||
|
} catch (error) {
|
||||||
|
logger.error('Error assigning task to me:', error);
|
||||||
|
} finally {
|
||||||
|
setUpdatingAssignToMe(false);
|
||||||
|
}
|
||||||
|
}, [projectId, subtask.id, updatingAssignToMe, dispatch, trackMixpanelEvent, sectionId]);
|
||||||
|
|
||||||
|
// const handleArchive = async () => {
|
||||||
|
// if (!projectId || !subtask.id) return;
|
||||||
|
|
||||||
|
// try {
|
||||||
|
// const res = await taskListBulkActionsApiService.archiveTasks(
|
||||||
|
// {
|
||||||
|
// tasks: [subtask.id],
|
||||||
|
// project_id: projectId,
|
||||||
|
// },
|
||||||
|
// false
|
||||||
|
// );
|
||||||
|
|
||||||
|
// if (res.done) {
|
||||||
|
// trackMixpanelEvent(evt_project_task_list_context_menu_archive);
|
||||||
|
// dispatch(deleteBoardTask({ sectionId, taskId: subtask.id }));
|
||||||
|
// }
|
||||||
|
// } catch (error) {
|
||||||
|
// logger.error('Error archiving subtask:', error);
|
||||||
|
// }
|
||||||
|
// };
|
||||||
|
|
||||||
|
const handleDelete = async () => {
|
||||||
|
if (!projectId || !subtask.id) return;
|
||||||
|
|
||||||
|
try {
|
||||||
|
const res = await taskListBulkActionsApiService.deleteTasks({ tasks: [subtask.id] }, projectId);
|
||||||
|
if (res.done) {
|
||||||
|
trackMixpanelEvent(evt_project_task_list_context_menu_delete);
|
||||||
|
dispatch(deleteBoardTask({ sectionId, taskId: subtask.id }));
|
||||||
|
}
|
||||||
|
} catch (error) {
|
||||||
|
logger.error('Error deleting subtask:', error);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
const items: MenuProps['items'] = [
|
||||||
|
{
|
||||||
|
label: (
|
||||||
|
<span>
|
||||||
|
<UserAddOutlined />
|
||||||
|
|
||||||
|
<Typography.Text>{t('assignToMe')}</Typography.Text>
|
||||||
|
</span>
|
||||||
|
),
|
||||||
|
key: '1',
|
||||||
|
onClick: () => handleAssignToMe(),
|
||||||
|
disabled: updatingAssignToMe,
|
||||||
|
},
|
||||||
|
// {
|
||||||
|
// label: (
|
||||||
|
// <span>
|
||||||
|
// <InboxOutlined />
|
||||||
|
//
|
||||||
|
// <Typography.Text>{t('archive')}</Typography.Text>
|
||||||
|
// </span>
|
||||||
|
// ),
|
||||||
|
// key: '2',
|
||||||
|
// onClick: () => handleArchive(),
|
||||||
|
// },
|
||||||
|
{
|
||||||
|
label: (
|
||||||
|
<Popconfirm
|
||||||
|
title={t('deleteConfirmationTitle')}
|
||||||
|
icon={<ExclamationCircleFilled style={{ color: colors.vibrantOrange }} />}
|
||||||
|
okText={t('deleteConfirmationOk')}
|
||||||
|
cancelText={t('deleteConfirmationCancel')}
|
||||||
|
onConfirm={() => handleDelete()}
|
||||||
>
|
>
|
||||||
{subtask.name}
|
<DeleteOutlined />
|
||||||
</Typography.Text>
|
|
||||||
</Col>
|
{t('delete')}
|
||||||
|
</Popconfirm>
|
||||||
|
),
|
||||||
|
key: '3',
|
||||||
|
},
|
||||||
|
];
|
||||||
|
|
||||||
<Flex gap={8} justify="end" style={{ width: '100%' }}>
|
return (
|
||||||
<CustomAvatarGroup task={subtask} sectionId={sectionId} />
|
<Dropdown menu={{ items }} trigger={['contextMenu']}>
|
||||||
|
<List.Item
|
||||||
|
key={subtask.id}
|
||||||
|
className="group"
|
||||||
|
style={{
|
||||||
|
width: '100%',
|
||||||
|
}}
|
||||||
|
onClick={e => handleCardClick(e, subtask.id || '')}
|
||||||
|
>
|
||||||
|
<Col span={10}>
|
||||||
|
<Typography.Text
|
||||||
|
style={{ fontWeight: 500, fontSize: 14 }}
|
||||||
|
delete={subtask.status === 'done'}
|
||||||
|
ellipsis={{ expanded: false }}
|
||||||
|
>
|
||||||
|
{subtask.name}
|
||||||
|
</Typography.Text>
|
||||||
|
</Col>
|
||||||
|
|
||||||
<CustomDueDatePicker task={subtask} onDateChange={setSubtaskDueDate} />
|
<Flex gap={8} justify="end" style={{ width: '100%' }}>
|
||||||
</Flex>
|
<CustomAvatarGroup task={subtask} sectionId={sectionId} />
|
||||||
</List.Item>
|
<CustomDueDatePicker task={subtask} onDateChange={setSubtaskDueDate} />
|
||||||
|
</Flex>
|
||||||
|
</List.Item>
|
||||||
|
</Dropdown>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -256,50 +256,49 @@ const BoardViewTaskCard = ({ task, sectionId }: IBoardViewTaskCardProps) => {
|
|||||||
}, [task.labels, themeMode]);
|
}, [task.labels, themeMode]);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Dropdown menu={{ items }} trigger={['contextMenu']}>
|
<Flex
|
||||||
<Flex
|
ref={setNodeRef}
|
||||||
ref={setNodeRef}
|
{...attributes}
|
||||||
{...attributes}
|
{...listeners}
|
||||||
{...listeners}
|
vertical
|
||||||
vertical
|
gap={12}
|
||||||
gap={12}
|
style={{
|
||||||
style={{
|
...style,
|
||||||
...style,
|
width: '100%',
|
||||||
width: '100%',
|
padding: 12,
|
||||||
padding: 12,
|
backgroundColor: themeMode === 'dark' ? '#292929' : '#fafafa',
|
||||||
backgroundColor: themeMode === 'dark' ? '#292929' : '#fafafa',
|
borderRadius: 6,
|
||||||
borderRadius: 6,
|
cursor: 'grab',
|
||||||
cursor: 'grab',
|
overflow: 'hidden',
|
||||||
overflow: 'hidden',
|
}}
|
||||||
}}
|
className={`group outline-1 ${themeWiseColor('outline-[#edeae9]', 'outline-[#6a696a]', themeMode)} hover:outline board-task-card`}
|
||||||
className={`group outline-1 ${themeWiseColor('outline-[#edeae9]', 'outline-[#6a696a]', themeMode)} hover:outline board-task-card`}
|
data-id={task.id}
|
||||||
onClick={e => handleCardClick(e, task.id || '')}
|
data-dragging={isDragging ? "true" : "false"}
|
||||||
data-id={task.id}
|
>
|
||||||
data-dragging={isDragging ? "true" : "false"}
|
<Dropdown menu={{ items }} trigger={['contextMenu']}>
|
||||||
>
|
{/* Task Card */}
|
||||||
{/* Labels and Progress */}
|
<Flex vertical gap={8}
|
||||||
<Flex align="center" justify="space-between">
|
onClick={e => handleCardClick(e, task.id || '')}>
|
||||||
<Flex>
|
{/* Labels and Progress */}
|
||||||
{renderLabels}
|
<Flex align="center" justify="space-between">
|
||||||
|
<Flex>
|
||||||
|
{renderLabels}
|
||||||
|
</Flex>
|
||||||
|
|
||||||
|
<Tooltip title={` ${task?.completed_count} / ${task?.total_tasks_count}`}>
|
||||||
|
<Progress type="circle" percent={task?.complete_ratio} size={26} strokeWidth={(task.complete_ratio || 0) >= 100 ? 9 : 7} />
|
||||||
|
</Tooltip>
|
||||||
|
</Flex>
|
||||||
|
<Flex gap={4} align="center">
|
||||||
|
{/* Action Icons */}
|
||||||
|
<PrioritySection task={task} />
|
||||||
|
<Typography.Text
|
||||||
|
style={{ fontWeight: 500 }}
|
||||||
|
ellipsis={{ tooltip: task.name }}
|
||||||
|
>
|
||||||
|
{task.name}
|
||||||
|
</Typography.Text>
|
||||||
</Flex>
|
</Flex>
|
||||||
|
|
||||||
<Tooltip title={` ${task?.completed_count} / ${task?.total_tasks_count}`}>
|
|
||||||
<Progress type="circle" percent={task?.complete_ratio} size={26} strokeWidth={(task.complete_ratio || 0) >= 100 ? 9 : 7} />
|
|
||||||
</Tooltip>
|
|
||||||
</Flex>
|
|
||||||
<Flex gap={4} align="center">
|
|
||||||
{/* Action Icons */}
|
|
||||||
<PrioritySection task={task} />
|
|
||||||
<Typography.Text
|
|
||||||
style={{ fontWeight: 500 }}
|
|
||||||
ellipsis={{ tooltip: task.name }}
|
|
||||||
>
|
|
||||||
{task.name}
|
|
||||||
</Typography.Text>
|
|
||||||
</Flex>
|
|
||||||
|
|
||||||
|
|
||||||
<Flex vertical gap={8}>
|
|
||||||
<Flex
|
<Flex
|
||||||
align="center"
|
align="center"
|
||||||
justify="space-between"
|
justify="space-between"
|
||||||
@@ -337,47 +336,50 @@ const BoardViewTaskCard = ({ task, sectionId }: IBoardViewTaskCardProps) => {
|
|||||||
</Button>
|
</Button>
|
||||||
</Flex>
|
</Flex>
|
||||||
</Flex>
|
</Flex>
|
||||||
|
|
||||||
{isSubTaskShow && (
|
|
||||||
<Flex vertical>
|
|
||||||
<Divider style={{ marginBlock: 0 }} />
|
|
||||||
<List>
|
|
||||||
{task.sub_tasks_loading && (
|
|
||||||
<List.Item>
|
|
||||||
<Skeleton active paragraph={{ rows: 2 }} title={false} style={{ marginTop: 8 }} />
|
|
||||||
</List.Item>
|
|
||||||
)}
|
|
||||||
|
|
||||||
{!task.sub_tasks_loading && task?.sub_tasks &&
|
|
||||||
task?.sub_tasks.map((subtask: any) => (
|
|
||||||
<BoardSubTaskCard key={subtask.id} subtask={subtask} sectionId={sectionId} />
|
|
||||||
))}
|
|
||||||
|
|
||||||
{showNewSubtaskCard && (
|
|
||||||
<BoardCreateSubtaskCard
|
|
||||||
sectionId={sectionId}
|
|
||||||
parentTaskId={task.id || ''}
|
|
||||||
setShowNewSubtaskCard={setShowNewSubtaskCard}
|
|
||||||
/>
|
|
||||||
)}
|
|
||||||
</List>
|
|
||||||
<Button
|
|
||||||
type="text"
|
|
||||||
style={{
|
|
||||||
width: 'fit-content',
|
|
||||||
borderRadius: 6,
|
|
||||||
boxShadow: 'none',
|
|
||||||
}}
|
|
||||||
icon={<PlusOutlined />}
|
|
||||||
onClick={handleAddSubtaskClick}
|
|
||||||
>
|
|
||||||
{t('addSubtask', 'Add Subtask')}
|
|
||||||
</Button>
|
|
||||||
</Flex>
|
|
||||||
)}
|
|
||||||
</Flex>
|
</Flex>
|
||||||
|
</Dropdown>
|
||||||
|
{/* Subtask Section */}
|
||||||
|
<Flex vertical gap={8}>
|
||||||
|
{isSubTaskShow && (
|
||||||
|
<Flex vertical>
|
||||||
|
<Divider style={{ marginBlock: 0 }} />
|
||||||
|
<List>
|
||||||
|
{task.sub_tasks_loading && (
|
||||||
|
<List.Item>
|
||||||
|
<Skeleton active paragraph={{ rows: 2 }} title={false} style={{ marginTop: 8 }} />
|
||||||
|
</List.Item>
|
||||||
|
)}
|
||||||
|
|
||||||
|
{!task.sub_tasks_loading && task?.sub_tasks &&
|
||||||
|
task?.sub_tasks.map((subtask: any) => (
|
||||||
|
<BoardSubTaskCard key={subtask.id} subtask={subtask} sectionId={sectionId} />
|
||||||
|
))}
|
||||||
|
|
||||||
|
{showNewSubtaskCard && (
|
||||||
|
<BoardCreateSubtaskCard
|
||||||
|
sectionId={sectionId}
|
||||||
|
parentTaskId={task.id || ''}
|
||||||
|
setShowNewSubtaskCard={setShowNewSubtaskCard}
|
||||||
|
/>
|
||||||
|
)}
|
||||||
|
</List>
|
||||||
|
<Button
|
||||||
|
type="text"
|
||||||
|
style={{
|
||||||
|
width: 'fit-content',
|
||||||
|
borderRadius: 6,
|
||||||
|
boxShadow: 'none',
|
||||||
|
}}
|
||||||
|
icon={<PlusOutlined />}
|
||||||
|
onClick={handleAddSubtaskClick}
|
||||||
|
>
|
||||||
|
{t('addSubtask', 'Add Subtask')}
|
||||||
|
</Button>
|
||||||
|
</Flex>
|
||||||
|
)}
|
||||||
</Flex>
|
</Flex>
|
||||||
</Dropdown>
|
</Flex>
|
||||||
|
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user