feat(events): default duration when saving without timer — per-type fallback (15m feed, 45m nap, 8h sleep, etc.)
This commit is contained in:
@@ -316,6 +316,14 @@ export function EventModal({ type, babyId, onClose, onSaved, initialEvent }: Pro
|
|||||||
if (photoUrl) metadata.photo = photoUrl;
|
if (photoUrl) metadata.photo = photoUrl;
|
||||||
|
|
||||||
const toUTC = (local: string) => local ? new Date(local).toISOString() : null;
|
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);
|
localStorage.removeItem(TIMER_KEY);
|
||||||
|
|
||||||
if (isEditing) {
|
if (isEditing) {
|
||||||
@@ -324,7 +332,7 @@ export function EventModal({ type, babyId, onClose, onSaved, initialEvent }: Pro
|
|||||||
headers: { "Content-Type": "application/json" },
|
headers: { "Content-Type": "application/json" },
|
||||||
body: JSON.stringify({
|
body: JSON.stringify({
|
||||||
startedAt: toUTC(form.startedAt),
|
startedAt: toUTC(form.startedAt),
|
||||||
endedAt: form.endedAt ? toUTC(form.endedAt) : null,
|
endedAt: resolvedEndedAt ? toUTC(resolvedEndedAt) : null,
|
||||||
notes: form.notes || null,
|
notes: form.notes || null,
|
||||||
metadata: Object.keys(metadata).length > 0 ? metadata : null,
|
metadata: Object.keys(metadata).length > 0 ? metadata : null,
|
||||||
}),
|
}),
|
||||||
@@ -337,7 +345,7 @@ export function EventModal({ type, babyId, onClose, onSaved, initialEvent }: Pro
|
|||||||
babyId,
|
babyId,
|
||||||
type,
|
type,
|
||||||
startedAt: toUTC(form.startedAt),
|
startedAt: toUTC(form.startedAt),
|
||||||
endedAt: form.endedAt ? toUTC(form.endedAt) : null,
|
endedAt: resolvedEndedAt ? toUTC(resolvedEndedAt) : null,
|
||||||
notes: form.notes || null,
|
notes: form.notes || null,
|
||||||
metadata: Object.keys(metadata).length > 0 ? metadata : null,
|
metadata: Object.keys(metadata).length > 0 ? metadata : null,
|
||||||
}),
|
}),
|
||||||
|
|||||||
@@ -24,6 +24,7 @@ export const EVENT_CONFIG: Record<
|
|||||||
borderClass: string; // tailwind border
|
borderClass: string; // tailwind border
|
||||||
hasDuration: boolean;
|
hasDuration: boolean;
|
||||||
hasTimer: boolean;
|
hasTimer: boolean;
|
||||||
|
defaultDurationMin?: number;
|
||||||
}
|
}
|
||||||
> = {
|
> = {
|
||||||
BREASTFEED: {
|
BREASTFEED: {
|
||||||
@@ -35,6 +36,7 @@ export const EVENT_CONFIG: Record<
|
|||||||
borderClass: "border-rose-200",
|
borderClass: "border-rose-200",
|
||||||
hasDuration: true,
|
hasDuration: true,
|
||||||
hasTimer: true,
|
hasTimer: true,
|
||||||
|
defaultDurationMin: 15,
|
||||||
},
|
},
|
||||||
BOTTLE: {
|
BOTTLE: {
|
||||||
label: "Biberon",
|
label: "Biberon",
|
||||||
@@ -55,6 +57,7 @@ export const EVENT_CONFIG: Record<
|
|||||||
borderClass: "border-cyan-200",
|
borderClass: "border-cyan-200",
|
||||||
hasDuration: true,
|
hasDuration: true,
|
||||||
hasTimer: true,
|
hasTimer: true,
|
||||||
|
defaultDurationMin: 15,
|
||||||
},
|
},
|
||||||
DIAPER_WET: {
|
DIAPER_WET: {
|
||||||
label: "Couche mouillée",
|
label: "Couche mouillée",
|
||||||
@@ -85,6 +88,7 @@ export const EVENT_CONFIG: Record<
|
|||||||
borderClass: "border-violet-200",
|
borderClass: "border-violet-200",
|
||||||
hasDuration: true,
|
hasDuration: true,
|
||||||
hasTimer: true,
|
hasTimer: true,
|
||||||
|
defaultDurationMin: 45,
|
||||||
},
|
},
|
||||||
NIGHT_SLEEP: {
|
NIGHT_SLEEP: {
|
||||||
label: "Sommeil nocturne",
|
label: "Sommeil nocturne",
|
||||||
@@ -95,6 +99,7 @@ export const EVENT_CONFIG: Record<
|
|||||||
borderClass: "border-indigo-200",
|
borderClass: "border-indigo-200",
|
||||||
hasDuration: true,
|
hasDuration: true,
|
||||||
hasTimer: true,
|
hasTimer: true,
|
||||||
|
defaultDurationMin: 480,
|
||||||
},
|
},
|
||||||
MEDICATION: {
|
MEDICATION: {
|
||||||
label: "Traitement",
|
label: "Traitement",
|
||||||
@@ -125,6 +130,7 @@ export const EVENT_CONFIG: Record<
|
|||||||
borderClass: "border-sky-200",
|
borderClass: "border-sky-200",
|
||||||
hasDuration: true,
|
hasDuration: true,
|
||||||
hasTimer: true,
|
hasTimer: true,
|
||||||
|
defaultDurationMin: 10,
|
||||||
},
|
},
|
||||||
WALK: {
|
WALK: {
|
||||||
label: "Balade",
|
label: "Balade",
|
||||||
@@ -135,6 +141,7 @@ export const EVENT_CONFIG: Record<
|
|||||||
borderClass: "border-lime-200",
|
borderClass: "border-lime-200",
|
||||||
hasDuration: true,
|
hasDuration: true,
|
||||||
hasTimer: true,
|
hasTimer: true,
|
||||||
|
defaultDurationMin: 30,
|
||||||
},
|
},
|
||||||
TUMMY_TIME: {
|
TUMMY_TIME: {
|
||||||
label: "Plat ventre",
|
label: "Plat ventre",
|
||||||
@@ -145,6 +152,7 @@ export const EVENT_CONFIG: Record<
|
|||||||
borderClass: "border-amber-200",
|
borderClass: "border-amber-200",
|
||||||
hasDuration: true,
|
hasDuration: true,
|
||||||
hasTimer: true,
|
hasTimer: true,
|
||||||
|
defaultDurationMin: 5,
|
||||||
},
|
},
|
||||||
SYMPTOM: {
|
SYMPTOM: {
|
||||||
label: "Symptôme",
|
label: "Symptôme",
|
||||||
|
|||||||
Reference in New Issue
Block a user