calendar 37
This commit is contained in:
parent
5eff93a394
commit
1c0c494852
@ -743,35 +743,23 @@ export function CalendarClient({ initialCalendars, userId, userProfile }: Calend
|
||||
|
||||
const handleEventSubmit = async () => {
|
||||
try {
|
||||
// Log the current state before validation
|
||||
console.log("Current state before submission:", {
|
||||
selectedCalendarId,
|
||||
eventForm,
|
||||
calendars
|
||||
});
|
||||
|
||||
if (!eventForm.title || !eventForm.start || !eventForm.end || !selectedCalendarId) {
|
||||
// Validate required fields including calendar
|
||||
if (!eventForm.title || !eventForm.start || !eventForm.end || !eventForm.calendarId) {
|
||||
console.log("Form validation failed:", {
|
||||
title: eventForm.title,
|
||||
start: eventForm.start,
|
||||
end: eventForm.end,
|
||||
selectedCalendarId,
|
||||
calendars: calendars.map(c => ({ id: c.id, name: c.name }))
|
||||
calendarId: eventForm.calendarId
|
||||
});
|
||||
setError("Veuillez remplir tous les champs obligatoires");
|
||||
setError("Veuillez remplir tous les champs obligatoires et sélectionner un calendrier");
|
||||
return;
|
||||
}
|
||||
|
||||
setLoading(true);
|
||||
// Ensure we're using the selected calendar ID
|
||||
const eventData = {
|
||||
title: eventForm.title,
|
||||
description: eventForm.description,
|
||||
...eventForm,
|
||||
start: new Date(eventForm.start).toISOString(),
|
||||
end: new Date(eventForm.end).toISOString(),
|
||||
allDay: eventForm.allDay,
|
||||
location: eventForm.location,
|
||||
calendarId: selectedCalendarId,
|
||||
userId
|
||||
};
|
||||
|
||||
@ -987,6 +975,15 @@ export function CalendarClient({ initialCalendars, userId, userProfile }: Calend
|
||||
}
|
||||
};
|
||||
|
||||
// Update the date handlers to maintain consistent time format
|
||||
const formatTimeForInput = (date: Date) => {
|
||||
return date.toLocaleTimeString('fr-FR', {
|
||||
hour: '2-digit',
|
||||
minute: '2-digit',
|
||||
hour12: false
|
||||
});
|
||||
};
|
||||
|
||||
return (
|
||||
<div className="space-y-4">
|
||||
<Card className="p-4">
|
||||
@ -1196,7 +1193,7 @@ export function CalendarClient({ initialCalendars, userId, userProfile }: Calend
|
||||
end: "",
|
||||
allDay: false,
|
||||
location: null,
|
||||
calendarId: selectedCalendarId
|
||||
calendarId: selectedCalendarId || calendars[0]?.id
|
||||
});
|
||||
setSelectedEvent(null);
|
||||
setError(null);
|
||||
@ -1234,9 +1231,15 @@ export function CalendarClient({ initialCalendars, userId, userProfile }: Calend
|
||||
<button
|
||||
key={cal.id}
|
||||
type="button"
|
||||
onClick={() => setSelectedCalendarId(cal.id)}
|
||||
onClick={() => {
|
||||
console.log('Selecting calendar:', cal.id);
|
||||
setEventForm(prev => ({
|
||||
...prev,
|
||||
calendarId: cal.id
|
||||
}));
|
||||
}}
|
||||
className={`flex items-center gap-2 px-3 py-2 rounded-md border transition-all ${
|
||||
cal.id === selectedCalendarId
|
||||
eventForm.calendarId === cal.id
|
||||
? 'border-primary bg-primary/5'
|
||||
: 'border-gray-200 hover:border-gray-300'
|
||||
}`}
|
||||
@ -1268,7 +1271,7 @@ export function CalendarClient({ initialCalendars, userId, userProfile }: Calend
|
||||
</div>
|
||||
<Input
|
||||
type="time"
|
||||
value={eventForm.start ? new Date(eventForm.start).toLocaleTimeString('fr-FR', { hour: '2-digit', minute: '2-digit' }) : ''}
|
||||
value={eventForm.start ? formatTimeForInput(new Date(eventForm.start)) : ''}
|
||||
onChange={(e) => {
|
||||
const [hours, minutes] = e.target.value.split(':');
|
||||
const date = getDateFromString(eventForm.start);
|
||||
@ -1297,7 +1300,7 @@ export function CalendarClient({ initialCalendars, userId, userProfile }: Calend
|
||||
</div>
|
||||
<Input
|
||||
type="time"
|
||||
value={eventForm.end ? new Date(eventForm.end).toLocaleTimeString('fr-FR', { hour: '2-digit', minute: '2-digit' }) : ''}
|
||||
value={eventForm.end ? formatTimeForInput(new Date(eventForm.end)) : ''}
|
||||
onChange={(e) => {
|
||||
const [hours, minutes] = e.target.value.split(':');
|
||||
const date = getDateFromString(eventForm.end);
|
||||
|
||||
Loading…
Reference in New Issue
Block a user