Skip to content

Staging#169

Merged
Riyad-Murad merged 2 commits intomainfrom
staging
May 20, 2025
Merged

Staging#169
Riyad-Murad merged 2 commits intomainfrom
staging

Conversation

@Riyad-Murad
Copy link
Owner

@Riyad-Murad Riyad-Murad commented May 20, 2025

Summary by Sourcery

Fetch provider users from the API and display them in a reusable table component with basic styling and an edit action icon.

New Features:

  • Implement ProviderUsersService to retrieve users from the backend.
  • Integrate data fetching in ProviderUsers.jsx and manage user list state.
  • Add CustomTable component to render user data with column headers and an edit icon.

Enhancements:

  • Add CSS styles for CustomTable and adjust ProviderUsers layout margin.
  • Handle API errors by defaulting to an empty user list.

@sourcery-ai
Copy link

sourcery-ai bot commented May 20, 2025

Reviewer's Guide

This PR enhances the ProviderUsers page by introducing a data-fetching flow using hooks and a new service, and by rendering results in a reusable CustomTable component complete with styling and an edit icon.

Sequence Diagram for Fetching and Displaying Provider Users

sequenceDiagram
    participant PU as ProviderUsers Component
    participant PUS as ProviderUsersService
    participant Axios as AxiosInstance
    participant BE as Backend API

    activate PU
    PU->>PU: useEffect hook runs
    PU->>PUS: getAllUsers(userId)
    activate PUS
    PUS->>Axios: get("providers/getAllUsers/{userId}")
    activate Axios
    Axios->>BE: HTTP GET Request
    activate BE
    BE-->>Axios: HTTP Response (User Data)
    deactivate BE
    Axios-->>PUS: Response
    deactivate Axios
    PUS-->>PU: Formatted User Data (users[])
    deactivate PUS
    PU->>PU: setUsers(users)
    PU->>CustomTable Component: Render with users
    deactivate PU
Loading

Class Diagram for Frontend Components and User Data Structure

classDiagram
    class ProviderUsers {
        <<React Component>>
        -users: User[]
        -userId: String
        +useEffect()
        #_fetchUsers()
    }
    class ProviderUsersService {
        <<Service>>
        +getAllUsers(providerId: String): Promise<User[]>
    }
    class CustomTable {
        <<React Component>>
        +headers: String[]
        +data: User[]
    }
    class User {
        <<Data Structure>>
        +name: String
        +email: String
        +phone_number: String
    }
    class AxiosInstance {
        <<HTTP Client>>
        +get(url: String): Promise
    }

    ProviderUsers o--> CustomTable : Renders
    ProviderUsers ..> ProviderUsersService : Calls
    ProviderUsersService ..> AxiosInstance : Uses
    CustomTable ..> User : Data items are
Loading

File-Level Changes

Change Details Files
ProviderUsers component now fetches and displays user data
  • Imported useState, useEffect, useSelector, CustomTable, and service
  • Managed users state and Redux userId
  • Fetched users in useEffect and handled non-array responses
  • Defined table headers and rendered CustomTable with data
ProviderUsers.jsx
Added ProviderUsersService for API interactions
  • Created getAllUsers to call axiosInstance with providerId
  • Validated response data and handled errors by returning an empty array
ProviderUsersService.js
Created a reusable CustomTable component
  • Implemented table structure with headers and body rows
  • Integrated FontAwesome edit icon for actions
  • Exported component for use in ProviderUsers
CustomTable.jsx
styles.css (CustomTable)
Adjusted ProviderUsers styles
  • Added right margin to container
styles.css (ProviderUsers)

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

@Riyad-Murad Riyad-Murad merged commit 44045fc into main May 20, 2025
1 of 6 checks passed
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 @Riyad-Murad - I've reviewed your changes and they look great!

Here's what I looked at during the review
  • 🟡 General issues: 3 issues found
  • 🟢 Security: all looks good
  • 🟢 Testing: all looks good
  • 🟢 Documentation: all looks good

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.

const userId = useSelector((state) => state.user.id);
const { getAllUsers } = ProviderUsersService();

useEffect(() => {
Copy link

Choose a reason for hiding this comment

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

suggestion (bug_risk): Missing getAllUsers in effect dependencies

getAllUsers is recreated every render, so memoize it or include it in the effect’s dependency array with userId to avoid stale closures.

Comment on lines +12 to +15
} catch (error) {
console.error("Error fetching users:", error);
return [];
}
Copy link

Choose a reason for hiding this comment

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

suggestion (bug_risk): Silent failure on fetch errors

Returning [] hides fetch errors. Propagate the error or use a shared handler so the UI can display an error banner.

Suggested change
} catch (error) {
console.error("Error fetching users:", error);
return [];
}
} catch (error) {
console.error("Error fetching users:", error);
throw error;
}

<td>{user.email}</td>
<td>{user.phone_number}</td>
<td>
<FontAwesomeIcon icon={faPenToSquare} className="edit-icon" />
Copy link

Choose a reason for hiding this comment

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

suggestion (bug_risk): No action handler for edit icon

Pass an onEdit or onAction prop into CustomTable and attach it as the edit icon’s onClick handler to enable row-level actions.

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.

1 participant