From c1e02249d6f8511b70f02c049f297e6cc9d4ac86 Mon Sep 17 00:00:00 2001 From: Mannu Date: Sat, 30 May 2026 22:52:05 +0530 Subject: [PATCH] fix: home page vaccine reminder showing "undefined due today" MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Two stacked causes: 1. ROOT CAUSE (home page field mismatch): the DB-backed notifications rewrite (678cf65) changed the API response shape, but the home page banner still read the OLD fields. It checked `notif.status === "overdue"` (no longer returned — now it's `title`) so it always fell to the else branch `${notif.vaccineName} due today`, and `vaccineName` no longer exists at top level (now in `metadata.vaccineName`) → rendered "undefined due today". Fix: render the complete server-built `message` ("BCG is N days overdue" / "BCG is due today"). Also filter to vaccine_* notifications so the banner can't show a log/memory/garment nudge under a "Vaccine Reminder" header. 2. Stale message data: an earlier generator had stored "undefined …" in the message itself, frozen by ON CONFLICT DO NOTHING. Delete legacy "undefined%" rows and switch vaccine upsert to DO UPDATE so messages (and overdue day-counts) stay correct instead of freezing the first version. is_read / id / created_at preserved. Co-Authored-By: Claude Opus 4.8 --- src/app/(app)/home/page.tsx | 4 +--- src/app/api/notifications/route.ts | 12 +++++++++++- 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/src/app/(app)/home/page.tsx b/src/app/(app)/home/page.tsx index 450d4d8..c189508 100644 --- a/src/app/(app)/home/page.tsx +++ b/src/app/(app)/home/page.tsx @@ -401,9 +401,7 @@ export default function HomePage() {
💊 Vaccine Reminder
- {vaccineReminders[0].status === "overdue" - ? `${vaccineReminders[0].message}` - : `${vaccineReminders[0].vaccineName} due today`} + {vaccineReminders[0].message}
diff --git a/src/app/api/notifications/route.ts b/src/app/api/notifications/route.ts index 607a062..dfb32cf 100644 --- a/src/app/api/notifications/route.ts +++ b/src/app/api/notifications/route.ts @@ -83,6 +83,12 @@ export async function GET(request: NextRequest) { const child = children[0]; const birthDate = new Date(child.birth_date as string); + // Self-heal legacy data: an earlier generator stored "undefined" in the + // message ("undefined is N days overdue"). Those rows were frozen by + // ON CONFLICT DO NOTHING. Delete them so the upsert below regenerates them + // with the correct vaccine name. + await sql`DELETE FROM notifications WHERE family_id = ${familyId} AND message LIKE 'undefined%'`; + // ── 1. Vaccine notifications ────────────────────────────────────────────── const given = await sql` SELECT vaccine_name FROM vaccinations @@ -118,7 +124,11 @@ export async function GET(request: NextRequest) { ${dueDateStr}::date, ${JSON.stringify({ vaccineName: v.name, dueDate: dueDateStr })}::jsonb ) - ON CONFLICT (family_id, child_id, type, scheduled_for) DO NOTHING + ON CONFLICT (family_id, child_id, type, scheduled_for) DO UPDATE SET + title = EXCLUDED.title, + message = EXCLUDED.message, + action_url = EXCLUDED.action_url, + metadata = EXCLUDED.metadata `; }