calendar 18
This commit is contained in:
parent
eb4d14379d
commit
b456778234
@ -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);
|
||||
|
||||
@ -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({
|
||||
|
||||
Loading…
Reference in New Issue
Block a user