Skip to content

Conversation

@elhalj
Copy link
Owner

@elhalj elhalj commented Sep 9, 2025

Summary

Implement a unified profile and preferences management UI with full CRUD support and route parameter handling

New Features:

  • Add tabbed Profile component with separate editable forms for profile info and preferences
  • Support viewing any user’s profile via /dashboard/profile/:id with loading, error handling, and own-vs-other distinction

Enhancements:

  • Refactor Profile state to use a single activeTab, initialize form values from currentUser, and improve form validation and UX
  • Extend AuthProvider and useAuth hook with getUserById, update updateProfile signature and endpoint, and align updatePreferences with new API contract
  • Add getUserById endpoint and refine updatePreference logic and responses in backend UserController
  • Update routing and header link to use profile ID parameter for profile pages

Chores:

  • Apply minor formatting and import adjustments, disable form buttons during loading, and update text labels for localization

@elhalj elhalj added the enhancement New feature or request label Sep 9, 2025
@netlify
Copy link

netlify bot commented Sep 9, 2025

Deploy Preview for colab-flow ready!

Name Link
🔨 Latest commit 5e0fd32
🔍 Latest deploy log https://app.netlify.com/projects/colab-flow/deploys/68c09bb821998100087018ed
😎 Deploy Preview https://deploy-preview-35--colab-flow.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify project configuration.

@sourcery-ai
Copy link

sourcery-ai bot commented Sep 9, 2025

Reviewer's Guide

This PR overhauls the profile and preference UIs into a unified tabbed interface, extends routing and data fetching to support viewing other users’ profiles, updates the Auth context/provider to handle userName and new backend calls, and synchronizes backend routes and controllers for profile and preference updates.

Sequence diagram for viewing another user's profile

sequenceDiagram
    actor User
    participant Frontend
    participant AuthProvider
    participant Backend
    User->>Frontend: Navigate to /dashboard/profile/:id
    Frontend->>AuthProvider: getUserById(id)
    AuthProvider->>Backend: GET /auth/user/:id
    Backend-->>AuthProvider: Return user data
    AuthProvider-->>Frontend: Return user data
    Frontend-->>User: Display profile UI for user
Loading

Sequence diagram for updating profile and preferences

sequenceDiagram
    actor User
    participant Frontend
    participant AuthProvider
    participant Backend
    User->>Frontend: Submit profile or preference form
    Frontend->>AuthProvider: updateProfile(...) or updatePreferences(...)
    AuthProvider->>Backend: PUT /auth/update/profile/:id or /auth/update/preference/:id
    Backend-->>AuthProvider: Return updated user data
    AuthProvider-->>Frontend: Update local state
    Frontend-->>User: Show updated profile/preference
Loading

Entity relationship diagram for updated User and Profile data types

