import { useCallback, useState } from 'react'; import type { TaskProperties } from '@/api/types'; import { useNetwork } from '@/hooks/use-networks'; import { metaKey } from '@/lib/platform'; import { Input } from '@/components/ui/input'; import { Label } from '@/components/ui/label'; import { Textarea } from '@/components/ui/textarea'; import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue, } from '@/components/ui/select'; import { KeyHint } from '@/components/key-hint'; const UNASSIGNED = 'unassigned'; interface TaskComposeStepProps { networkId: string; onCancel: () => void; onSubmit: (properties: TaskProperties) => void; } /** * Minimal task creation form. Checklist items are added after creation in * the always-editable task view, keeping this step a quick capture. */ export function TaskComposeStep({ networkId, onCancel, onSubmit, }: TaskComposeStepProps) { const network = useNetwork(networkId); const [title, setTitle] = useState(''); const [notes, setNotes] = useState(''); const [assignedTo, setAssignedTo] = useState(UNASSIGNED); const handleSubmit = useCallback(() => { const trimmed = title.trim(); if (!trimmed) return; onSubmit({ title: trimmed, ...(notes.trim() && { notes: notes.trim() }), ...(assignedTo !== UNASSIGNED && { assigned_to: assignedTo }), checklist: [], done: false, }); }, [title, notes, assignedTo, onSubmit]); const handleKeyDown = useCallback( (e: React.KeyboardEvent) => { if (e.key === 'Escape') { e.preventDefault(); onCancel(); } else if (e.key === 'Enter' && (e.metaKey || e.ctrlKey)) { e.preventDefault(); handleSubmit(); } }, [onCancel, handleSubmit], ); return (
setTitle(e.target.value)} placeholder="What needs to get done?" className="border-white/10 bg-white/5 text-white placeholder-white/30 focus-visible:border-white/30 focus-visible:ring-0" />