Skip to content

Conversation

@codeunia-dev
Copy link
Owner

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

  • Implement admin newsletter page with subscriber management
  • Create API routes for newsletter subscribers and sending
  • Add unsubscribe page for newsletter management
  • Implement subscriber statistics and export functionality
  • Add tabs for subscribers list and newsletter sending
  • Include error handling and loading states
  • Enhance footer with newsletter-related components

Author: @akshay0611

Summary by CodeRabbit

  • New Features
    • Added newsletter subscription functionality to the footer
    • Added unsubscribe page for users to manage newsletter preferences
    • Added admin dashboard to manage subscribers and view subscription statistics
    • Admin features include exporting subscribers as CSV and composing/sending newsletters to active subscribers

- Implement admin newsletter page with subscriber management
- Create API routes for newsletter subscribers and sending
- Add unsubscribe page for newsletter management
- Implement subscriber statistics and export functionality
- Add tabs for subscribers list and newsletter sending
- Include error handling and loading states
- Enhance footer with newsletter-related components
@vercel
Copy link

vercel bot commented Nov 1, 2025

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

Project Deployment Preview Comments Updated (UTC)
codeunia Ready Ready Preview Comment Nov 1, 2025 9:07am

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Nov 1, 2025

Caution

Review failed

The pull request is closed.

Walkthrough

Introduces a complete newsletter management system comprising public subscription/unsubscription flows, admin pages for subscriber management and newsletter delivery, and API endpoints for handling subscriptions, sending bulk emails, and retrieving subscriber data with Supabase integration and authentication.

Changes

Cohort / File(s) Summary
Admin Newsletter Management
app/admin/newsletter/page.tsx, app/api/admin/newsletter/subscribers/route.ts, app/api/admin/newsletter/send/route.ts
Adds admin interface to view subscriber statistics, export subscriber list as CSV, and compose/send newsletters. Implements GET endpoint to fetch subscribers with admin auth, and POST endpoint to send newsletters in batches (50 per batch) with 1-second delays between batches and unsubscribe links.
Public Newsletter Subscription
app/api/newsletter/route.ts
Adds POST endpoint to handle newsletter subscriptions: validates email format, checks for existing subscribers, resubscribes inactive subscribers, or creates new subscription records. Returns 409 for duplicates, 201 for new subscriptions, 200 for resubscriptions.
Public Newsletter Unsubscription
app/newsletter/unsubscribe/page.tsx, app/api/newsletter/unsubscribe/route.ts
Adds token-based unsubscribe page with loading, success, and error states. Implements POST endpoint to update subscription status to "unsubscribed" via unsubscribe token.
Footer Newsletter Integration
components/footer.tsx
Integrates newsletter signup form into footer with email validation, loading state, success/error messaging, and visual feedback (spinner, check icon). Posts to newsletter subscription endpoint.

Sequence Diagrams

sequenceDiagram
    actor User
    participant Footer
    participant API as /api/newsletter
    participant Supabase

    User->>Footer: Enter email & submit
    Footer->>Footer: Validate email format
    Footer->>API: POST {email}
    API->>API: Normalize email
    API->>Supabase: Check existing subscriber
    alt Subscriber exists & subscribed
        Supabase-->>API: Return subscriber
        API-->>Footer: 409 Conflict
        Footer->>User: Show error
    else Subscriber exists & unsubscribed
        Supabase-->>API: Return inactive subscriber
        API->>Supabase: Update status to "subscribed"
        Supabase-->>API: Success
        API-->>Footer: 200 OK
        Footer->>User: Show success
    else New subscriber
        Supabase-->>API: No record
        API->>Supabase: Insert new subscriber
        Supabase-->>API: 201 Created
        API-->>Footer: 201 Created
        Footer->>User: Show success
    end
Loading
sequenceDiagram
    actor Admin
    participant AdminPage as Admin Page
    participant API as /api/admin/newsletter/send
    participant Supabase
    participant Resend as Resend Service

    Admin->>AdminPage: Compose newsletter<br/>(subject + content)
    Admin->>AdminPage: Click "Send"
    AdminPage->>AdminPage: Validate inputs
    AdminPage->>AdminPage: Confirm scope
    AdminPage->>API: POST {subject, content}
    API->>Supabase: Verify admin auth
    Supabase-->>API: ✓ Admin confirmed
    API->>Supabase: Fetch subscribed users
    Supabase-->>API: Return subscriber list
    
    rect rgb(200, 220, 255)
    Note over API,Resend: Batch Processing (50 per batch)
    loop For each batch
        API->>Resend: Send emails (batch)
        Resend-->>API: Success/failure per email
        API->>API: Log per-email errors
        API->>API: Wait 1 second (rate limit)
    end
    end
    
    API-->>AdminPage: {total, sent} summary
    AdminPage->>Admin: Show result & reset form
Loading
sequenceDiagram
    actor User
    participant UnsubPage as Unsubscribe Page
    participant API as /api/newsletter/unsubscribe
    participant Supabase

    User->>UnsubPage: Click unsubscribe link (with token)
    UnsubPage->>UnsubPage: Read token from URL
    alt Token missing
        UnsubPage->>User: Show error state
    else Token present
        UnsubPage->>UnsubPage: Show loading state
        UnsubPage->>API: POST {token}
        API->>Supabase: Update status to "unsubscribed"<br/>WHERE unsubscribe_token = token
        alt Update successful
            Supabase-->>API: Success
            API-->>UnsubPage: 200 OK {message}
            UnsubPage->>User: Show success state
        else Token not found/already unsubscribed
            Supabase-->>API: No rows updated
            API-->>UnsubPage: 404 Not Found
            UnsubPage->>User: Show error state
        end
    end
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

  • Admin send API (app/api/admin/newsletter/send/route.ts): Review batch logic, rate-limiting delay, per-subscriber error handling, and Resend service integration carefully
  • Newsletter subscribe API (app/api/newsletter/route.ts): Verify subscription state transitions (new/resubscribe/duplicate), email normalization, and error code semantics
  • Auth enforcement across admin routes: Confirm Supabase authentication and is\_admin checks are correctly enforced
  • CSV export logic in admin page: Validate data formatting and download triggering mechanism

Poem

🐰 A newsletter hops into view,
Subscribers gather, both old and new,
Batch by batch, emails take flight,
With unsubscribe links shining bright!
Admins send tidings, users can flee,
A hoppy newsletter system—wheeeee! 🎉

✨ 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/newsletter

📜 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 3a6bbac and dee7024.

📒 Files selected for processing (7)
  • app/admin/newsletter/page.tsx (1 hunks)
  • app/api/admin/newsletter/send/route.ts (1 hunks)
  • app/api/admin/newsletter/subscribers/route.ts (1 hunks)
  • app/api/newsletter/route.ts (1 hunks)
  • app/api/newsletter/unsubscribe/route.ts (1 hunks)
  • app/newsletter/unsubscribe/page.tsx (1 hunks)
  • components/footer.tsx (4 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 a98b071 into main Nov 1, 2025
3 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