erDiagram
    USER {
      string _id
      string userName
      string email
      Profile profile
      Preferences preferences
    }
    PROFILE {
      string userName
      string firstName
      string lastName
      string bio
      string phone
    }
    PREFERENCES {
      Notifications notifications
      string language
      string theme
    }
    NOTIFICATIONS {
      boolean email
      boolean push
      boolean taskUpdates
      boolean mention
    }
    USER ||--|{ PROFILE : has
    USER ||--|{ PREFERENCES : has
    PREFERENCES ||--|{ NOTIFICATIONS : has
Loading

Class diagram for updated AuthContext and related types

classDiagram
    class AuthContextType {
      user: User[]
      currentUser: User | null
      loading: boolean
      error: string
      login(email: string, password: string): Promise<void>
      register(userName: string, email: string, password: string): Promise<void>
      logout(): void
      getAllUser(): Promise<void>
      getUserById(id: string): Promise<User>
      updatePreferences(email: boolean, push: boolean, taskUpdates: boolean, mention: boolean, language: string, theme: string, profileId: string): Promise<void>
      updateProfile(userName: string, firstName: string, lastName: string, bio: string, phone: string, profileId: string): Promise<void>
    }
    class User {
      _id: string
      userName: string
      email: string
      profile: Profile
      preferences: Preferences
    }
    class Profile {
      userName: string
      firstName: string
      lastName: string
      bio: string
      phone: string
    }
    class Preferences {
      notifications: Notifications
      language: string
      theme: string
    }
    class Notifications {
      email: boolean
      push: boolean
      taskUpdates: boolean
      mention: boolean
    }
    AuthContextType o-- User
    User o-- Profile
    User o-- Preferences
    Preferences o-- Notifications
Loading

File-Level Changes

Change Details Files
Refactored Profile component to unify tabs and form logic
  • Replaced multiple boolean show states with a single activeTab state
  • Added useEffect to initialize preference and profile state from currentUser
  • Introduced userName field in profile state and form
  • Renamed notification to notifications and updated handlers and API calls accordingly
  • Enhanced form UI with back buttons, disabled styling, and localized labels
frontend/src/ui/profile/Profile.tsx
Enhanced ProfilePage to handle dynamic user profiles
  • Added useParams to read profile ID from URL
  • Fetched all users on mount and differentiated between own vs other profiles
  • Managed separate isLoading and errorMsg states for fetch flow
  • Displayed heading dynamically based on own or viewed user
frontend/src/pages/ProfilePage.tsx
Updated AuthProvider with extended updateProfile and getUserById
  • Modified updateProfile signature to include userName and new /auth/update/profile endpoint
  • Reorganized payload to wrap fields under a profile object
  • Added getUserById method with loading state and error handling
  • Included getUserById in provider value
frontend/src/context/AuthProvider.tsx
Added backend getUserById and improved updatePreference logic
  • Introduced getUserById action in UserController and corresponding route
  • Refined updatePreference to accept explicit notification fields and runValidators
  • Standardized HTTP status codes and error messages
  • Populated related fields and excluded password
src/controllers/user.controller.js
src/routes/user.route.js
Extended AuthContext and useAuth hook types for new methods
  • Added getUserById signature to AuthContextType with default value
  • Updated updateProfile and updatePreferences signatures in context and hook
  • Corrected typo in useAuth error message
  • Updated Profile interface to include userName
frontend/src/context/AuthContext.tsx
frontend/src/hook/useAuth.ts
frontend/src/types/user.ts
Minor routing and UI fixes
  • Adjusted Dashboard component formatting and imports
  • Wrapped username in Header with Link and updated NavLink import
  • Updated App route to use /dashboard/profile/:id
frontend/src/pages/Dashboard.tsx
frontend/src/components/Header.tsx
frontend/src/App.tsx

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

Copy link

@sourcery-ai sourcery-ai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey there - I've reviewed your changes - here's some feedback:

  • Profile.tsx has grown quite large and mixes tab logic, forms, and display—consider splitting it into smaller components (e.g., TabNavigation, ProfileForm, PreferenceForm) to improve readability and maintainability.
  • In ProfilePage.tsx you still fetch all users and then filter by id—since you added getUserById in the auth context, consider calling getUserById directly when an ID param is present to avoid loading the entire user list.
  • There’s a lot of duplicated form logic (state initialization, change handlers, error display) across the profile and preference forms—extract common hooks or subcomponents to reduce repetition and simplify the code.
Prompt for AI Agents
Please address the comments from this code review:
## Overall Comments
- Profile.tsx has grown quite large and mixes tab logic, forms, and display—consider splitting it into smaller components (e.g., TabNavigation, ProfileForm, PreferenceForm) to improve readability and maintainability.
- In ProfilePage.tsx you still fetch all users and then filter by id—since you added getUserById in the auth context, consider calling getUserById directly when an ID param is present to avoid loading the entire user list.
- There’s a lot of duplicated form logic (state initialization, change handlers, error display) across the profile and preference forms—extract common hooks or subcomponents to reduce repetition and simplify the code.

## Individual Comments

### Comment 1
<location> `src/controllers/user.controller.js:157` </location>
<code_context>

     const [preference, setPreference] = useState<Preference>({ 
-        notification: {
+        notifications: {
             email: false, 
             push: false, 
</code_context>

<issue_to_address>
Inconsistent naming for 'mentions' field may cause confusion or bugs.

Standardize the field name to 'mentions' throughout the codebase to prevent mismatches between frontend and backend.
</issue_to_address>

### Comment 2
<location> `frontend/src/context/AuthProvider.tsx:213` </location>
<code_context>
-      setLoading(false);
-    }
-  }, [])
+    const updatedUser = response.data?.updateProfile || response.data;
+    setCurrentUser(prev => ({
+      ...prev,
</code_context>

<issue_to_address>
Ambiguous response handling for updated profile data.

Relying on two possible response formats may cause inconsistencies. Standardize the backend response to always return updated user data in a consistent structure.
</issue_to_address>

### Comment 3
<location> `frontend/src/context/AuthProvider.tsx:243` </location>
<code_context>
+  const getUserById = useCallback(async (id: string) => {
+  try {
+    setLoading(true);
+    const res = await instance.get(`/auth/user/${id}`);
+    
+    console.log("API Response for user by ID:", res.data); // Debug
</code_context>

<issue_to_address>
Console log for debugging should be removed in production.

Consider removing or replacing the console.log with a proper logging mechanism to prevent exposure of sensitive data.
</issue_to_address>

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

Comment on lines +157 to +161
notifications: {
email,
push,
taskUpdates,
mentions: mention, // Note: In the model it's 'mentions' but in the request it's 'mention'
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

issue: Inconsistent naming for 'mentions' field may cause confusion or bugs.

Standardize the field name to 'mentions' throughout the codebase to prevent mismatches between frontend and backend.

setLoading(false);
}
}, [])
const updatedUser = response.data?.updateProfile || response.data;
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

issue: Ambiguous response handling for updated profile data.

Relying on two possible response formats may cause inconsistencies. Standardize the backend response to always return updated user data in a consistent structure.

const getUserById = useCallback(async (id: string) => {
try {
setLoading(true);
const res = await instance.get(`/auth/user/${id}`);
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nitpick: Console log for debugging should be removed in production.

Consider removing or replacing the console.log with a proper logging mechanism to prevent exposure of sensitive data.

@elhalj
Copy link
Owner Author

elhalj commented Sep 9, 2025

@sourcery-ai summary

@elhalj
Copy link
Owner Author

elhalj commented Sep 9, 2025

@sourcery-ai title

@sourcery-ai sourcery-ai bot changed the title add preference ui an profile ui Add user profile and preference management with ID-based routing Sep 9, 2025
@elhalj elhalj merged commit 9dbbcfa into main Sep 9, 2025
8 of 10 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants