From d76af98aeccdb4575491152da1399c3aa74462ae Mon Sep 17 00:00:00 2001 From: Alma Date: Sun, 13 Apr 2025 13:52:53 +0200 Subject: [PATCH] calendar 8 --- components/calendar/calendar-client.tsx | 269 +++++++++++++++++++++++- 1 file changed, 265 insertions(+), 4 deletions(-) diff --git a/components/calendar/calendar-client.tsx b/components/calendar/calendar-client.tsx index cad7a3a0..c29215b0 100644 --- a/components/calendar/calendar-client.tsx +++ b/components/calendar/calendar-client.tsx @@ -1,6 +1,6 @@ "use client"; -import { useState, useRef } from "react"; +import { useState, useRef, useEffect } from "react"; import FullCalendar from "@fullcalendar/react"; import dayGridPlugin from "@fullcalendar/daygrid"; import timeGridPlugin from "@fullcalendar/timegrid"; @@ -9,11 +9,28 @@ import frLocale from "@fullcalendar/core/locales/fr"; import { Card } from "@/components/ui/card"; import { Button } from "@/components/ui/button"; import { Tabs, TabsContent, TabsList, TabsTrigger } from "@/components/ui/tabs"; -import { Loader2, Plus } from "lucide-react"; +import { Loader2, Plus, Calendar as CalendarIcon, Check, X } from "lucide-react"; import { Calendar, Event } from "@prisma/client"; import { Dialog, DialogContent, DialogHeader, DialogTitle, DialogFooter } from "@/components/ui/dialog"; import { Input } from "@/components/ui/input"; import { Textarea } from "@/components/ui/textarea"; +import { Label } from "@/components/ui/label"; + +// Predefined professional color palette +const colorPalette = [ + "#4f46e5", // Indigo + "#0891b2", // Cyan + "#0e7490", // Teal + "#16a34a", // Green + "#65a30d", // Lime + "#ca8a04", // Amber + "#d97706", // Orange + "#dc2626", // Red + "#e11d48", // Rose + "#9333ea", // Purple + "#7c3aed", // Violet + "#2563eb", // Blue +]; interface CalendarClientProps { initialCalendars: (Calendar & { events: Event[] })[]; @@ -30,6 +47,192 @@ interface EventFormData { calendarId?: string; } +interface CalendarDialogProps { + open: boolean; + onClose: () => void; + onSave: (calendarData: Partial) => Promise; + initialData?: Partial; +} + +function CalendarDialog({ open, onClose, onSave, initialData }: CalendarDialogProps) { + const [name, setName] = useState(initialData?.name || ""); + const [color, setColor] = useState(initialData?.color || "#4f46e5"); + const [description, setDescription] = useState(initialData?.description || ""); + const [isSubmitting, setIsSubmitting] = useState(false); + const [customColorMode, setCustomColorMode] = useState(false); + + useEffect(() => { + if (open) { + setName(initialData?.name || ""); + setColor(initialData?.color || "#4f46e5"); + setDescription(initialData?.description || ""); + setCustomColorMode(!colorPalette.includes(initialData?.color || "#4f46e5")); + } + }, [open, initialData]); + + const handleSubmit = async (e: React.FormEvent) => { + e.preventDefault(); + setIsSubmitting(true); + + try { + await onSave({ + id: initialData?.id, + name, + color, + description + }); + resetForm(); + } catch (error) { + console.error("Erreur lors de la création du calendrier:", error); + } finally { + setIsSubmitting(false); + } + }; + + const resetForm = () => { + setName(""); + setColor("#4f46e5"); + setDescription(""); + setCustomColorMode(false); + onClose(); + }; + + return ( + !open && onClose()}> + + + + + {initialData?.id ? "Modifier le calendrier" : "Créer un nouveau calendrier"} + + + +
+
+
+ + setName(e.target.value)} + placeholder="Nom du calendrier" + required + className="rounded-lg border-gray-300 focus:border-indigo-500 focus:ring-indigo-500" + /> +
+ +
+ + +
+ {colorPalette.map((paletteColor) => ( + + ))} + + +
+ + {customColorMode && ( +
+
+ setColor(e.target.value)} + className="w-10 h-10 p-1 cursor-pointer rounded border-gray-300" + /> + setColor(e.target.value)} + placeholder="#RRGGBB" + className="w-28 rounded-lg" + /> +
+
+
+ )} +
+ +
+ +