Skip to content

Conversation

@codeunia-dev
Copy link
Owner

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

This pull request introduces key improvements to the Company Dashboard experience, including enhanced user profile visuals and automated email notifications for company member role changes.


✨ What’s New

1. Improved Company Dashboard Profile UI

  • Added avatar image support for user profiles.
  • Improved layout and styling for better visual clarity.
  • Ensures consistent presentation of user details across the dashboard.

2. Role Change Notification Emails

  • Implemented backend logic to trigger email notifications whenever a member’s role is updated.
  • Helps keep team members aware of changes in their access level.
  • Improves transparency and communication within company teams.

🔧 Code Overview

  • 234 additions
  • 73 deletions
  • Changes span 5 files, including dashboard components, utility functions, and notification handlers.

🧪 Testing

  • Verified profile page renders correctly with avatar support.

  • Confirmed email notifications are sent for:

    • Admin → Member role changes
    • Member → Admin promotions
  • Checked dashboard routes and ensured no breakages.


📌 Notes

  • Future enhancement: Add UI for managing company member roles directly from the dashboard.
  • Consider supporting custom email templates for more personalized branding.

✅ Ready for Review

This PR is ready for review and requires one approval before merging.

Authored by: @akshay0611

Summary by CodeRabbit

  • New Features

    • Members now receive email notifications when their role is changed
    • Enhanced error messaging displays when team member limit is reached during invitations
  • Bug Fixes

    • Fixed branding text inconsistencies in email templates
    • Improved form validation feedback for users
  • Refactor

    • Optimized avatar display rendering in company dashboard sidebar

…ges and dynamic data fetching

- Fetch user profile data from profiles table including avatar_url, first_name, and last_name
- Add UserProfile interface to properly type user profile data structure
- Implement useEffect hook to load user profile on component mount
- Replace hardcoded avatar initials with dynamic data from user profile
- Create reusable AvatarContent component to eliminate duplicate avatar rendering logic
- Update CompanySidebar to accept avatarUrl and avatarInitial as separate props
- Integrate Avatar component from UI library for consistent image display with fallback
- Support avatar image display with gradient fallback when image unavailable
- Refactor avatar rendering across mobile and desktop sidebar sections to use new component
- Improve user profile data consistency by centralizing profile fetching in layout component
- Implement role change email notification when member roles are updated
- Add getRoleChangeEmail function with role-specific permissions display
- Include member name, company name, old/new role, and changed by information
- Send email asynchronously to avoid blocking the API response
- Add dashboard link in email for easy access to company settings
- Fix email template branding from "CodeUnia" to "Codeunia" for consistency
- Include graceful error handling for email delivery failures
- Fetch member and requesting user profile information for personalized emails
@vercel
Copy link

vercel bot commented Nov 17, 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 17, 2025 5:00am

@codeunia-dev codeunia-dev merged commit cbe17be into main Nov 17, 2025
2 of 4 checks passed
@coderabbitai
Copy link
Contributor

coderabbitai bot commented Nov 17, 2025

Caution

Review failed

The pull request is closed.

Walkthrough

Multiple interrelated features: Role-change email notifications with async sending added to member update endpoint; user profile data refactored to fetch from Supabase; avatar rendering migrated to reusable component; toast notification system migrated from useToast hook to direct sonner API; new role-change email template created.

Changes

Cohort / File(s) Summary
Member Role Change & Notification
app/api/companies/[slug]/members/[userId]/route.ts, lib/email/company-emails.ts
Role updates now trigger async email notifications. Captures old role, fetches member and requester profiles, constructs role-change email with permissions details, sends non-blocking notification. New getRoleChangeEmail function generates HTML email template with role comparison and dashboard link.
Company Dashboard Layout Refactor
app/dashboard/company/layout.tsx
CompanyDashboardContent component signature changed to accept single user prop instead of separate avatar, name, email props. Introduced Supabase profile data fetch to derive avatarUrl, avatarInitial, name, and email from profiles table.
Avatar Component Refactoring
components/dashboard/CompanySidebar.tsx
Replaced inline avatar rendering with reusable AvatarContent component. Updated CompanySidebarProps to accept avatarUrl?: string and avatarInitial: string instead of avatar: React.ReactNode. Avatar now renders consistently across desktop and mobile sections.
Toast Notification Migration
components/dashboard/TeamManagement.tsx
Replaced useToast hook with direct toast API from sonner. Converted all toast() calls to toast.error/toast.success variants. Added explicit validation feedback for email field and detailed error display for upgrade-required scenarios. Minor text fix: "CodeUnia" → "Codeunia".

Sequence Diagram

sequenceDiagram
    participant Client
    participant API as PUT /members/[userId]
    participant DB as Database
    participant Email as Email Service
    participant Cache as Cache Layer

    Client->>API: Update member role
    API->>DB: Fetch old role & member data
    DB-->>API: Member profile
    API->>DB: Update role to newRole
    DB-->>API: Update confirmed
    API->>DB: Fetch requester profile
    DB-->>API: Requester profile
    
    rect rgb(100, 150, 200)
    Note over API,Email: Async Email Flow (non-blocking)
    API->>Email: Send role-change notification
    Email-->>API: Email sent (async)
    end
    
    API->>Cache: Invalidate member cache
    API-->>Client: 200 OK
    
    alt Email fails
        Email->>API: Log error (no impact to response)
    end
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

  • app/api/companies/[slug]/members/[userId]/route.ts: Review async email sending logic, error handling, and profile fetching flow—ensure no request blocking and proper cache invalidation order.
  • app/dashboard/company/layout.tsx: Verify Supabase profile fetch implementation, fallback handling, and ensure signature change doesn't break parent/child prop passing.
  • lib/email/company-emails.ts: Note that getRoleChangeEmail function appears duplicated in the diff—verify this is not an accidental duplication before merge. Review permissions map logic and HTML template formatting.
  • components/dashboard/TeamManagement.tsx: High-density toast migration with multiple call-site changes; verify all error/success branches are correctly mapped and the upgrade-detection logic properly returns early.

Possibly related PRs

Poem

🐰 A rabbit hops through profile data streams,
Role changes now whisper via email dreams,
Avatars hop into reusable slots,
Toasts pop with sonner, no more tangled knots,
The dashboard dances with Supabase delight!

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

📜 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 fd21917 and 456eabf.

📒 Files selected for processing (5)
  • app/api/companies/[slug]/members/[userId]/route.ts (2 hunks)
  • app/dashboard/company/layout.tsx (3 hunks)
  • components/dashboard/CompanySidebar.tsx (7 hunks)
  • components/dashboard/TeamManagement.tsx (7 hunks)
  • lib/email/company-emails.ts (3 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.

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