|
| 1 | +import { DashboardLayout } from "@/components/layout/dashboard-layout" |
| 2 | +import { Card, CardContent, CardHeader, CardTitle } from "@/components/ui/card" |
| 3 | +import { Button } from "@/components/ui/button" |
| 4 | +import { Badge } from "@/components/ui/badge" |
| 5 | +import { ChevronLeft, ChevronRight, Plus } from "lucide-react" |
| 6 | + |
| 7 | +// Helper function to generate calendar days |
| 8 | +const generateCalendarDays = () => { |
| 9 | + const days = [] |
| 10 | + const today = new Date() |
| 11 | + const currentMonth = today.getMonth() |
| 12 | + const currentYear = today.getFullYear() |
| 13 | + |
| 14 | + // Get the first day of the month |
| 15 | + const firstDay = new Date(currentYear, currentMonth, 1) |
| 16 | + const startingDay = firstDay.getDay() // 0 = Sunday, 1 = Monday, etc. |
| 17 | + |
| 18 | + // Get the number of days in the month |
| 19 | + const lastDay = new Date(currentYear, currentMonth + 1, 0) |
| 20 | + const totalDays = lastDay.getDate() |
| 21 | + |
| 22 | + // Add empty cells for days before the first day of the month |
| 23 | + for (let i = 0; i < startingDay; i++) { |
| 24 | + days.push({ day: "", isCurrentMonth: false }) |
| 25 | + } |
| 26 | + |
| 27 | + // Add days of the current month |
| 28 | + for (let i = 1; i <= totalDays; i++) { |
| 29 | + days.push({ |
| 30 | + day: i, |
| 31 | + isCurrentMonth: true, |
| 32 | + isToday: i === today.getDate(), |
| 33 | + hasEvents: [5, 12, 15, 20, 25].includes(i), // Sample days with events |
| 34 | + }) |
| 35 | + } |
| 36 | + |
| 37 | + // Add empty cells to complete the last week if needed |
| 38 | + const remainingCells = 42 - days.length // 6 rows of 7 days |
| 39 | + for (let i = 0; i < remainingCells; i++) { |
| 40 | + days.push({ day: "", isCurrentMonth: false }) |
| 41 | + } |
| 42 | + |
| 43 | + return days |
| 44 | +} |
| 45 | + |
| 46 | +const events = [ |
| 47 | + { |
| 48 | + id: 1, |
| 49 | + title: "Team Meeting", |
| 50 | + time: "10:00 AM - 11:30 AM", |
| 51 | + type: "meeting", |
| 52 | + color: "bg-blue-500/20 text-blue-500", |
| 53 | + }, |
| 54 | + { |
| 55 | + id: 2, |
| 56 | + title: "Project Deadline: Website Redesign", |
| 57 | + time: "5:00 PM", |
| 58 | + type: "deadline", |
| 59 | + color: "bg-red-500/20 text-red-500", |
| 60 | + }, |
| 61 | + { |
| 62 | + id: 3, |
| 63 | + title: "Client Call: ABC Corp", |
| 64 | + time: "2:00 PM - 3:00 PM", |
| 65 | + type: "call", |
| 66 | + color: "bg-green-500/20 text-green-500", |
| 67 | + }, |
| 68 | + { |
| 69 | + id: 4, |
| 70 | + title: "Review Mobile App Wireframes", |
| 71 | + time: "4:00 PM - 5:00 PM", |
| 72 | + type: "task", |
| 73 | + color: "bg-purple-500/20 text-purple-500", |
| 74 | + }, |
| 75 | +] |
| 76 | + |
| 77 | +export default function CalendarPage() { |
| 78 | + const calendarDays = generateCalendarDays() |
| 79 | + const weekdays = ["Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"] |
| 80 | + const currentMonth = new Date().toLocaleString("default", { month: "long", year: "numeric" }) |
| 81 | + |
| 82 | + return ( |
| 83 | + <DashboardLayout> |
| 84 | + <div className="flex justify-between items-center mb-6"> |
| 85 | + <div> |
| 86 | + <h2 className="text-2xl font-bold">Calendar</h2> |
| 87 | + <p className="text-muted-foreground">Manage your schedule and events</p> |
| 88 | + </div> |
| 89 | + <Button className="flex items-center gap-2"> |
| 90 | + <Plus className="h-5 w-5" /> |
| 91 | + New Event |
| 92 | + </Button> |
| 93 | + </div> |
| 94 | + |
| 95 | + <div className="grid grid-cols-1 lg:grid-cols-4 gap-6"> |
| 96 | + <div className="lg:col-span-3"> |
| 97 | + <Card> |
| 98 | + <CardHeader className="flex flex-row items-center justify-between pb-2"> |
| 99 | + <CardTitle>{currentMonth}</CardTitle> |
| 100 | + <div className="flex items-center gap-2"> |
| 101 | + <Button variant="outline" size="icon"> |
| 102 | + <ChevronLeft className="h-4 w-4" /> |
| 103 | + </Button> |
| 104 | + <Button variant="outline" size="icon"> |
| 105 | + <ChevronRight className="h-4 w-4" /> |
| 106 | + </Button> |
| 107 | + </div> |
| 108 | + </CardHeader> |
| 109 | + <CardContent> |
| 110 | + <div className="grid grid-cols-7 gap-1"> |
| 111 | + {weekdays.map((day) => ( |
| 112 | + <div key={day} className="text-center font-medium text-sm py-2"> |
| 113 | + {day} |
| 114 | + </div> |
| 115 | + ))} |
| 116 | + {calendarDays.map((day, index) => ( |
| 117 | + <div |
| 118 | + key={index} |
| 119 | + className={`aspect-square p-2 border ${ |
| 120 | + day.isCurrentMonth ? "bg-card" : "bg-muted/50 text-muted-foreground" |
| 121 | + } ${day.isToday ? "border-primary" : "border-border"} relative`} |
| 122 | + > |
| 123 | + {day.day && ( |
| 124 | + <> |
| 125 | + <span className="text-sm">{day.day}</span> |
| 126 | + {day.hasEvents && ( |
| 127 | + <div className="absolute bottom-1 right-1 h-2 w-2 rounded-full bg-primary"></div> |
| 128 | + )} |
| 129 | + </> |
| 130 | + )} |
| 131 | + </div> |
| 132 | + ))} |
| 133 | + </div> |
| 134 | + </CardContent> |
| 135 | + </Card> |
| 136 | + </div> |
| 137 | + |
| 138 | + <div> |
| 139 | + <Card> |
| 140 | + <CardHeader> |
| 141 | + <CardTitle>Today's Events</CardTitle> |
| 142 | + </CardHeader> |
| 143 | + <CardContent> |
| 144 | + <div className="space-y-4"> |
| 145 | + {events.map((event) => ( |
| 146 | + <div key={event.id} className="border rounded-lg p-3"> |
| 147 | + <h4 className="font-medium">{event.title}</h4> |
| 148 | + <div className="flex items-center justify-between mt-2"> |
| 149 | + <p className="text-sm text-muted-foreground">{event.time}</p> |
| 150 | + <Badge variant="outline" className={event.color}> |
| 151 | + {event.type} |
| 152 | + </Badge> |
| 153 | + </div> |
| 154 | + </div> |
| 155 | + ))} |
| 156 | + </div> |
| 157 | + </CardContent> |
| 158 | + </Card> |
| 159 | + </div> |
| 160 | + </div> |
| 161 | + </DashboardLayout> |
| 162 | + ) |
| 163 | +} |
| 164 | + |
0 commit comments