Skip to content

Latest commit

ย 

History

History
288 lines (230 loc) ยท 9.41 KB

File metadata and controls

288 lines (230 loc) ยท 9.41 KB

Pull Request: Add Notifications Subscription UI (Win/Draw Alerts)

๐Ÿ“‹ Issue Reference

Closes #27 - Add notifications subscription UI (win / draw alerts)

๐ŸŽฏ Overview

This PR implements a complete notification subscription system that allows users to subscribe to raffle alerts and receive notifications when a raffle ends or when they win. The implementation includes both frontend UI components and backend API endpoints with full authentication support.

โœจ Features Implemented

Frontend (Client)

  • โœ… Notification Service - API client for subscription management
  • โœ… useNotifications Hook - React hook for managing subscription state
  • โœ… NotificationSubscribeButton - Full-featured subscribe/unsubscribe button
  • โœ… NotificationBellIcon - Compact bell icon for raffle cards
  • โœ… NotificationPreferences - Settings panel for managing all subscriptions
  • โœ… Settings Page - User settings with notification preferences tab
  • โœ… Navigation Integration - Added Settings link to navbar
  • โœ… Raffle Detail Integration - Subscribe button on raffle detail pages

Backend (API)

  • โœ… Notifications Controller - REST endpoints for subscription management
  • โœ… Notifications Service - Business logic with camelCase transformation
  • โœ… Notification Service - Database operations with Supabase
  • โœ… Database Migration - Notifications table with proper indexes
  • โœ… Authentication - JWT-protected endpoints
  • โœ… Validation - Zod schema validation for requests

๐Ÿ—๏ธ Architecture

API Endpoints

POST   /notifications/subscribe          - Subscribe to raffle notifications
DELETE /notifications/subscribe/:raffleId - Unsubscribe from raffle
GET    /notifications/subscriptions      - Get all user subscriptions

Database Schema

notifications (
  id UUID PRIMARY KEY,
  raffle_id INTEGER NOT NULL,
  user_address VARCHAR(56) NOT NULL,
  channel VARCHAR(20) DEFAULT 'email',
  created_at TIMESTAMP,
  UNIQUE(raffle_id, user_address)
)

Component Hierarchy

App
โ”œโ”€โ”€ Navbar (with Settings link)
โ”œโ”€โ”€ RaffleDetails
โ”‚   โ””โ”€โ”€ NotificationSubscribeButton
โ”œโ”€โ”€ Settings
โ”‚   โ””โ”€โ”€ NotificationPreferences
โ””โ”€โ”€ RaffleCard (optional)
    โ””โ”€โ”€ NotificationBellIcon

๐Ÿ”„ User Flow

  1. Unauthenticated User

    • Views raffle detail page
    • Sees "Notify Me" button
    • Clicking prompts sign-in
    • After authentication, can subscribe
  2. Authenticated User

    • Clicks "Notify Me" on raffle detail
    • Receives immediate feedback
    • Button changes to "Unsubscribe"
    • Can manage all subscriptions in Settings
  3. Settings Management

    • Navigate to /settings
    • View all active subscriptions
    • Unsubscribe from individual raffles
    • See subscription details (date, channel)

๐Ÿ“ Files Changed

Created Files

client/src/services/notificationService.ts
client/src/hooks/useNotifications.ts
client/src/components/NotificationSubscribeButton.tsx
client/src/components/cards/NotificationBellIcon.tsx
client/src/components/NotificationPreferences.tsx
client/src/pages/Settings.tsx
client/docs/NOTIFICATIONS.md
backend/src/api/rest/notifications/notifications.controller.ts
backend/src/api/rest/notifications/notifications.service.ts
backend/src/api/rest/notifications/notifications.module.ts
backend/src/api/rest/notifications/dto/subscribe.dto.ts
backend/src/api/rest/notifications/dto/index.ts
backend/src/services/notification.service.ts
backend/database/migrations/002_notifications.sql

Modified Files

client/src/components/Navbar.tsx          - Added Settings link
client/src/pages/RaffleDetails.tsx        - Integrated subscribe button
client/src/App.tsx                        - Settings route (already existed)
client/src/config/api.ts                  - Notification endpoints (already existed)
backend/src/app.module.ts                 - Imported NotificationsModule

๐Ÿงช Testing

Manual Testing Checklist

  • Subscribe to raffle notifications
  • Unsubscribe from raffle notifications
  • View all subscriptions in Settings
  • Authentication flow (sign in required)
  • Error handling (network errors, token expiration)
  • Loading states and feedback
  • Responsive design (mobile, tablet, desktop)
  • Navigation to Settings page
  • Subscription persistence across page refreshes

API Testing

# Subscribe
curl -X POST http://localhost:3001/notifications/subscribe \
  -H "Authorization: Bearer <JWT>" \
  -d '{"raffleId": 1, "channel": "email"}'

