Successfully implemented the notification subscription feature for the Tikka raffle platform. Users can now subscribe to receive notifications when a raffle ends or when they win.
notificationService.ts: API client for notification endpoints- Subscribe to raffle notifications
- Unsubscribe from notifications
- Get user subscriptions
- Check subscription status
useNotifications.ts: Custom hook for managing subscriptions- Manages subscription state
- Handles authentication requirements
- Auto-checks subscription status
- Provides subscribe/unsubscribe methods
- Full-featured subscribe/unsubscribe button
- Shows loading states and success/error messages
- Handles authentication flow
- Available in default and compact variants
- Used on raffle detail pages
- Compact bell icon for raffle cards
- Quick toggle for subscriptions
- Visual indication of subscription status
- Minimal UI footprint
- Complete subscription management panel
- Lists all active subscriptions
- Allows individual unsubscribe
- Shows subscription details (date, channel)
- New
/settingsroute - Tabbed interface (Notifications, Profile)
- Full notification preferences management
- Profile information display
- Added notification subscription section
- "Stay Updated" card with subscribe button
- Prompts authentication when needed
- Added Settings route
- Integrated with existing routing structure
- Updated
api.tswith notification endpoints - Added notification types to
types.ts - Configured API client for authenticated requests
client/
├── src/
│ ├── components/
│ │ ├── NotificationSubscribeButton.tsx # Main subscribe button
│ │ ├── NotificationPreferences.tsx # Settings panel
│ │ └── cards/
│ │ └── NotificationBellIcon.tsx # Compact bell icon
│ ├── hooks/
│ │ └── useNotifications.ts # Subscription hook
│ ├── services/
│ │ └── notificationService.ts # API client
│ ├── pages/
│ │ ├── Settings.tsx # Settings page
│ │ └── RaffleDetails.tsx # Updated with notifications
│ ├── config/
│ │ └── api.ts # Updated with endpoints
│ └── types/
│ └── types.ts # Updated with notification types
└── docs/
└── NOTIFICATIONS.md # Feature documentation
The backend must implement these endpoints:
Subscribe to raffle notifications
Request:
Headers: Authorization: Bearer <JWT>
Body: { raffleId: number, channel?: 'email' | 'push' }
Response:
Status: 201 Created
Body: {
id: string,
raffleId: number,
userAddress: string,
channel: string,
createdAt: string
}Unsubscribe from raffle notifications
Request:
Headers: Authorization: Bearer <JWT>
Params: raffleId (number)
Response:
Status: 204 No ContentGet all user subscriptions
Request:
Headers: Authorization: Bearer <JWT>
Response:
Status: 200 OK
Body: [{
id: string,
raffleId: number,
channel: string,
createdAt: string
}]- User views raffle details
- Sees "Stay Updated" section with "Notify Me" button
- If not signed in, clicking prompts authentication
- If signed in, clicking subscribes to notifications
- Button updates to show "Unsubscribe" status
- Success message displays briefly
- User navigates to
/settings - Clicks "Notifications" tab
- Views all active subscriptions
- Can unsubscribe from individual raffles
- Sees subscription details (date, channel)
- Compact bell icon can be added to raffle cards
- Quick toggle without leaving the page
- Visual indication of subscription status
All notification features require:
- User must be signed in with Stellar wallet
- Valid JWT token in sessionStorage
- Token automatically included in API requests
- Auto-logout on wallet disconnect
Currently supported:
- Email (default): Email notifications
- Push (future): Browser push notifications
The implementation handles:
- Authentication required errors
- Network failures
- Subscription conflicts
- Token expiration
- API errors
All errors display user-friendly messages with dismiss options.
- Sign in with wallet
- Subscribe to raffle from detail page
- Verify subscription status updates
- Navigate to Settings → Notifications
- View active subscriptions
- Unsubscribe from a raffle
- Verify subscription removed
- Test without authentication
- Test error scenarios
-
Create Notifications Table
CREATE TABLE notifications ( id UUID PRIMARY KEY, raffle_id INTEGER NOT NULL, user_address VARCHAR(56) NOT NULL, channel VARCHAR(20) NOT NULL, created_at TIMESTAMP DEFAULT NOW(), UNIQUE(raffle_id, user_address) );
-
Implement API Endpoints
- POST /notifications/subscribe
- DELETE /notifications/subscribe/:raffleId
- GET /notifications/subscriptions
-
Add Authentication Middleware
- Verify JWT tokens
- Extract user address
- Protect endpoints
-
Implement Notification Delivery
- Email service integration
- Event triggers on raffle end
- Event triggers on win
- Push notification support
- Email preferences (frequency, types)
- Notification history
- Batch operations
- SMS notifications
- Discord/Telegram integration
- Notification templates
See client/docs/NOTIFICATIONS.md for detailed usage documentation and examples.
- All components follow existing Tikka design patterns
- Uses existing authentication system
- Integrates seamlessly with current routing
- Minimal dependencies (uses existing lucide-react icons)
- Responsive design for mobile and desktop
- Accessible UI with proper ARIA labels