Add toast notification system with sonner library

- Create Toaster component wrapping sonner at bottom-right position
- Add showToast utility with success/error/info methods
- Error toasts persist until dismissed, others auto-dismiss after 5s
- Migrate error handling to toasts across all pages:
  - Dashboard (override toggle errors)
  - Settings (save/load success/error)
  - Garmin settings (connection success/error)
  - Calendar (load errors)
  - Period History (load/delete errors)
- Add dark mode support for toast styling
- Add Toaster provider to root layout
- 27 new tests (23 toaster component + 4 integration)
- Total: 977 unit tests passing

P5.2 COMPLETE - All P0-P5 items now complete.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
2026-01-12 23:04:27 +00:00
parent 38bea1ffd7
commit e971fe683f
17 changed files with 697 additions and 187 deletions

View File

@@ -4,7 +4,7 @@ This file is maintained by Ralph. Run `./ralph-sandbox.sh plan 3` to generate ta
## Current State Summary
### Overall Status: 950 unit tests passing across 49 test files + 64 E2E tests across 6 files
### Overall Status: 977 unit tests passing across 50 test files + 64 E2E tests across 6 files
### Library Implementation
| File | Status | Gap Analysis |
@@ -130,7 +130,8 @@ This file is maintained by Ralph. Run `./ralph-sandbox.sh plan 3` to generate ta
| `src/components/dashboard/onboarding-banner.test.tsx` | **EXISTS** - 16 tests (setup prompts, icons, action buttons, interactions, dismissal) |
| `src/components/calendar/day-cell.test.tsx` | **EXISTS** - 27 tests (phase coloring, today highlighting, click handling, accessibility) |
| `src/app/plan/page.test.tsx` | **EXISTS** - 16 tests (loading states, error handling, phase display, exercise reference, rebounding techniques) |
| `src/app/layout.test.tsx` | **EXISTS** - 3 tests (skip navigation link rendering, accessibility) |
| `src/app/layout.test.tsx` | **EXISTS** - 4 tests (skip navigation link rendering, accessibility, Toaster rendering) |
| `src/components/ui/toaster.test.tsx` | **EXISTS** - 23 tests (toast rendering, types, auto-dismiss, error persistence, accessibility) |
### Critical Business Rules (from Spec)
1. **Override Priority:** flare > stress > sleep > pms (must be enforced in order)
@@ -878,9 +879,9 @@ P4.* UX Polish ────────> After core functionality complete
| Done | P5.1 Period History UI | Complete | Page + 3 API routes with 61 tests |
| Done | P5.3 CI Pipeline | Complete | Lint, typecheck, tests in Gitea Actions |
| Done | P5.4 E2E Tests | Complete | 64 tests across 6 files |
| **Low** | P5.2 Toast Notifications | Low | Install library + integrate |
| Done | P5.2 Toast Notifications | Complete | sonner library + 23 tests |
**All P0-P4 items are complete. P5.1, P5.3, and P5.4 complete. Only remaining P5 item: Toast Notifications.**
**All P0-P5 items are complete. The project is feature complete.**
@@ -991,16 +992,16 @@ Analysis of all specs vs implementation revealed these gaps:
| Logout functionality | authentication.md | **COMPLETE** | Added POST /api/auth/logout + settings button |
| Garmin sync structured logging | observability.md | **COMPLETE** | Added sync start/complete/failure logging |
| Email sent/failed logging | observability.md | **COMPLETE** | Email events now logged (info for success, error for failure) with structured data (userId, emailType, success) |
| Period history UI | cycle-tracking.md | **PENDING** | See P5.1 below |
| Period history UI | cycle-tracking.md | **COMPLETE** | See P5.1 below |
| Dashboard color-coded backgrounds | dashboard.md | **COMPLETE** | DecisionCard shows RED/YELLOW/GREEN backgrounds per status (8 new tests) |
| Toast notifications | dashboard.md | **PENDING** | See P5.2 below |
| CI pipeline | testing.md | **PARTIALLY COMPLETE** | See P5.3 below |
| Toast notifications | dashboard.md | **COMPLETE** | sonner library + Toaster component + showToast utility (23 tests) |
| CI pipeline | testing.md | **COMPLETE** | See P5.3 below |
---
## P5: Remaining Gaps
## P5: Final Items ✅ ALL COMPLETE
These items were identified during gap analysis and remain pending.
These items were identified during gap analysis and have been completed.
### P5.1: Period History UI ✅ COMPLETE
- [x] Create period history viewing and editing UI
@@ -1037,36 +1038,34 @@ These items were identified during gap analysis and remain pending.
- **Total Tests Added:** 61 tests (18 + 16 + 27)
- **Why:** Users need to view and correct their period log history per spec requirement
### P5.2: Toast Notifications (PENDING)
- [ ] Add toast notification system for user feedback
### P5.2: Toast Notifications ✅ COMPLETE
- [x] Add toast notification system for user feedback
- **Spec Reference:** specs/dashboard.md lines 88-96
- **Required Features:**
- **Features Implemented:**
- Toast position: Bottom-right
- Auto-dismiss after 5 seconds
- Errors persist until dismissed
- Auto-dismiss after 5 seconds for success/info toasts
- Error toasts persist until dismissed (per spec: "Errors persist until dismissed")
- Toast types: success, error, info
- **Example Messages (from spec):**
- Network errors: "Unable to fetch data. Retry?"
- Garmin sync failed: "Garmin data unavailable. Using last known values."
- Save errors: "Failed to save. Try again."
- **Current State:**
- Only inline error messages exist
- No toast library installed
- No toast component
- **Implementation Tasks:**
1. Install toast library (react-hot-toast or sonner recommended)
2. Create Toast provider in layout.tsx
3. Create useToast hook for consistent API
4. Replace inline errors with toast notifications across:
- Dashboard (override toggle errors)
- Settings (save success/error)
- Garmin settings (connection success/error)
- Calendar (token regeneration success/error)
- Period logging (confirmation/error)
- **Files to Create/Modify:**
- `src/components/ui/toaster.tsx` + tests
- `src/app/layout.tsx` (add provider)
- Various page components (replace inline errors)
- Dark mode support with proper color theming
- Close button on all toasts
- **Library Used:** sonner (v2.0.7)
- **Files Created/Modified:**
- `src/components/ui/toaster.tsx` - Toaster component wrapping sonner with showToast utility (23 tests)
- `src/app/layout.tsx` - Added Toaster provider
- `src/app/page.tsx` - Dashboard override toggle errors now use toast
- `src/app/settings/page.tsx` - Settings save/load errors now use toast
- `src/app/settings/garmin/page.tsx` - Garmin connection success/error now use toast
- `src/app/calendar/page.tsx` - Calendar load errors now use toast
- `src/app/period-history/page.tsx` - Period history load/delete errors now use toast
- **Test Files Updated:**
- `src/components/ui/toaster.test.tsx` - 23 tests for toast component
- `src/app/layout.test.tsx` - Added Toaster mock
- `src/app/page.test.tsx` - Added showToast mock and test
- `src/app/settings/page.test.tsx` - Added showToast mock
- `src/app/settings/garmin/page.test.tsx` - Added showToast mock
- `src/app/calendar/page.test.tsx` - Added showToast mock and test
- `src/app/period-history/page.test.tsx` - Added showToast mock and tests
- **Total Tests Added:** 27 new tests (23 toaster + 4 integration tests across pages)
- **Why:** Better UX for transient feedback per spec requirements
### P5.3: CI Pipeline ✅ COMPLETE