import { useState } from "react" import { motion, AnimatePresence } from "framer-motion" import { X, ChevronDown, ChevronUp, Calendar, Clock } from "lucide-react" import { useMutation, useQueryClient } from "@tanstack/react-query" import { tasksApi } from "../api/tasks" import clsx from "clsx" import { format, addDays } from "date-fns" const COLORS = [ "#6B7280", "#6366f1", "#8b5cf6", "#d946ef", "#ec4899", "#f43f5e", "#f97316", "#eab308", "#22c55e", "#0ea5e9", ] const ICON_CATEGORIES = [ { name: "Продуктивность", icons: ["📋", "📝", "✅", "📌", "🎯", "💡", "📅", "⏰"] }, { name: "Работа", icons: ["💼", "💻", "📧", "📞", "📊", "📈", "🖥️", "⌨️"] }, { name: "Дом", icons: ["🏠", "🧹", "🧺", "🍳", "🛒", "🔧", "🪴", "🛋️"] }, { name: "Финансы", icons: ["💰", "💳", "📊", "💵", "🏦", "🧾"] }, { name: "Здоровье", icons: ["💊", "🏃", "🧘", "💪", "🩺", "🦷"] }, { name: "Разное", icons: ["⭐", "🎁", "📦", "✈️", "🚗", "📷", "🎉"] }, ] const PRIORITIES = [ { value: 0, label: "Без приоритета", color: "bg-gray-100 text-gray-600" }, { value: 1, label: "Низкий", color: "bg-blue-100 text-blue-700" }, { value: 2, label: "Средний", color: "bg-yellow-100 text-yellow-700" }, { value: 3, label: "Высокий", color: "bg-red-100 text-red-700" }, ] export default function CreateTaskModal({ open, onClose, defaultDueDate = null }) { const today = format(new Date(), "yyyy-MM-dd") const tomorrow = format(addDays(new Date(), 1), "yyyy-MM-dd") const [title, setTitle] = useState("") const [description, setDescription] = useState("") const [color, setColor] = useState(COLORS[0]) const [icon, setIcon] = useState("📋") const [dueDate, setDueDate] = useState(defaultDueDate || today) const [priority, setPriority] = useState(0) const [reminderTime, setReminderTime] = useState("") const [error, setError] = useState("") const [showAllIcons, setShowAllIcons] = useState(false) const queryClient = useQueryClient() const mutation = useMutation({ mutationFn: (data) => tasksApi.create(data), onSuccess: () => { queryClient.invalidateQueries({ queryKey: ["tasks"] }) queryClient.invalidateQueries({ queryKey: ["tasks-today"] }) handleClose() }, onError: (err) => { setError(err.response?.data?.error || "Ошибка создания") }, }) const handleClose = () => { setTitle("") setDescription("") setColor(COLORS[0]) setIcon("📋") setDueDate(defaultDueDate || today) setPriority(0) setReminderTime("") setError("") setShowAllIcons(false) onClose() } const handleSubmit = (e) => { e.preventDefault() if (!title.trim()) { setError("Введи название задачи") return } mutation.mutate({ title, description, color, icon, due_date: dueDate || null, priority, reminder_time: reminderTime || null, }) } const popularIcons = ["📋", "📝", "✅", "🎯", "💼", "🏠", "💰", "📞"] return ( {open && ( <>

Новая задача

{error && (
{error}
)}
setTitle(e.target.value)} className="input" placeholder="Что нужно сделать?" autoFocus />