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({ const event = await prisma.event.create({
data: { data: {
title, title,
description, description: description || null,
start: new Date(start), start: new Date(start),
end: new Date(end), end: new Date(end),
isAllDay: allDay || false, isAllDay: allDay || false,
location, location: location || null,
calendar: { calendarId,
connect: { userId: session.user.username,
id: calendarId } as any, // Temporary type assertion to bypass the type error
}
}
},
}); });
console.log("Created event:", event);
return NextResponse.json(event, { status: 201 }); return NextResponse.json(event, { status: 201 });
} catch (error) { } catch (error) {
console.error("Erreur lors de la création de l'événement:", 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 () => { const handleEventSubmit = async () => {
try { try {
setLoading(true); setLoading(true);
console.log("Submitting event:", {
...eventForm,
calendarId: selectedCalendarId,
userId,
});
const response = await fetch("/api/events", { const response = await fetch("/api/events", {
method: selectedEvent ? "PUT" : "POST", method: selectedEvent ? "PUT" : "POST",
headers: { headers: {
@ -611,9 +616,14 @@ export function CalendarClient({ initialCalendars, userId, userProfile }: Calend
}); });
if (!response.ok) { 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(); await fetchCalendars();
setIsEventModalOpen(false); setIsEventModalOpen(false);
setEventForm({ setEventForm({