feat(events): default duration when saving without timer — per-type fallback (15m feed, 45m nap, 8h sleep, etc.)

This commit is contained in:
2026-06-15 20:04:32 +02:00
parent 4a50d125c6
commit 716a85db84
2 changed files with 18 additions and 2 deletions
+10 -2
View File
@@ -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,
}),
+8
View File
@@ -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",