import { useState } from 'react'; import { useTranslation } from 'react-i18next'; import { Dialog, DialogContent, DialogHeader, DialogTitle } from '@/components/ui/dialog'; import { Button } from '@/components/ui/button'; import { Input } from '@/components/ui/input'; import { Textarea } from '@/components/ui/textarea'; import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue } from '@/components/ui/select'; import { Calendar } from '@/components/ui/calendar'; import { Popover, PopoverContent, PopoverTrigger } from '@/components/ui/popover'; import { Command, CommandEmpty, CommandGroup, CommandInput, CommandItem, CommandList } from '@/components/ui/command'; import { Badge } from "@/components/ui/badge"; import { cn } from "@/lib/utils"; import { CalendarIcon, Plus, Tag, Check, Link2 } from 'lucide-react'; import { Task, Label } from '@shared/schema'; import { useQuery } from '@tanstack/react-query'; import { parseTaskInput } from '../lib/nlp'; import { Sparkles } from 'lucide-react'; interface TaskCreationModalProps { isOpen: boolean; onClose: () => void; onSave: (task: Partial) => void; } export default function TaskCreationModal({ isOpen, onClose, onSave }: TaskCreationModalProps) { const { t } = useTranslation(); const [title, setTitle] = useState(''); const [description, setDescription] = useState(''); const [priority, setPriority] = useState<'low' | 'medium' | 'high'>('medium'); const [energyLevel, setEnergyLevel] = useState<'low' | 'medium' | 'high'>('medium'); const [estimatedDuration, setEstimatedDuration] = useState(); const [dueDate, setDueDate] = useState(); const [labelId, setLabelId] = useState(); const [dependencies, setDependencies] = useState([]); const [isDependenciesOpen, setIsDependenciesOpen] = useState(false); const [isCalendarOpen, setIsCalendarOpen] = useState(false); const [error, setError] = useState(null); // Fetch labels const { data: labels = [] } = useQuery({ queryKey: ['/api/labels'], }); const { data: tasks = [] } = useQuery({ queryKey: ['/api/tasks'], }); const handleSave = () => { if (!title.trim()) { setError(t('taskCreation.titleRequired') || 'Title is required'); return; } const newTask: Partial = { title: title.trim(), description: description.trim() || undefined, priority, energyLevel, estimatedDuration, dueDate, labelId, dependencies, status: 'todo', timeTracked: 0, isTracking: false }; onSave(newTask); console.log('New task created:', newTask); // Reset form setTitle(''); setDescription(''); setPriority('medium'); setDueDate(undefined); setDueDate(undefined); setLabelId(undefined); setDependencies([]); setError(null); onClose(); }; const handleKeyDown = (e: React.KeyboardEvent) => { if (e.key === 'Enter' && !e.shiftKey) { e.preventDefault(); handleSave(); } }; const handleClose = () => { setTitle(''); setDescription(''); setPriority('medium'); setDueDate(undefined); setDueDate(undefined); setLabelId(undefined); setDependencies([]); setError(null); onClose(); }; return ( {t('taskCreation.title')}
{ setTitle(e.target.value); const parsed = parseTaskInput(e.target.value); if (parsed.priority) setPriority(parsed.priority); if (parsed.dueDate) setDueDate(parsed.dueDate); if (parsed.labelName) { const foundLabel = labels.find(l => l.name.toLowerCase() === parsed.labelName?.toLowerCase()); if (foundLabel) setLabelId(foundLabel.id); } if (error) setError(null); }} onKeyDown={handleKeyDown} className="text-base" data-testid="input-task-title" autoFocus />
{title.includes('!') || title.includes('#') || title.toLowerCase().includes('tomorrow') || title.toLowerCase().includes('morgen') || title.toLowerCase().includes('today') || title.toLowerCase().includes('heute') ? (
{t('taskCreation.smartInputActive')}
) : null} {error &&

{error}

}