Skip to content

Latest commit

 

History

History
188 lines (150 loc) · 5.59 KB

File metadata and controls

188 lines (150 loc) · 5.59 KB

Notification System Implementation Status

✅ Completed (Frontend)

1. Profile Page - Notification Preferences UI

File: src/pages/Profile.js (lines 20-24, 40-43, 68, 145-196)

Features Implemented:

  • Checkbox to enable/disable urgent task email notifications
  • Slider to set notification radius (1-20 km)
  • Only visible for volunteers (userType === 'volunteer')
  • Preferences saved to Firestore under notificationPreferences field
  • Beautiful UI with yellowish theme matching the app design

Database Structure:

users/{userId} {
  notificationPreferences: {
    urgentTasksNearby: true,
    maxRadius: 5,
    urgencyLevels: ['high', 'emergency']
  }
}

2. VolunteerFeed - Location Tracking

File: src/pages/VolunteerFeed.js (lines 103-136)

Features Implemented:

  • Updates volunteer location in database when page loads
  • Periodic updates every 5 minutes while on the page
  • Marks user as active (isActive: true) when on the feed
  • Marks user as inactive (isActive: false) when leaving the page
  • Uses serverTimestamp for accurate tracking

Database Structure:

users/{userId} {
  location: {
    lat: 42.1234,
    lng: -76.5678,
    lastUpdated: timestamp,
    isActive: true  // Updated by VolunteerFeed
  }
}

🚧 Remaining (Backend) - Requires User Setup

3. Firebase Cloud Functions

Status: Not yet set up (requires Firebase configuration)

Next Steps:

  1. Install Firebase CLI:

    npm install -g firebase-tools
    firebase login
  2. Initialize Firebase Functions:

    firebase init functions
  3. Install dependencies in functions/ folder:

    cd functions
    npm install --save @sendgrid/mail geofire-common
  4. Copy the cloud function code from URGENT_TASK_NOTIFICATIONS.md (lines 97-379) into functions/index.js

  5. Set Firebase config:

    firebase functions:config:set sendgrid.key="YOUR_SENDGRID_API_KEY"
    firebase functions:config:set app.url="http://localhost:3000"
  6. Deploy:

    firebase deploy --only functions

4. Email Service (SendGrid/Mailgun)

Status: Not yet configured

Option A - SendGrid (Recommended):

  1. Sign up at https://sendgrid.com/ (free tier: 100 emails/day)
  2. Create API key: Settings → API Keys → Create API Key
  3. Verify sender email: Sender Authentication → Verify Single Sender
  4. Use API key in Firebase config (step 5 above)

Option B - Mailgun:

  1. Sign up at https://www.mailgun.com/
  2. Get API key from Settings → API Keys
  3. Modify cloud function to use Mailgun instead of SendGrid

5. Firestore Security Rules

Status: Not yet updated

Add to firestore.rules:

match /users/{userId} {
  allow read: if request.auth != null;
  allow write: if request.auth.uid == userId;

  // Only allow updating own notification preferences
  allow update: if request.auth.uid == userId
    && request.resource.data.diff(resource.data).affectedKeys()
      .hasOnly(['notificationPreferences', 'location']);
}

🧪 Testing

Frontend Testing (Available Now)

You can test the frontend features immediately:

  1. Navigate to Profile page as a volunteer
  2. Verify the "Email Notifications" section appears
  3. Toggle the notification checkbox on/off
  4. Adjust the radius slider (1-20 km)
  5. Save and verify preferences are persisted
  6. Navigate to VolunteerFeed page
  7. Open browser console and look for "Location updated for notifications" logs every 5 minutes
  8. Check Firestore to see the location.isActive field updating

Backend Testing (After Setup)

Once Firebase Cloud Functions and SendGrid are configured:

  1. Create an urgent request with urgencyLevel: 'high' or 'emergency'
  2. Ensure request location is within notification radius of test volunteer
  3. Check volunteer email for notification
  4. Verify Firebase logs: firebase functions:log
  5. Test rate limiting: Try creating 4 urgent requests within an hour - 4th should not trigger email

📊 Cost Estimation

Free Tier (Testing/Small Scale):

  • SendGrid: 100 emails/day free
  • Firebase Functions: 2M invocations/month free
  • Firestore: 50K reads/day free

Production (100 volunteers, 3 notifications/hour, 12 hours):

  • Daily emails: ~3,600
  • SendGrid Pro: $15/month (40K emails)
  • Firebase Blaze Plan: Pay-as-you-go (likely $5-10/month)

🔒 Privacy & Security

Implemented:

  • ✅ Opt-in notifications (default: enabled, but user can disable)
  • ✅ Location tracking only when volunteer is on feed page
  • ✅ Clear indication of notification radius
  • ✅ Rate limiting documented (3 emails/hour max)

Recommended:

  • Add terms of service explaining location tracking
  • Add privacy policy covering email notifications
  • Consider adding notification history to profile (show last 5 emails sent)
  • Add "unsubscribe" link in emails

📝 Summary

What's Ready:

  • Frontend UI for notification preferences ✅
  • Location tracking on VolunteerFeed ✅
  • Complete documentation and architecture ✅
  • Database schema ready ✅

What You Need to Do:

  1. Enable Google Maps APIs (already in progress)
  2. Set up Firebase Cloud Functions (follow steps above)
  3. Configure SendGrid account and API key
  4. Deploy cloud functions
  5. Update Firestore security rules
  6. Test end-to-end

Estimated Setup Time: 30-60 minutes

📚 Reference Documentation

See URGENT_TASK_NOTIFICATIONS.md for complete technical details including:

  • Full cloud function implementation
  • Email templates (text + HTML)
  • Proximity calculation logic
  • Notification history cleanup
  • Advanced features (SMS, push notifications)