Skip to content

Conversation

@codeunia-dev
Copy link
Owner

@codeunia-dev codeunia-dev commented Nov 24, 2025

  • Create new API endpoint for fetching and updating company notification preferences
  • Add GET /api/companies/[slug]/notifications route to retrieve current notification settings
  • Add PUT /api/companies/[slug]/notifications route to update notification preferences with role-based access control
  • Implement notification preference types in company type definitions
  • Add notification preferences service for managing company email notification logic
  • Integrate notification preferences UI in company settings dashboard page
  • Add loading and saving states for notification preference updates
  • Implement role-based authorization (owner/admin only) for notification preference management
  • Allows company owners and admins to control email notifications for registrations, event approvals/rejections, team member joins, and subscription expiration alerts

Authored by: @akshay0611

Summary by CodeRabbit

  • New Features
    • Added notification preference management to company settings, enabling owners and admins to control which emails they receive, including: new member registrations, event approvals and rejections, team member join notifications, and subscription expiration alerts.
    • Notification settings now integrate into the company dashboard with real-time save functionality and loading indicators.

✏️ Tip: You can customize this high-level summary in your review settings.

…mpany settings

- Create new API endpoint for fetching and updating company notification preferences
- Add GET /api/companies/[slug]/notifications route to retrieve current notification settings
- Add PUT /api/companies/[slug]/notifications route to update notification preferences with role-based access control
- Implement notification preference types in company type definitions
- Add notification preferences service for managing company email notification logic
- Integrate notification preferences UI in company settings dashboard page
- Add loading and saving states for notification preference updates
- Implement role-based authorization (owner/admin only) for notification preference management
- Allows company owners and admins to control email notifications for registrations, event approvals/rejections, team member joins, and subscription expiration alerts
@vercel
Copy link

vercel bot commented Nov 24, 2025

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Preview Comments Updated (UTC)
codeunia Building Building Preview Comment Nov 24, 2025 8:33am

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Nov 24, 2025

Caution

Review failed

The pull request is closed.

Walkthrough

Introduces a notification preferences system for companies with a new API route (GET/PUT) for managing preferences, a service layer for querying and sending notifications based on preferences, frontend UI updates to display and persist settings, and type definitions for notification preference fields.

Changes

Cohort / File(s) Summary
API Route
app/api/companies/[slug]/notifications/route.ts
Adds GET and PUT endpoints to fetch and update company notification preferences with authentication and owner/admin authorization checks.
Frontend Settings Page
app/dashboard/company/[slug]/settings/page.tsx
Introduces loading and saving states for notifications, fetches preferences on mount, conditionally renders notification toggles, and implements PUT request to persist preferences with success/error toasts.
Notification Service
lib/services/company-notifications.ts
Adds functions to fetch notification preferences, check if a notification type is enabled, retrieve active owner/admin recipient emails, and send emails conditionally based on preference status.
Type Definitions
types/company.ts
Extends Company interface with five optional notification boolean fields and introduces CompanyNotificationPreferences interface with required equivalents.

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant UI as Settings Page
    participant API as /api/.../notifications
    participant DB as Database
    participant Service as Service Layer

    rect rgba(100, 200, 150, 0.2)
    note over User,Service: Get Notification Preferences
    User->>UI: Navigate to Notifications
    UI->>API: GET /api/companies/[slug]/notifications
    API->>API: Verify Auth & Permissions
    API->>DB: Fetch company notification prefs
    DB-->>API: Return preferences (or nulls)
    API-->>UI: Return with defaults
    UI->>UI: Set loading state, render toggles
    end

    rect rgba(150, 150, 200, 0.2)
    note over User,Service: Save Notification Preferences
    User->>UI: Toggle preference & click Save
    UI->>UI: Show "Saving…" state
    UI->>API: PUT /api/companies/[slug]/notifications
    API->>API: Verify Auth & Permissions
    API->>API: Validate & sanitize input
    API->>DB: Update notification preferences
    DB-->>API: Return updated record
    API-->>UI: Return updated preferences
    UI->>UI: Show success toast, clear loading
    end
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20–30 minutes

  • Authorization logic: Both API endpoints repeat auth/permission checks (authenticate user, verify active membership, ensure owner/admin role)—verify these patterns are consistent and correctly implemented
  • Service layer integration: Review getCompanyNotificationRecipients() and error handling paths; verify defensive null checks and default behaviors
  • Frontend state management: Trace loading/saving state transitions in the settings page; ensure proper cleanup and error handling in useEffect
  • Type consistency: Confirm notification preference fields in Company and CompanyNotificationPreferences interfaces remain in sync

Possibly related PRs

Poem

🐰 Notifications hop into view,
Preferences saved, preferences true,
API routes and toggles align,
Company emails now by design!
Hop-hop-hooray, the system's divine!

✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch feat/companynotification

📜 Recent review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 5170580 and ae1cb8b.

📒 Files selected for processing (4)
  • app/api/companies/[slug]/notifications/route.ts (1 hunks)
  • app/dashboard/company/[slug]/settings/page.tsx (4 hunks)
  • lib/services/company-notifications.ts (1 hunks)
  • types/company.ts (2 hunks)

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@codeunia-dev codeunia-dev merged commit 872c131 into main Nov 24, 2025
2 of 4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants