diff --git a/src/components/event-modal.tsx b/src/components/event-modal.tsx index c87beec..1288815 100644 --- a/src/components/event-modal.tsx +++ b/src/components/event-modal.tsx @@ -316,6 +316,14 @@ export function EventModal({ type, babyId, onClose, onSaved, initialEvent }: Pro if (photoUrl) metadata.photo = photoUrl; const toUTC = (local: string) => local ? new Date(local).toISOString() : null; + + // Default duration when hasDuration but endedAt not filled + let resolvedEndedAt = form.endedAt; + if (config.hasDuration && !resolvedEndedAt && config.defaultDurationMin) { + const start = new Date(form.startedAt); + resolvedEndedAt = new Date(start.getTime() + config.defaultDurationMin * 60000).toISOString().slice(0, 16); + } + localStorage.removeItem(TIMER_KEY); if (isEditing) { @@ -324,7 +332,7 @@ export function EventModal({ type, babyId, onClose, onSaved, initialEvent }: Pro headers: { "Content-Type": "application/json" }, body: JSON.stringify({ startedAt: toUTC(form.startedAt), - endedAt: form.endedAt ? toUTC(form.endedAt) : null, + endedAt: resolvedEndedAt ? toUTC(resolvedEndedAt) : null, notes: form.notes || null, metadata: Object.keys(metadata).length > 0 ? metadata : null, }), @@ -337,7 +345,7 @@ export function EventModal({ type, babyId, onClose, onSaved, initialEvent }: Pro babyId, type, startedAt: toUTC(form.startedAt), - endedAt: form.endedAt ? toUTC(form.endedAt) : null, + endedAt: resolvedEndedAt ? toUTC(resolvedEndedAt) : null, notes: form.notes || null, metadata: Object.keys(metadata).length > 0 ? metadata : null, }), diff --git a/src/lib/event-config.ts b/src/lib/event-config.ts index 6b27134..c79b4f6 100644 --- a/src/lib/event-config.ts +++ b/src/lib/event-config.ts @@ -24,6 +24,7 @@ export const EVENT_CONFIG: Record< borderClass: string; // tailwind border hasDuration: boolean; hasTimer: boolean; + defaultDurationMin?: number; } > = { BREASTFEED: { @@ -35,6 +36,7 @@ export const EVENT_CONFIG: Record< borderClass: "border-rose-200", hasDuration: true, hasTimer: true, + defaultDurationMin: 15, }, BOTTLE: { label: "Biberon", @@ -55,6 +57,7 @@ export const EVENT_CONFIG: Record< borderClass: "border-cyan-200", hasDuration: true, hasTimer: true, + defaultDurationMin: 15, }, DIAPER_WET: { label: "Couche mouillée", @@ -85,6 +88,7 @@ export const EVENT_CONFIG: Record< borderClass: "border-violet-200", hasDuration: true, hasTimer: true, + defaultDurationMin: 45, }, NIGHT_SLEEP: { label: "Sommeil nocturne", @@ -95,6 +99,7 @@ export const EVENT_CONFIG: Record< borderClass: "border-indigo-200", hasDuration: true, hasTimer: true, + defaultDurationMin: 480, }, MEDICATION: { label: "Traitement", @@ -125,6 +130,7 @@ export const EVENT_CONFIG: Record< borderClass: "border-sky-200", hasDuration: true, hasTimer: true, + defaultDurationMin: 10, }, WALK: { label: "Balade", @@ -135,6 +141,7 @@ export const EVENT_CONFIG: Record< borderClass: "border-lime-200", hasDuration: true, hasTimer: true, + defaultDurationMin: 30, }, TUMMY_TIME: { label: "Plat ventre", @@ -145,6 +152,7 @@ export const EVENT_CONFIG: Record< borderClass: "border-amber-200", hasDuration: true, hasTimer: true, + defaultDurationMin: 5, }, SYMPTOM: { label: "Symptôme",