calendar 21
This commit is contained in:
parent
68292d9076
commit
7bd520de34
@ -619,6 +619,11 @@ export function CalendarClient({ initialCalendars, userId, userProfile }: Calend
|
|||||||
|
|
||||||
const handleEventSubmit = async () => {
|
const handleEventSubmit = async () => {
|
||||||
try {
|
try {
|
||||||
|
if (!eventForm.title || !eventForm.start || !eventForm.end || !selectedCalendarId) {
|
||||||
|
setError("Veuillez remplir tous les champs obligatoires");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
setLoading(true);
|
setLoading(true);
|
||||||
const eventData = {
|
const eventData = {
|
||||||
...eventForm,
|
...eventForm,
|
||||||
@ -645,10 +650,7 @@ export function CalendarClient({ initialCalendars, userId, userProfile }: Calend
|
|||||||
const savedEvent = await response.json();
|
const savedEvent = await response.json();
|
||||||
console.log("Event saved successfully:", savedEvent);
|
console.log("Event saved successfully:", savedEvent);
|
||||||
|
|
||||||
// Refresh calendars and update the view
|
// Reset form and close modal first
|
||||||
await fetchCalendars();
|
|
||||||
|
|
||||||
// Reset form and close modal
|
|
||||||
setIsEventModalOpen(false);
|
setIsEventModalOpen(false);
|
||||||
setEventForm({
|
setEventForm({
|
||||||
title: "",
|
title: "",
|
||||||
@ -661,6 +663,9 @@ export function CalendarClient({ initialCalendars, userId, userProfile }: Calend
|
|||||||
});
|
});
|
||||||
setSelectedEvent(null);
|
setSelectedEvent(null);
|
||||||
|
|
||||||
|
// Then refresh the calendar data
|
||||||
|
await fetchCalendars();
|
||||||
|
|
||||||
// Force calendar refresh
|
// Force calendar refresh
|
||||||
if (calendarRef.current) {
|
if (calendarRef.current) {
|
||||||
const calendarApi = calendarRef.current.getApi();
|
const calendarApi = calendarRef.current.getApi();
|
||||||
@ -905,7 +910,22 @@ export function CalendarClient({ initialCalendars, userId, userProfile }: Calend
|
|||||||
/>
|
/>
|
||||||
|
|
||||||
{/* Event dialog */}
|
{/* Event dialog */}
|
||||||
<Dialog open={isEventModalOpen} onOpenChange={(open) => !open && setIsEventModalOpen(false)}>
|
<Dialog open={isEventModalOpen} onOpenChange={(open) => {
|
||||||
|
if (!open) {
|
||||||
|
setIsEventModalOpen(false);
|
||||||
|
setEventForm({
|
||||||
|
title: "",
|
||||||
|
description: null,
|
||||||
|
start: "",
|
||||||
|
end: "",
|
||||||
|
allDay: false,
|
||||||
|
location: null,
|
||||||
|
calendarId: selectedCalendarId
|
||||||
|
});
|
||||||
|
setSelectedEvent(null);
|
||||||
|
setError(null);
|
||||||
|
}
|
||||||
|
}}>
|
||||||
<DialogContent className="sm:max-w-lg">
|
<DialogContent className="sm:max-w-lg">
|
||||||
<DialogHeader>
|
<DialogHeader>
|
||||||
<DialogTitle>
|
<DialogTitle>
|
||||||
@ -913,6 +933,12 @@ export function CalendarClient({ initialCalendars, userId, userProfile }: Calend
|
|||||||
</DialogTitle>
|
</DialogTitle>
|
||||||
</DialogHeader>
|
</DialogHeader>
|
||||||
|
|
||||||
|
{error && (
|
||||||
|
<div className="bg-red-50 border border-red-200 text-red-600 px-4 py-2 rounded-md text-sm">
|
||||||
|
{error}
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
|
||||||
<div className="space-y-4 py-4">
|
<div className="space-y-4 py-4">
|
||||||
<div className="space-y-2">
|
<div className="space-y-2">
|
||||||
<Label>Titre</Label>
|
<Label>Titre</Label>
|
||||||
@ -927,17 +953,26 @@ export function CalendarClient({ initialCalendars, userId, userProfile }: Calend
|
|||||||
|
|
||||||
<div className="space-y-2">
|
<div className="space-y-2">
|
||||||
<Label>Calendrier</Label>
|
<Label>Calendrier</Label>
|
||||||
<select
|
<div className="flex flex-wrap gap-2">
|
||||||
value={selectedCalendarId}
|
|
||||||
onChange={(e) => setSelectedCalendarId(e.target.value)}
|
|
||||||
className="w-full rounded-md border border-gray-300 px-3 py-2 text-sm focus:outline-none focus:ring-2 focus:ring-primary"
|
|
||||||
>
|
|
||||||
{calendars.map((cal) => (
|
{calendars.map((cal) => (
|
||||||
<option key={cal.id} value={cal.id}>
|
<button
|
||||||
{cal.name}
|
key={cal.id}
|
||||||
</option>
|
type="button"
|
||||||
|
onClick={() => setSelectedCalendarId(cal.id)}
|
||||||
|
className={`flex items-center gap-2 px-3 py-2 rounded-md border transition-all ${
|
||||||
|
cal.id === selectedCalendarId
|
||||||
|
? 'border-primary bg-primary/5'
|
||||||
|
: 'border-gray-200 hover:border-gray-300'
|
||||||
|
}`}
|
||||||
|
>
|
||||||
|
<div
|
||||||
|
className="w-3 h-3 rounded-full"
|
||||||
|
style={{ backgroundColor: cal.color }}
|
||||||
|
/>
|
||||||
|
<span className="text-sm font-medium">{cal.name}</span>
|
||||||
|
</button>
|
||||||
))}
|
))}
|
||||||
</select>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div className="grid grid-cols-2 gap-4">
|
<div className="grid grid-cols-2 gap-4">
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user