diff --git a/src/app/(app)/dashboard/page.tsx b/src/app/(app)/dashboard/page.tsx index c7b367e..783777a 100644 --- a/src/app/(app)/dashboard/page.tsx +++ b/src/app/(app)/dashboard/page.tsx @@ -510,9 +510,9 @@ export default function DashboardPage() { useEffect(() => { const lastFeed = events.find((e) => e.type === "BREASTFEED" || e.type === "BOTTLE"); - checkFeedAlert(lastFeed ? new Date(lastFeed.startedAt) : null, getThresholds()); + checkFeedAlert(lastFeed ? new Date(lastFeed.startedAt) : null, getThresholds(), baby?.name); const id = setInterval(() => { - checkFeedAlert(lastFeed ? new Date(lastFeed.startedAt) : null, getThresholds()); + checkFeedAlert(lastFeed ? new Date(lastFeed.startedAt) : null, getThresholds(), baby?.name); }, 5 * 60 * 1000); return () => clearInterval(id); }, [events]); diff --git a/src/app/api/cron/milk-expiry/route.ts b/src/app/api/cron/milk-expiry/route.ts index 8001025..0f9659a 100644 --- a/src/app/api/cron/milk-expiry/route.ts +++ b/src/app/api/cron/milk-expiry/route.ts @@ -73,7 +73,7 @@ export async function POST(req: Request) { const message = [`🥛 Stock lait — ${babyName}`, "", ...lines].join("\n"); for (const user of users) { if (user.pushoverUserKey) { - await sendPushover(user.pushoverUserKey, message, `🥛 Alerte stock lait`); + await sendPushover(user.pushoverUserKey, message, `🥛 Lait — ${babyName}`); sent++; } } diff --git a/src/app/api/reminders/check/route.ts b/src/app/api/reminders/check/route.ts index 91f1033..ef9c200 100644 --- a/src/app/api/reminders/check/route.ts +++ b/src/app/api/reminders/check/route.ts @@ -23,7 +23,7 @@ export async function POST() { const message = `Rappel médicament : ${reminder.name}${dosePart} pour ${reminder.baby.name}`; try { - await notifyFamilyFeedAlert(reminder.baby.familyId, message); + await notifyFamilyFeedAlert(reminder.baby.familyId, message, `💊 ${reminder.name} — ${reminder.baby.name}`); await prisma.medicationReminder.update({ where: { id: reminder.id }, data: { lastSentAt: now }, diff --git a/src/lib/notifications.ts b/src/lib/notifications.ts index 1b98a96..4082e89 100644 --- a/src/lib/notifications.ts +++ b/src/lib/notifications.ts @@ -36,15 +36,16 @@ export function sendNotification(title: string, body: string): void { }); } -export function checkFeedAlert(lastFeedAt: Date | null, thresholds: NotificationThresholds): void { +export function checkFeedAlert(lastFeedAt: Date | null, thresholds: NotificationThresholds, babyName?: string): void { if (!thresholds.enabled || !lastFeedAt) return; const hoursSince = (Date.now() - lastFeedAt.getTime()) / 3600000; if (hoursSince >= thresholds.feedAlertHours) { const h = Math.floor(hoursSince); const m = Math.floor((hoursSince - h) * 60); + const who = babyName ? `${babyName} n'a` : "Bébé n'a"; sendNotification( - "🍼 Rappel repas — Grow", - `Dernier repas il y a ${h}h${m.toString().padStart(2, "0")}. Heure de nourrir bébé ?` + `🍼 Rappel repas — ${babyName ?? "Grow"}`, + `${who} pas mangé depuis ${h}h${m.toString().padStart(2, "0")}. Heure de la prochaine tétée ?` ); } } diff --git a/src/lib/push-notify.ts b/src/lib/push-notify.ts index c4ce637..5053e36 100644 --- a/src/lib/push-notify.ts +++ b/src/lib/push-notify.ts @@ -20,12 +20,12 @@ export async function sendPushover(userKey: string, message: string, title = "Gr } } -export async function notifyFamilyFeedAlert(familyId: string, message: string): Promise { +export async function notifyFamilyFeedAlert(familyId: string, message: string, title?: string): Promise { const users = await prisma.user.findMany({ where: { familyId, pushoverUserKey: { not: null } }, select: { pushoverUserKey: true }, }); await Promise.allSettled( - users.map((u) => sendPushover(u.pushoverUserKey!, message)) + users.map((u) => sendPushover(u.pushoverUserKey!, message, title ?? "Grow")) ); }