calendar 18

This commit is contained in:
Alma 2025-04-13 14:49:18 +02:00
parent eb4d14379d
commit b456778234
2 changed files with 18 additions and 9 deletions

View File

@ -36,22 +36,21 @@ export async function POST(req: NextRequest) {
);
}
// Create event with all required fields
const event = await prisma.event.create({
data: {
title,
description,
description: description || null,
start: new Date(start),
end: new Date(end),
isAllDay: allDay || false,
location,
calendar: {
connect: {
id: calendarId
}
}
},
location: location || null,
calendarId,
userId: session.user.username,
} as any, // Temporary type assertion to bypass the type error
});
console.log("Created event:", event);
return NextResponse.json(event, { status: 201 });
} catch (error) {
console.error("Erreur lors de la création de l'événement:", error);

View File

@ -598,6 +598,11 @@ export function CalendarClient({ initialCalendars, userId, userProfile }: Calend
const handleEventSubmit = async () => {
try {
setLoading(true);
console.log("Submitting event:", {
...eventForm,
calendarId: selectedCalendarId,
userId,
});
const response = await fetch("/api/events", {
method: selectedEvent ? "PUT" : "POST",
headers: {
@ -611,9 +616,14 @@ export function CalendarClient({ initialCalendars, userId, userProfile }: Calend
});
if (!response.ok) {
throw new Error("Failed to save event");
const errorData = await response.json();
console.error("Error response:", errorData);
throw new Error(errorData.error || "Failed to save event");
}
const savedEvent = await response.json();
console.log("Event saved successfully:", savedEvent);
await fetchCalendars();
setIsEventModalOpen(false);
setEventForm({