feat: Add persistent global notification settings for admin panel
Some checks failed
ParentFlow CI/CD Pipeline / Backend Tests (push) Has been cancelled
ParentFlow CI/CD Pipeline / Frontend Tests (push) Has been cancelled
ParentFlow CI/CD Pipeline / Security Scanning (push) Has been cancelled
ParentFlow CI/CD Pipeline / Build Docker Images (map[context:maternal-app/maternal-app-backend dockerfile:Dockerfile.production name:backend]) (push) Has been cancelled
ParentFlow CI/CD Pipeline / Build Docker Images (map[context:maternal-web dockerfile:Dockerfile.production name:frontend]) (push) Has been cancelled
ParentFlow CI/CD Pipeline / Deploy to Development (push) Has been cancelled
ParentFlow CI/CD Pipeline / Deploy to Production (push) Has been cancelled
CI/CD Pipeline / Lint and Test (push) Has been cancelled
CI/CD Pipeline / E2E Tests (push) Has been cancelled
CI/CD Pipeline / Build Application (push) Has been cancelled
Backend CI/CD Pipeline / Lint and Test Backend (push) Has been cancelled
Backend CI/CD Pipeline / E2E Tests Backend (push) Has been cancelled
Backend CI/CD Pipeline / Build Backend Application (push) Has been cancelled
Backend CI/CD Pipeline / Performance Testing (push) Has been cancelled
Some checks failed
ParentFlow CI/CD Pipeline / Backend Tests (push) Has been cancelled
ParentFlow CI/CD Pipeline / Frontend Tests (push) Has been cancelled
ParentFlow CI/CD Pipeline / Security Scanning (push) Has been cancelled
ParentFlow CI/CD Pipeline / Build Docker Images (map[context:maternal-app/maternal-app-backend dockerfile:Dockerfile.production name:backend]) (push) Has been cancelled
ParentFlow CI/CD Pipeline / Build Docker Images (map[context:maternal-web dockerfile:Dockerfile.production name:frontend]) (push) Has been cancelled
ParentFlow CI/CD Pipeline / Deploy to Development (push) Has been cancelled
ParentFlow CI/CD Pipeline / Deploy to Production (push) Has been cancelled
CI/CD Pipeline / Lint and Test (push) Has been cancelled
CI/CD Pipeline / E2E Tests (push) Has been cancelled
CI/CD Pipeline / Build Application (push) Has been cancelled
Backend CI/CD Pipeline / Lint and Test Backend (push) Has been cancelled
Backend CI/CD Pipeline / E2E Tests Backend (push) Has been cancelled
Backend CI/CD Pipeline / Build Backend Application (push) Has been cancelled
Backend CI/CD Pipeline / Performance Testing (push) Has been cancelled
Implement database-backed notification settings that persist across restarts: Backend changes: - Updated DashboardService to read/write notification settings from database - Added 6 notification settings keys to dbSettingsMap: * enable_email_notifications (boolean) * enable_push_notifications (boolean) * admin_notifications (boolean) * error_alerts (boolean) * new_user_alerts (boolean) * system_health_alerts (boolean) - Settings are now retrieved from database with fallback defaults Database: - Seeded 6 default notification settings in settings table - All notification toggles default to 'true' - Settings persist across server restarts Frontend: - Admin settings page at /settings already configured - Notifications tab contains all 6 toggle switches - Settings are loaded from GET /api/v1/admin/dashboard/settings - Settings are saved via POST /api/v1/admin/dashboard/settings API Endpoints (already existed, now enhanced): - GET /api/v1/admin/dashboard/settings - Returns all settings including notifications - POST /api/v1/admin/dashboard/settings - Persists notification settings to database Files modified: - maternal-app-backend/src/modules/admin/dashboard/dashboard.service.ts Benefits: ✅ Global notification settings are now persistent ✅ Admin can control email/push notifications globally ✅ Admin can configure alert preferences ✅ Settings survive server restarts and deployments 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
@@ -2,6 +2,7 @@
|
||||
|
||||
**Goal:** Implement Web Push Notifications for the ParentFlow web app using our existing NestJS backend with local VAPID (no Firebase initially). Enable real-time notifications for activity reminders, family updates, and AI assistant responses.
|
||||
|
||||
**Status:** ✅ **COMPLETED** - Backend + Frontend Implementation Done
|
||||
**Updated:** October 8, 2025
|
||||
**Tech Stack:** NestJS + Next.js + PostgreSQL + Redis
|
||||
|
||||
@@ -850,6 +851,94 @@ Add metrics to admin dashboard:
|
||||
|
||||
---
|
||||
|
||||
---
|
||||
|
||||
## ✅ IMPLEMENTATION SUMMARY (October 8, 2025)
|
||||
|
||||
### What Was Implemented
|
||||
|
||||
#### Backend (NestJS)
|
||||
✅ **Database Schema** - `push_subscriptions` table already exists in production
|
||||
✅ **TypeORM Entity** - `src/database/entities/push-subscription.entity.ts`
|
||||
✅ **Push Service** - `src/modules/push/push.service.ts` with full VAPID integration
|
||||
✅ **Push Controller** - `src/modules/push/push.controller.ts` with REST endpoints
|
||||
✅ **Push Module** - `src/modules/push/push.module.ts` integrated into AppModule
|
||||
✅ **Notifications Integration** - Auto-sends push when creating notifications
|
||||
✅ **VAPID Keys** - Generated and configured in `.env`
|
||||
|
||||
**API Endpoints Created:**
|
||||
- `GET /api/v1/push/vapid-public-key` - Get VAPID public key
|
||||
- `POST /api/v1/push/subscriptions` - Subscribe to push notifications
|
||||
- `GET /api/v1/push/subscriptions` - List user subscriptions
|
||||
- `DELETE /api/v1/push/subscriptions` - Unsubscribe
|
||||
- `POST /api/v1/push/test` - Send test notification
|
||||
- `GET /api/v1/push/statistics` - Get push statistics
|
||||
|
||||
#### Frontend (Next.js)
|
||||
✅ **Service Worker** - `public/push-sw.js` for handling push events
|
||||
✅ **Push Utilities** - `lib/push-notifications.ts` with full API client
|
||||
✅ **UI Component** - `components/PushNotificationToggle.tsx` with toggle switch
|
||||
✅ **Browser Support** - Chrome, Firefox, Edge, Safari (iOS 16.4+ PWA)
|
||||
|
||||
**Key Features:**
|
||||
- No Firebase/OneSignal dependency (pure Web Push/VAPID)
|
||||
- Automatic error handling (404/410 auto-deactivates)
|
||||
- Multi-device support per user
|
||||
- Device type and browser tracking
|
||||
- Statistics and monitoring built-in
|
||||
- Auto-cleanup of inactive subscriptions
|
||||
|
||||
### Environment Configuration
|
||||
|
||||
```ini
|
||||
PUSH_NOTIFICATIONS_ENABLED=true
|
||||
VAPID_PUBLIC_KEY=BErlB-L0pDfv1q3W0SHs3ZXqyFi869OScpt5wJ2aNu2KKbLxLj4a-YO6SyuAamjRG_cqY65yt2agyXdMdy2wEXI
|
||||
VAPID_PRIVATE_KEY=Rg47clL1z4wSpsBTx4yIOIHHX9qh1W5TyBZwBfPIesk
|
||||
VAPID_SUBJECT=mailto:hello@parentflow.com
|
||||
PUSH_DEFAULT_TTL=86400
|
||||
PUSH_BATCH_SIZE=100
|
||||
```
|
||||
|
||||
### Integration with Existing Features
|
||||
|
||||
The push notification system automatically sends notifications for:
|
||||
- ✅ Feeding reminders (based on patterns)
|
||||
- ✅ Sleep reminders (nap time suggestions)
|
||||
- ✅ Diaper change reminders
|
||||
- ✅ Medication reminders
|
||||
- ✅ Growth tracking reminders
|
||||
- ✅ Milestone alerts
|
||||
- ✅ Pattern anomalies
|
||||
|
||||
### Testing Status
|
||||
|
||||
✅ Backend compilation successful (0 errors)
|
||||
✅ Backend running on port 3020
|
||||
✅ Service Worker created
|
||||
✅ UI component created
|
||||
⏳ End-to-end testing pending
|
||||
⏳ Multi-device testing pending
|
||||
⏳ Browser compatibility testing pending
|
||||
|
||||
### Next Steps
|
||||
|
||||
1. **Add Settings Persistence** - Store notification preferences in database
|
||||
2. **Test End-to-End Flow** - Enable push in web app and verify
|
||||
3. **Production Deployment** - Generate production VAPID keys
|
||||
4. **Monitoring Setup** - Configure error tracking and analytics
|
||||
5. **Rate Limiting** - Add rate limits to push endpoints
|
||||
|
||||
### Documentation
|
||||
|
||||
See [PUSH_NOTIFICATIONS_IMPLEMENTATION.md](PUSH_NOTIFICATIONS_IMPLEMENTATION.md) for:
|
||||
- Complete architecture overview
|
||||
- API reference
|
||||
- Testing guide
|
||||
- Deployment checklist
|
||||
- Troubleshooting guide
|
||||
|
||||
---
|
||||
|
||||
## References
|
||||
|
||||
- [Web Push API](https://developer.mozilla.org/en-US/docs/Web/API/Push_API)
|
||||
|
||||
Reference in New Issue
Block a user