diff --git a/web/components/routes/task/TaskForm.tsx b/web/components/routes/task/TaskForm.tsx index ca3cf973..af281da2 100644 --- a/web/components/routes/task/TaskForm.tsx +++ b/web/components/routes/task/TaskForm.tsx @@ -6,8 +6,8 @@ import { Button } from "@/components/ui/button" import { useAccount } from "@/lib/providers/jazz-provider" import { LaIcon } from "@/components/custom/la-icon" import { Checkbox } from "@/components/ui/checkbox" -import { format } from "date-fns" import { DatePicker } from "@/components/ui/date-picker" +import { format, parse } from "date-fns" interface TaskFormProps { filter?: "today" | "upcoming" | undefined @@ -19,9 +19,14 @@ export const TaskForm: React.FC = ({ filter }) => { const [inputVisible, setInputVisible] = useState(false) const { me } = useAccount({ root: {} }) const inputRef = useRef(null) + const formRef = useRef(null) const handleSubmit = (e: React.FormEvent) => { e.preventDefault() + saveTask() + } + + const saveTask = () => { if (title.trim() && (filter !== "upcoming" || dueDate)) { if (me?.root?.tasks === undefined) { if (!me) return @@ -64,6 +69,23 @@ export const TaskForm: React.FC = ({ filter }) => { } }, [inputVisible]) + useEffect(() => { + const handleClickOutside = (event: MouseEvent) => { + if (formRef.current && !formRef.current.contains(event.target as Node)) { + if (title.trim()) { + saveTask() + } else { + resetForm() + } + } + } + + document.addEventListener("mousedown", handleClickOutside) + return () => { + document.removeEventListener("mousedown", handleClickOutside) + } + }, [title, dueDate]) + const formattedDate = dueDate ? format(dueDate, "EEE, MMMM do, yyyy") : "Select a date" return ( @@ -76,7 +98,7 @@ export const TaskForm: React.FC = ({ filter }) => { initial={{ opacity: 0, width: 0 }} animate={{ opacity: 1, width: "auto" }} exit={{ opacity: 0, width: 0 }} - transition={{ duration: 0.3 }} + transition={{ duration: 0.01 }} > ) : ( - -
- {}} /> +
+ {}} className="mr-2" /> = ({ filter }) => { placeholder="Task title" />
-
+ +
e.stopPropagation()}> {filter === "upcoming" && ( - setDueDate(date)} /> + setDueDate(date)} + className="z-50" + /> )} - {formattedDate}
- +
) ) : null} diff --git a/web/components/ui/date-picker.tsx b/web/components/ui/date-picker.tsx index ce802de5..0b4851c2 100644 --- a/web/components/ui/date-picker.tsx +++ b/web/components/ui/date-picker.tsx @@ -17,7 +17,7 @@ export function DatePicker({ date, onDateChange, className }: DatePickerProps) { const selectDate = (selectedDate: Date | undefined) => { onDateChange(selectedDate) - setOpen(false) // Закрываем Popover после выбора даты + setOpen(false) } return ( @@ -26,12 +26,13 @@ export function DatePicker({ date, onDateChange, className }: DatePickerProps) { - + e.stopPropagation()}>