import React, { useEffect, useState } from 'react'; import { DatePicker, Tooltip, Tag, Avatar, Progress, Typography, Dropdown, MenuProps, Button, } from 'antd'; import { DoubleRightOutlined, PauseOutlined, UserAddOutlined, InboxOutlined, DeleteOutlined, MinusOutlined, ForkOutlined, CaretRightFilled, CaretDownFilled, } from '@ant-design/icons'; import './TaskCard.css'; import dayjs, { Dayjs } from 'dayjs'; import AddMembersDropdown from '../../add-members-dropdown/add-members-dropdown'; import { useAppDispatch } from '@/hooks/useAppDispatch'; import { deleteTask } from '../../../features/tasks/tasks.slice'; import SubTaskCard from '../subTaskCard/SubTaskCard'; import { useAppSelector } from '@/hooks/useAppSelector'; import { useTranslation } from 'react-i18next'; import { IProjectTask } from '@/types/project/projectTasksViewModel.types'; import Avatars from '@/components/avatars/avatars'; import { useSortable } from '@dnd-kit/sortable'; import { CSS } from '@dnd-kit/utilities'; import { UniqueIdentifier } from '@dnd-kit/core'; interface taskProps { task: IProjectTask; } const TaskCard: React.FC = ({ task }) => { const [isSubTaskShow, setIsSubTaskShow] = useState(false); const [dueDate, setDueDate] = useState(null); const [isToday, setIsToday] = useState(false); const [isTomorrow, setIsTomorrow] = useState(false); const [isItPrevDate, setIsItPrevDate] = useState(false); const themeMode = useAppSelector(state => state.themeReducer.mode); const dispatch = useAppDispatch(); const { attributes, listeners, setNodeRef, transform, transition, isDragging } = useSortable({ id: task.id as UniqueIdentifier, data: { type: 'task', task, }, }); const handleDateChange = (date: Dayjs | null) => { setDueDate(date); }; const { t } = useTranslation('kanban-board'); const formatDate = (date: Dayjs | null) => { if (!date) return ''; const today = dayjs(); const tomorrow = today.add(1, 'day'); if (date.isSame(today, 'day')) { return t('today'); } else if (date.isSame(tomorrow, 'day')) { return t('tomorrow'); } else { return date.isSame(today, 'year') ? date.format('MMM DD') : date.format('MMM DD, YYYY'); } }; useEffect(() => { if (dueDate) { setIsToday(dueDate.isSame(dayjs(), 'day')); setIsTomorrow(dueDate.isSame(dayjs().add(1, 'day'), 'day')); setIsItPrevDate(dueDate.isBefore(dayjs())); } else { setIsToday(false); setIsTomorrow(false); setIsItPrevDate(false); } }, [dueDate]); const handleDelete = () => { if (!task.id) return; dispatch(deleteTask(task.id)); // Call delete function with taskId }; const items: MenuProps['items'] = [ { label: ( {t('assignToMe')} ), key: '1', }, { label: ( {t('archive')} ), key: '2', }, { label: ( {t('delete')} ), key: '3', }, ]; // const progress = (task.subTasks?.length || 0 + 1 )/ (task.subTasks?.length || 0 + 1) const style = { transform: CSS.Transform.toString(transform), transition, opacity: isDragging ? 0.5 : 1, position: 'relative', touchAction: 'none', }; return (
{/* Labels and Progress */}
{task.labels?.length ? ( <> {task.labels.slice(0, 2).map((label, index) => ( {label.name} ))} {task.labels?.length > 2 && + {task.labels.length - 2}} ) : ( '' )}
{/* Action Icons */}
{task.priority === 'low' ? ( ) : task.priority === 'medium' ? ( ) : ( )} {task.name}
{/* Subtask Section */}
formatDate(value)} />
{task.sub_tasks_count && task.sub_tasks_count > 0 && ( )}
{isSubTaskShow && task.sub_tasks_count && task.sub_tasks_count > 0 && task.sub_tasks?.map(subtask => )}
); }; export default TaskCard;