Commit Graph
9 Commits
Author SHA1 Message Date
g-butandClaude Sonnet 4.6 a579c237e3 test(domain): add tests for normalizeCheckinMetric, streakMessage, relativeDate, sparkLevel
Cover the four functions extracted from components in the prior commit:
- normalizeCheckinMetric: boundary values (1→0, 5→100), midpoint, fractional rounding
- streakMessage: each milestone tier (0/1, 2, 3-6, 7-13, 14-29, 30+)
- relativeDate: today, yesterday, N-days-ago cases
- sparkLevel: low / mid / high threshold boundaries per SPARKLINE config

Test count: 133 → 153 (+20)

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-04-23 09:31:38 +02:00
g-butandClaude Sonnet 4.6 ea4a5fe43b refactor(domain): move business logic out of components into canonical homes
- lib/domain/checkin.ts: add streakMessage() — milestone thresholds (30/14/7/3/2
  days) are domain decisions, not UI copy; page now imports instead of defining
- lib/utils/format.ts: add relativeDate() — was duplicated in admin/patients page;
  formatting utilities belong here alongside other date helpers
- lib/domain/signals.ts: add sparkLevel() — wellness categorisation using
  SPARKLINE thresholds belongs in signals domain next to wellnessAvg()
- admin/patients page: remove all three local function defs, clean unused imports
- admin/reports page: replace magic -7 with SIGNAL_CHECKIN_WINDOW_DAYS

No behaviour change — same logic, now in testable, single-homed modules.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-04-23 09:26:40 +02:00
g-butandClaude Sonnet 4.6 09ef9dfa55 refactor(config): eliminate magic numbers and duplicate UUID regex
- lib/config/auth.ts: add PASSWORD_RESET_TOKEN_MAX_LENGTH and
  RESET_TOKEN_IDENTIFIER_PREFIX ("reset:") so the token schema cap and
  identifier prefix have a single source of truth
- auth routes: import and use both new constants (4 occurrences of
  hardcoded "reset:" prefix replaced)
- lib/utils/validate.ts: export UUID_RE so routes don't each define their
  own copy of the same regex
- documents routes (GET + upload): import UUID_RE instead of local re-def

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-04-23 09:06:37 +02:00
g-butandClaude Sonnet 4.6 999a3045ce test(format): add 6 tests for displayName utility
Covers name priority, email-local-part fallback, null/undefined name,
null email with default fallback, and custom fallback string.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-04-23 02:06:37 +02:00
g-butandClaude Sonnet 4.6 41506a3363 refactor(dry): extract displayName() utility, replace 5 inline fallbacks
The pattern `name ?? email.split("@")[0]` appeared in 5 cron routes
with slight variations (optional chaining, different fallbacks). Extracted
to lib/utils/format.ts displayName(name, email, fallback="there") and
replaced all occurrences.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-04-23 02:05:17 +02:00
g-butandClaude Sonnet 4.6 5d19bae7ac fix(config): last VitaReBa strings in email templates; add format.ts tests
lib/email/templates.ts: 4 remaining hardcoded "VitaReBa" text strings in
email body copy (password-reset, welcome, weekly-digest, checkin-reminder)
now use COMPANY.shortName. Every non-HTML-design brand reference now derives
from lib/config/company.ts.

lib/utils/format.test.ts: 19 tests covering all 6 exported date utilities
(formatDateShort, formatDateLong, formatDateNumeric, formatDateTime,
formatDateMonthDay, formatDateISO) plus HOUR_MS and DAY_MS constants.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-04-22 23:51:25 +02:00
g-butandClaude Sonnet 4.6 99fac8df4f refactor(format): add formatDateMonthDay utility; eliminate all inline toLocaleDateString calls
Add formatDateMonthDay() to lib/utils/format.ts for compact chart axis labels
("2 Apr"). Replace inline toLocaleDateString in assessments page, checkin page,
admin patient detail page, and admin documents page with the shared utility.
Also fix remaining USER_ROLE string literals in portal/admin layouts and
message thread pages.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-04-22 22:36:07 +02:00
g-butandClaude Sonnet 4.6 c4dbf247d7 refactor(utils): centralize formatDateISO, DAY_MS, HOUR_MS in lib/utils/format.ts
- Add formatDateISO(), DAY_MS, HOUR_MS exports to lib/utils/format.ts
- Remove 10+ inline .toISOString().slice(0,10) expressions across 8 files
- Remove 4 inline (24*60*60*1000) magic numbers across 5 files
- Remove local dateStr() function from weekly-digest/route.ts
- Remove local dayMs constant from lib/domain/signals.ts
- Remove private HOUR_MS/DAY_MS from lib/config/email-sequences.ts

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-04-22 14:52:29 +02:00
g-butandClaude Sonnet 4.6 785b923e25 feat(ui): portal nav overhaul, clinical goals UI, check-in, accessibility + readability fixes
Navigation & layout:
- PortalNav: icon sidebar with 4 groups, active state with teal left border
- BottomNav: fixed mobile bottom tab bar (5 items, safe-area-inset-bottom)
- NavBreadcrumb: route-aware header breadcrumb
- UserDropdown: escape key close, aria-expanded ring, quick check-in link

Portal features:
- Check-in page: 1-10 scale for mood/energy/sleep/stress
- PatientGoalsCard: admin goal CRUD with progress bars
- Dashboard: active clinical goals section
- ProfileCompletenessBar uses profileCompletenessColor()
- Admin patient detail decomposed into card components

Accessibility & readability:
- html font-size 112% - raises all rem values ~12% site-wide
- --muted darkened to #71727c (WCAG AA 4.5:1 on white)
- Hero eyebrow 0.6rem to 0.72rem, pill 0.58 to 0.68rem, sub contrast fixed
- Nav links 0.68 to 0.75rem
- LanguageSwitcher: pill container, mobile visible (was hidden), 0.62 to 0.72rem
- scaleBtn min-height 2.75rem (44px touch target)

Hero fix: .heroR justify-content flex-end (was center) aligns both columns

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-04-15 11:00:05 +02:00