({ tasks })
| 17 | }; |
| 18 | |
| 19 | const ProjectCalendar = ({ tasks }) => { |
| 20 | const [selectedDate, setSelectedDate] = useState(new Date()); |
| 21 | const [currentMonth, setCurrentMonth] = useState(new Date()); |
| 22 | |
| 23 | const today = new Date(); |
| 24 | const getTasksForDate = (date) => tasks.filter((task) => isSameDay(task.due_date, date)); |
| 25 | |
| 26 | const upcomingTasks = tasks |
| 27 | .filter((task) => task.due_date && !isBefore(task.due_date, today) && task.status !== "DONE") |
| 28 | .sort((a, b) => new Date(a.due_date) - new Date(b.due_date)) |
| 29 | .slice(0, 5); |
| 30 | |
| 31 | const overdueTasks = tasks.filter((task) => task.due_date && isBefore(task.due_date, today) && task.status !== "DONE"); |
| 32 | |
| 33 | const daysInMonth = eachDayOfInterval({ |
| 34 | start: startOfMonth(currentMonth), |
| 35 | end: endOfMonth(currentMonth), |
| 36 | }); |
| 37 | |
| 38 | |
| 39 | const handleMonthChange = (direction) => { |
| 40 | setCurrentMonth((prev) => (direction === "next" ? addMonths(prev, 1) : subMonths(prev, 1))); |
| 41 | }; |
| 42 | |
| 43 | return ( |
| 44 | <div className="grid lg:grid-cols-3 gap-6"> |
| 45 | {/* Calendar View */} |
| 46 | <div className="lg:col-span-2 "> |
| 47 | <div className="not-dark:bg-white dark:bg-gradient-to-br dark:from-zinc-800/70 dark:to-zinc-900/50 border border-zinc-300 dark:border-zinc-800 rounded-lg p-4"> |
| 48 | <div className="flex items-center justify-between mb-4"> |
| 49 | <h2 className="text-zinc-900 dark:text-white text-md flex gap-2 items-center max-sm:hidden"> |
| 50 | <CalendarIcon className="size-5" /> Task Calendar |
| 51 | </h2> |
| 52 | <div className="flex gap-2 items-center"> |
| 53 | <button onClick={() => handleMonthChange("prev")}> |
| 54 | <ChevronLeft className="size-5 text-zinc-600 dark:text-zinc-400 hover:text-zinc-900 dark:hover:text-white" /> |
| 55 | </button> |
| 56 | <span className="text-zinc-900 dark:text-white">{format(currentMonth, "MMMM yyyy")}</span> |
| 57 | <button onClick={() => handleMonthChange("next")}> |
| 58 | <ChevronRight className="size-5 text-zinc-600 dark:text-zinc-400 hover:text-zinc-900 dark:hover:text-white" /> |
| 59 | </button> |
| 60 | </div> |
| 61 | </div> |
| 62 | |
| 63 | <div className="grid grid-cols-7 text-xs text-zinc-600 dark:text-zinc-400 mb-2 text-center"> |
| 64 | {["Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"].map((day) => ( |
| 65 | <div key={day}>{day}</div> |
| 66 | ))} |
| 67 | </div> |
| 68 | |
| 69 | <div className="grid grid-cols-7 gap-2"> |
| 70 | {daysInMonth.map((day) => { |
| 71 | const dayTasks = getTasksForDate(day); |
| 72 | const isSelected = isSameDay(day, selectedDate); |
| 73 | const hasOverdue = dayTasks.some((t) => t.status !== "DONE" && isBefore(t.due_date, today)); |
| 74 | |
| 75 | return ( |
| 76 | <button |
nothing calls this directly
no test coverage detected