import { Avatar, Button, DatePicker, Input, InputRef } from '@/shared/antd-imports'; import React, { forwardRef, useEffect, useRef, useState } from 'react'; import AddMembersDropdown from '../../add-members-dropdown/add-members-dropdown'; import dayjs, { Dayjs } from 'dayjs'; import './TaskCreateCard.css'; import { useAppDispatch } from '@/hooks/useAppDispatch'; import { addTask, addTaskToTop } from '../../../features/tasks/tasks.slice'; import { setTaskCardDisabled } from '../../../features/board/create-card.slice'; import { useAppSelector } from '@/hooks/useAppSelector'; import { useTranslation } from 'react-i18next'; interface StatusProps { status: string; position: 'top' | 'bottom'; } const TaskCreateCard = forwardRef(({ status, position }, ref) => { const [characterLength, setCharacterLength] = useState(0); const [dueDate, setDueDate] = useState(null); const [isToday, setIsToday] = useState(false); const [isTomorrow, setIsTomorrow] = useState(false); const [isItPrevDate, setIsItPrevDate] = useState(false); const [taskName, setTaskName] = useState(''); const dispatch = useAppDispatch(); const themeMode = useAppSelector(state => state.themeReducer.mode); const { t } = useTranslation('kanban-board'); const handleChange = (e: React.ChangeEvent) => { setCharacterLength(e.target.value.length); setTaskName(e.target.value); }; const handleDateChange = (date: Dayjs | null) => { setDueDate(date); }; const cardRef = useRef(null); useEffect(() => { if (cardRef.current) { cardRef.current.scrollIntoView({ behavior: 'smooth', block: 'center' }); } if (ref && typeof ref === 'object' && ref.current) { ref.current.focus(); } }, []); const formatDate = (date: Dayjs | null) => { if (!date) return ''; const today = dayjs(); const tomorrow = today.add(1, 'day'); if (date.isSame(today, 'day')) { return 'Today'; } else if (date.isSame(tomorrow, 'day')) { return '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 handleAddTask = () => { if (taskName.trim()) { if (position === 'bottom') { dispatch( addTask({ taskId: `SP-${Date.now()}`, task: taskName, description: '-', progress: status === 'done' ? 100 : 0, members: [], labels: [], status: status, priority: 'medium', timeTracking: 0, estimation: '-', startDate: new Date(), dueDate: dueDate ? dueDate.toDate() : null, completedDate: null, createdDate: new Date(), lastUpdated: new Date(), reporter: '-', phase: '', subTasks: [], }) ); } else if (position === 'top') { dispatch( addTaskToTop({ taskId: `SP-${Date.now()}`, task: taskName, description: '-', progress: status === 'done' ? 100 : 0, members: [], labels: [], status: status, priority: 'medium', timeTracking: 0, estimation: '-', startDate: new Date(), dueDate: dueDate ? dueDate.toDate() : null, completedDate: null, createdDate: new Date(), lastUpdated: new Date(), reporter: '-', phase: '-', subTasks: [], }) ); } } setTaskName(''); }; const handleClose = () => { dispatch(setTaskCardDisabled({ status, position, disabled: true })); }; return (
{/* Input field */}
0 ? 1 : 0 }}> {/* Character Length */}
{characterLength}/100
{/* DatePicker and Avatars */}
formatDate(value)} />
{/* {member.charAt(0)} */}
{/* Add Task Button and Cancel Button*/}
); }); export default TaskCreateCard;