fix(notifications): include baby name in all push/browser notification titles and bodies

This commit is contained in:
2026-06-15 20:08:15 +02:00
parent 716a85db84
commit f7ab467385
5 changed files with 10 additions and 9 deletions
+2 -2
View File
@@ -510,9 +510,9 @@ export default function DashboardPage() {
useEffect(() => { useEffect(() => {
const lastFeed = events.find((e) => e.type === "BREASTFEED" || e.type === "BOTTLE"); 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(() => { const id = setInterval(() => {
checkFeedAlert(lastFeed ? new Date(lastFeed.startedAt) : null, getThresholds()); checkFeedAlert(lastFeed ? new Date(lastFeed.startedAt) : null, getThresholds(), baby?.name);
}, 5 * 60 * 1000); }, 5 * 60 * 1000);
return () => clearInterval(id); return () => clearInterval(id);
}, [events]); }, [events]);
+1 -1
View File
@@ -73,7 +73,7 @@ export async function POST(req: Request) {
const message = [`🥛 Stock lait — ${babyName}`, "", ...lines].join("\n"); const message = [`🥛 Stock lait — ${babyName}`, "", ...lines].join("\n");
for (const user of users) { for (const user of users) {
if (user.pushoverUserKey) { if (user.pushoverUserKey) {
await sendPushover(user.pushoverUserKey, message, `🥛 Alerte stock lait`); await sendPushover(user.pushoverUserKey, message, `🥛 Lait — ${babyName}`);
sent++; sent++;
} }
} }
+1 -1
View File
@@ -23,7 +23,7 @@ export async function POST() {
const message = `Rappel médicament : ${reminder.name}${dosePart} pour ${reminder.baby.name}`; const message = `Rappel médicament : ${reminder.name}${dosePart} pour ${reminder.baby.name}`;
try { try {
await notifyFamilyFeedAlert(reminder.baby.familyId, message); await notifyFamilyFeedAlert(reminder.baby.familyId, message, `💊 ${reminder.name}${reminder.baby.name}`);
await prisma.medicationReminder.update({ await prisma.medicationReminder.update({
where: { id: reminder.id }, where: { id: reminder.id },
data: { lastSentAt: now }, data: { lastSentAt: now },
+4 -3
View File
@@ -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; if (!thresholds.enabled || !lastFeedAt) return;
const hoursSince = (Date.now() - lastFeedAt.getTime()) / 3600000; const hoursSince = (Date.now() - lastFeedAt.getTime()) / 3600000;
if (hoursSince >= thresholds.feedAlertHours) { if (hoursSince >= thresholds.feedAlertHours) {
const h = Math.floor(hoursSince); const h = Math.floor(hoursSince);
const m = Math.floor((hoursSince - h) * 60); const m = Math.floor((hoursSince - h) * 60);
const who = babyName ? `${babyName} n'a` : "Bébé n'a";
sendNotification( sendNotification(
"🍼 Rappel repas — Grow", `🍼 Rappel repas — ${babyName ?? "Grow"}`,
`Dernier repas il y a ${h}h${m.toString().padStart(2, "0")}. Heure de nourrir bébé ?` `${who} pas mangé depuis ${h}h${m.toString().padStart(2, "0")}. Heure de la prochaine tétée ?`
); );
} }
} }
+2 -2
View File
@@ -20,12 +20,12 @@ export async function sendPushover(userKey: string, message: string, title = "Gr
} }
} }
export async function notifyFamilyFeedAlert(familyId: string, message: string): Promise<void> { export async function notifyFamilyFeedAlert(familyId: string, message: string, title?: string): Promise<void> {
const users = await prisma.user.findMany({ const users = await prisma.user.findMany({
where: { familyId, pushoverUserKey: { not: null } }, where: { familyId, pushoverUserKey: { not: null } },
select: { pushoverUserKey: true }, select: { pushoverUserKey: true },
}); });
await Promise.allSettled( await Promise.allSettled(
users.map((u) => sendPushover(u.pushoverUserKey!, message)) users.map((u) => sendPushover(u.pushoverUserKey!, message, title ?? "Grow"))
); );
} }