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
notificationPreferencesfield - Beautiful UI with yellowish theme matching the app design
Database Structure:
users/{userId} {
notificationPreferences: {
urgentTasksNearby: true,
maxRadius: 5,
urgencyLevels: ['high', 'emergency']
}
}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
}
}Status: Not yet set up (requires Firebase configuration)
Next Steps:
-
Install Firebase CLI:
npm install -g firebase-tools firebase login
-
Initialize Firebase Functions:
firebase init functions
-
Install dependencies in
functions/folder:cd functions npm install --save @sendgrid/mail geofire-common -
Copy the cloud function code from
URGENT_TASK_NOTIFICATIONS.md(lines 97-379) intofunctions/index.js -
Set Firebase config:
firebase functions:config:set sendgrid.key="YOUR_SENDGRID_API_KEY" firebase functions:config:set app.url="http://localhost:3000"
-
Deploy:
firebase deploy --only functions
Status: Not yet configured
Option A - SendGrid (Recommended):
- Sign up at https://sendgrid.com/ (free tier: 100 emails/day)
- Create API key: Settings → API Keys → Create API Key
- Verify sender email: Sender Authentication → Verify Single Sender
- Use API key in Firebase config (step 5 above)
Option B - Mailgun:
- Sign up at https://www.mailgun.com/
- Get API key from Settings → API Keys
- Modify cloud function to use Mailgun instead of SendGrid
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']);
}You can test the frontend features immediately:
- Navigate to Profile page as a volunteer
- Verify the "Email Notifications" section appears
- Toggle the notification checkbox on/off
- Adjust the radius slider (1-20 km)
- Save and verify preferences are persisted
- Navigate to VolunteerFeed page
- Open browser console and look for "Location updated for notifications" logs every 5 minutes
- Check Firestore to see the location.isActive field updating
Once Firebase Cloud Functions and SendGrid are configured:
- Create an urgent request with urgencyLevel: 'high' or 'emergency'
- Ensure request location is within notification radius of test volunteer
- Check volunteer email for notification
- Verify Firebase logs:
firebase functions:log - Test rate limiting: Try creating 4 urgent requests within an hour - 4th should not trigger email
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)
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
What's Ready:
- Frontend UI for notification preferences ✅
- Location tracking on VolunteerFeed ✅
- Complete documentation and architecture ✅
- Database schema ready ✅
What You Need to Do:
- Enable Google Maps APIs (already in progress)
- Set up Firebase Cloud Functions (follow steps above)
- Configure SendGrid account and API key
- Deploy cloud functions
- Update Firestore security rules
- Test end-to-end
Estimated Setup Time: 30-60 minutes
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)