diff --git a/TaskTracker.Web/src/components/CreateTaskForm.tsx b/TaskTracker.Web/src/components/CreateTaskForm.tsx new file mode 100644 index 0000000..4c63a16 --- /dev/null +++ b/TaskTracker.Web/src/components/CreateTaskForm.tsx @@ -0,0 +1,125 @@ +import { useRef, useState, useEffect } from 'react' +import { Loader2 } from 'lucide-react' +import { useCreateTask } from '../api/tasks.ts' +import { CATEGORY_COLORS } from '../lib/constants.ts' + +interface CreateTaskFormProps { + onClose: () => void +} + +const categories = Object.keys(CATEGORY_COLORS).filter((k) => k !== 'Unknown') + +export default function CreateTaskForm({ onClose }: CreateTaskFormProps) { + const [title, setTitle] = useState('') + const [description, setDescription] = useState('') + const [category, setCategory] = useState('') + const [estimatedMinutes, setEstimatedMinutes] = useState('') + const titleRef = useRef(null) + const createTask = useCreateTask() + + useEffect(() => { + titleRef.current?.focus() + }, []) + + function handleSubmit() { + const trimmed = title.trim() + if (!trimmed) return + + createTask.mutate( + { + title: trimmed, + description: description.trim() || undefined, + category: category || undefined, + estimatedMinutes: estimatedMinutes ? Number(estimatedMinutes) : undefined, + }, + { onSuccess: () => onClose() } + ) + } + + function handleKeyDown(e: React.KeyboardEvent) { + if (e.key === 'Escape') { + e.preventDefault() + onClose() + } + if (e.key === 'Enter' && (e.target as HTMLElement).tagName !== 'TEXTAREA') { + e.preventDefault() + handleSubmit() + } + } + + const inputClass = + 'w-full rounded-md bg-[#0f1117] text-white text-sm px-3 py-2 border border-white/10 placeholder-[#64748b] focus:outline-none focus:ring-2 focus:ring-indigo-500/60 focus:border-transparent transition-colors' + + return ( +
+ {/* Title */} + setTitle(e.target.value)} + className={inputClass} + /> + + {/* Description */} +