/** * Example: Task Row Component using Centralized Ant Design Imports * * This file demonstrates how to migrate from direct antd imports to the centralized import system. * * BEFORE (Direct imports): * import { Input, Typography, DatePicker } from 'antd'; * import type { InputRef } from 'antd'; * * AFTER (Centralized imports): * import { Input, Typography, DatePicker, type InputRef, dayjs, taskManagementAntdConfig } from './antd-imports'; */ import React, { useState, useCallback, useMemo } from 'react'; import { Input, Typography, DatePicker, Button, Select, Tooltip, Badge, Space, Checkbox, UserOutlined, CalendarOutlined, ClockCircleOutlined, EditOutlined, MoreOutlined, dayjs, taskManagementAntdConfig, taskMessage, type InputRef, type DatePickerProps, type Dayjs } from './antd-imports'; // Your existing task type import import { Task } from '@/types/task-management.types'; interface TaskRowExampleProps { task: Task; projectId: string; isDarkMode?: boolean; onTaskUpdate?: (taskId: string, updates: Partial) => void; } const TaskRowExample: React.FC = ({ task, projectId, isDarkMode = false, onTaskUpdate }) => { const [isEditing, setIsEditing] = useState(false); const [editingField, setEditingField] = useState(null); // Use centralized config for consistent DatePicker props const datePickerProps = useMemo(() => ({ ...taskManagementAntdConfig.datePickerDefaults, className: "w-full bg-transparent border-none shadow-none" }), []); // Use centralized config for consistent Button props const buttonProps = useMemo(() => ({ ...taskManagementAntdConfig.taskButtonDefaults, icon: }), []); // Handle date changes with centralized message system const handleDateChange = useCallback((date: Dayjs | null, field: 'startDate' | 'dueDate') => { if (onTaskUpdate) { onTaskUpdate(task.id, { [field]: date?.toISOString() || null }); taskMessage.success(`${field === 'startDate' ? 'Start' : 'Due'} date updated`); } }, [task.id, onTaskUpdate]); // Handle task title edit const handleTitleEdit = useCallback((newTitle: string) => { if (onTaskUpdate && newTitle.trim() !== task.title) { onTaskUpdate(task.id, { title: newTitle.trim() }); taskMessage.success('Task title updated'); } setIsEditing(false); }, [task.id, task.title, onTaskUpdate]); // Memoized date values for performance const startDateValue = useMemo(() => task.startDate ? dayjs(task.startDate) : undefined, [task.startDate] ); const dueDateValue = useMemo(() => task.dueDate ? dayjs(task.dueDate) : undefined, [task.dueDate] ); return (
{/* Task Selection Checkbox */}
{ // Handle selection logic here console.log('Task selected:', e.target.checked); }} />
{/* Task Title */}
{isEditing ? ( handleTitleEdit(e.currentTarget.value)} onBlur={(e) => handleTitleEdit(e.currentTarget.value)} /> ) : ( setIsEditing(true)} > {task.title}
{/* Task Progress */}
{/* Task Assignees */}
{task.assignee_names?.join(', ') || 'Unassigned'}
{/* Start Date */}
handleDateChange(date, 'startDate')} placeholder="Start Date" />
{/* Due Date */}
handleDateChange(date, 'dueDate')} placeholder="Due Date" disabledDate={(current) => startDateValue ? current.isBefore(startDateValue, 'day') : false } />
{/* Task Status */}
{ if (onTaskUpdate) { onTaskUpdate(task.id, { priority: value }); taskMessage.success('Priority updated'); } }} options={[ { label: 'Low', value: 'low' }, { label: 'Medium', value: 'medium' }, { label: 'High', value: 'high' }, { label: 'Critical', value: 'critical' }, ]} />
{/* Time Tracking */}
{task.timeTracking?.logged ? `${task.timeTracking.logged}h` : '0h'}
{/* Actions */}
); }; export default TaskRowExample; /** * Migration Guide: * * 1. Replace direct antd imports with centralized imports: * - Change: import { DatePicker } from 'antd'; * - To: import { DatePicker } from './antd-imports'; * * 2. Use centralized configurations: * - Apply taskManagementAntdConfig.datePickerDefaults to all DatePickers * - Use taskMessage instead of direct message calls * - Apply consistent styling with taskManagementTheme * * 3. Benefits: * - Better tree-shaking (smaller bundle size) * - Consistent component props across all task management components * - Centralized theme management * - Type safety with proper TypeScript types * - Easy maintenance and updates * * 4. Performance optimizations included: * - Memoized date values to prevent unnecessary dayjs parsing * - Centralized configurations to prevent prop recreation * - Optimized message utilities */