mirror of
https://github.com/bitbaum/vitareba.git
synced 2026-12-04 17:47:33 +01:00
Phase 1 of a full clinician/patient UI redesign George asked for after we shipped the actor-aware cancellation copy fix (#63) — he judged the wider nav/notification/mobile experience underneath it as poorly designed. This is the shared foundation (nav, header, notifications, mobile, mega menu, footer) that every individual page redesign in later phases will sit on top of. In-app notifications (lib/domain/notifications.ts, app/api/notifications/*, components/shared/NotificationBell.tsx): a companion to the existing email sends, not a replacement — wired alongside sendEmail at 5 trigger sites (new message, every booking lifecycle event, critical-signal + goal-achieved in cron/signals, clinician application decisions, document uploads). One shared bell component in both admin and portal headers, 30s polling reusing the existing MESSAGE_POLL_INTERVAL_MS constant. Kept as an in-repo module, not a published package — no second adopter yet to justify that (same rule-of-three standard that produced threadkit, which vitareba already imports for message read/write/unread — verified before starting, so no messaging-domain work was needed here). Admin nav (lib/config/routes.ts ADMIN_NAV_GROUPS, components/admin/AdminNav.tsx): flat 8-item list replaced with grouped sections mirroring the portal's own Care group, so the same clinician relationship reads the same shape from either side. Fixed the "always-on badge" problem: urgentPatients and pendingApplications were live state counts with no seen-at gate, so a clinician who'd already reviewed everything still saw a nonzero badge forever. Added profiles.patientsSeenAt/applicationsSeenAt (mirroring the existing bookingsSeenAt/goalsSeenAt pattern) and profiles.lastKnownSignalAt (there was no "when did this become urgent" timestamp at all) via one generic mark-seen route instead of a 4th near-identical file. Admin mobile (AdminBottomNav): replaced the fragile horizontal-scrolling pill strip (flagged in its own code comment as tracking <th> order by hand) with a bottom tab bar + "More" sheet, matching the portal's own BottomNav — a clinician who is also a patient (the existing role-switch) shouldn't relearn navigation switching sides. Marketing mega menu (components/sections/Nav.tsx): was CSS :hover-only, no keyboard access, no aria-expanded, unusable on a tablet or hybrid laptop. Now click/focus-driven with proper button semantics, Escape + click-outside (via the new shared useClickOutside hook — also used by the notification bell and UserDropdown, its 3rd use). Extracted NavAuthActions to fix the "future auth-state change needs editing two places" risk the desktop/mobile duplication already had. Marketing footer: was a logo and one copyright line, no links at all — now a real sitemap footer (explore/account columns, address, emergency contacts). EMERGENCY_CONTACTS existed in config but was wired into no authed screen either; added to UserDropdown too. New/changed columns: notifications (new table), profiles.patientsSeenAt, profiles.applicationsSeenAt, profiles.lastKnownSignalAt — all additive, drizzle/0015_loving_umar.sql. pnpm verify (1299 tests, 0 lint errors) and pnpm build both green. Co-authored-by: Claude Sonnet 5 <noreply@anthropic.com>
37 lines
1.4 KiB
TypeScript
37 lines
1.4 KiB
TypeScript
"use client";
|
|
|
|
import { useEffect, useRef, type RefObject } from "react";
|
|
|
|
/**
|
|
* Closes an open panel on an outside click or Escape. Extracted from
|
|
* UserDropdown, which had this exact listener pair inline — now shared with
|
|
* NotificationBell and the marketing mega menu, the third and what would have
|
|
* been a fourth hand-copy of the same nine lines.
|
|
*
|
|
* `onClose` is read via a ref, not a dependency: an inline `() => setOpen(false)`
|
|
* is a new function every render, and re-registering two document listeners on
|
|
* every render (as opposed to once, on mount) is pure waste for a callback
|
|
* this cheap to keep current in a ref instead.
|
|
*/
|
|
export function useClickOutside(ref: RefObject<HTMLElement | null>, onClose: () => void): void {
|
|
const onCloseRef = useRef(onClose);
|
|
useEffect(() => {
|
|
onCloseRef.current = onClose;
|
|
}, [onClose]);
|
|
|
|
useEffect(() => {
|
|
function onMouseDown(e: MouseEvent) {
|
|
if (ref.current && !ref.current.contains(e.target as Node)) onCloseRef.current();
|
|
}
|
|
function onKeyDown(e: KeyboardEvent) {
|
|
if (e.key === "Escape") onCloseRef.current();
|
|
}
|
|
document.addEventListener("mousedown", onMouseDown);
|
|
document.addEventListener("keydown", onKeyDown);
|
|
return () => {
|
|
document.removeEventListener("mousedown", onMouseDown);
|
|
document.removeEventListener("keydown", onKeyDown);
|
|
};
|
|
}, [ref]);
|
|
}
|