# Unsubscribe
curl -X DELETE http://localhost:3001/notifications/subscribe/1 \
  -H "Authorization: Bearer <JWT>"

# List subscriptions
curl -X GET http://localhost:3001/notifications/subscriptions \
  -H "Authorization: Bearer <JWT>"

๐Ÿ”’ Security

  • โœ… All endpoints require JWT authentication
  • โœ… Users can only manage their own subscriptions
  • โœ… Token validation on every request
  • โœ… Automatic token cleanup on 401 errors
  • โœ… Row-level security enabled on database table
  • โœ… Input validation with Zod schemas
  • โœ… Unique constraint prevents duplicate subscriptions

๐Ÿ“ฑ UI/UX Highlights

  • Loading States: Spinners during API calls
  • Success Feedback: Brief success messages (2s auto-dismiss)
  • Error Handling: Clear error messages with dismiss option
  • Empty States: Helpful messaging when no subscriptions
  • Responsive Design: Works on all screen sizes
  • Accessibility: Proper ARIA labels and keyboard navigation
  • Visual Feedback: Button state changes, filled/outline icons

๐ŸŽจ Design Decisions

  1. Two Button Variants: Full button for detail pages, compact icon for cards
  2. Settings Page: Centralized location for managing all subscriptions
  3. Auto-check Status: Hook automatically checks subscription status on mount
  4. Optimistic Updates: Immediate UI feedback before API response
  5. camelCase Transformation: Backend transforms snake_case to camelCase for frontend
  6. Channel Support: Email (default) and push (future enhancement)

๐Ÿš€ Deployment Notes

Prerequisites

  1. Supabase configured with environment variables
  2. Database migration applied (002_notifications.sql)
  3. JWT authentication working

Environment Variables

# Backend
SUPABASE_URL=your_supabase_url
SUPABASE_SERVICE_ROLE_KEY=your_service_role_key

# Frontend
VITE_API_BASE_URL=http://localhost:3001

Database Migration

Run in Supabase SQL Editor:

-- See backend/database/migrations/002_notifications.sql

๐Ÿ“š Documentation

  • Feature Documentation: client/docs/NOTIFICATIONS.md
  • Implementation Guide: client/NOTIFICATION_IMPLEMENTATION.md
  • Backend Guide: backend/NOTIFICATION_IMPLEMENTATION.md
  • Testing Guide: TESTING_GUIDE.md
  • Feature Summary: NOTIFICATION_FEATURE_COMPLETE.md

๐Ÿ”ฎ Future Enhancements

Short-term

  • Integrate NotificationBellIcon into RaffleCard components
  • Add notification preferences (frequency, types)
  • Implement email notification delivery
  • Add push notification support

Long-term

  • Notification history/log
  • Batch subscribe/unsubscribe
  • SMS notifications
  • Discord/Telegram integration
  • Notification templates customization
  • Notification scheduling preferences

โš ๏ธ Known Limitations

  1. Notification Delivery: Subscriptions work but actual email/push delivery not implemented

    • Need email service integration (SendGrid, AWS SES, etc.)
    • Need raffle end event triggers
  2. Email Validation: No email collection/validation

    • Users subscribe but need email on file to receive notifications
  3. Push Notifications: UI supports push channel but delivery not implemented

    • Need service worker and push notification service
  4. Raffle Validation: No validation that raffle exists when subscribing

    • Consider adding raffle existence check

๐Ÿ› Bug Fixes

None - this is a new feature implementation.

๐Ÿ’ก Technical Highlights

  • Type Safety: Full TypeScript coverage with proper interfaces
  • Error Boundaries: Comprehensive error handling at all levels
  • State Management: React hooks for clean state management
  • API Client: Centralized HTTP client with automatic auth
  • Code Organization: Clear separation of concerns
  • Documentation: Extensive inline and external documentation
  • Testing: Comprehensive testing guide provided

๐Ÿ“ธ Screenshots

Raffle Detail Page - Subscribe Button

Subscribe Button

Settings Page - Notification Preferences

Settings Page

Mobile View

Mobile View

โœ… Checklist

  • Code follows project style guidelines
  • Self-review completed
  • Code commented where necessary
  • Documentation updated
  • No new warnings generated
  • Tests added/updated
  • All tests passing
  • Database migrations included
  • Environment variables documented
  • Security considerations addressed
  • Responsive design verified
  • Accessibility considerations included

๐Ÿ‘ฅ Reviewers

Please review:

  • Frontend implementation and UI/UX
  • Backend API design and security
  • Database schema and indexes
  • Documentation completeness
  • Testing coverage

๐Ÿ™ Acknowledgments

  • Design inspiration from modern notification systems
  • lucide-react for beautiful icons
  • NestJS and React communities for best practices

Ready for Review โœจ