-
Notifications
You must be signed in to change notification settings - Fork 1
Staging #169
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Staging #169
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,32 @@ | ||
| // src/Components/CommonComponents/CustomTable/CustomTable.jsx | ||
| import "./styles.css"; | ||
| import { FontAwesomeIcon } from "@fortawesome/react-fontawesome"; | ||
| import { faPenToSquare } from "@fortawesome/free-solid-svg-icons"; | ||
|
|
||
| const CustomTable = ({ headers, data }) => { | ||
| return ( | ||
| <table className="custom-table"> | ||
| <thead> | ||
| <tr> | ||
| {headers.map((header, idx) => ( | ||
| <th key={idx}>{header}</th> | ||
| ))} | ||
| </tr> | ||
| </thead> | ||
| <tbody> | ||
| {data.map((user, idx) => ( | ||
| <tr key={idx}> | ||
| <td>{user.name}</td> | ||
| <td>{user.email}</td> | ||
| <td>{user.phone_number}</td> | ||
| <td> | ||
| <FontAwesomeIcon icon={faPenToSquare} className="edit-icon" /> | ||
| </td> | ||
| </tr> | ||
| ))} | ||
| </tbody> | ||
| </table> | ||
| ); | ||
| }; | ||
|
|
||
| export default CustomTable; | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,29 @@ | ||
| /* CustomTable.css */ | ||
| .custom-table { | ||
| width: 100%; | ||
| border-collapse: collapse; | ||
| margin-top: 20px; | ||
| } | ||
|
|
||
| .custom-table thead tr { | ||
| background-color: #f9a43a; | ||
| color: #000000; | ||
| text-align: left; | ||
| } | ||
|
|
||
| .custom-table th, | ||
| .custom-table td { | ||
| padding: 12px 15px; | ||
| } | ||
|
|
||
| .custom-table tbody tr { | ||
| background-color: #fff9f3; | ||
| color: #000000; | ||
| border-bottom: 1px solid #ddd; | ||
| } | ||
|
|
||
| .edit-icon { | ||
| cursor: pointer; | ||
| color: #000000; | ||
| font-size: 18px; | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,14 +1,31 @@ | ||
| import "./styles.css"; | ||
| import { useEffect, useState } from "react"; | ||
| import { useSelector } from "react-redux"; | ||
| import CustomTable from "../../../Components/CommonComponents/CustomTable/CustomTable"; | ||
| import ProviderUsersService from "../Services/ProviderUsersService/ProviderUsersService"; | ||
|
|
||
| const ProviderUsers = () => { | ||
| const [users, setUsers] = useState([]); | ||
| const userId = useSelector((state) => state.user.id); | ||
| const { getAllUsers } = ProviderUsersService(); | ||
|
|
||
| useEffect(() => { | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. |
||
| const fetchUsers = async () => { | ||
| const fetched = await getAllUsers(userId); | ||
| setUsers(Array.isArray(fetched) ? fetched : []); | ||
| }; | ||
| fetchUsers(); | ||
| }, [userId]); | ||
|
|
||
| const tableHeaders = ["Full Name", "Email", "Phone Number", "Actions"]; | ||
|
|
||
| return ( | ||
| <> | ||
| <div className="provider-users-container"> | ||
| <div className="main-content"> | ||
| <h1 className="main-content-title section-titles">Users</h1> | ||
| </div> | ||
| <div className="provider-users-container"> | ||
| <div className="main-content"> | ||
| <h1 className="main-content-title section-titles">Users</h1> | ||
| <CustomTable headers={tableHeaders} data={users} /> | ||
| </div> | ||
| </> | ||
| </div> | ||
| ); | ||
| }; | ||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -2,4 +2,5 @@ | |
| .provider-users-container { | ||
| display: flex; | ||
| flex-direction: row; | ||
| margin-right: 15px; | ||
| } | ||
| Original file line number | Diff line number | Diff line change | ||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -1 +1,21 @@ | ||||||||||||||||||
| import axiosInstance from "../../../../Axios/axios"; | ||||||||||||||||||
| // src/Pages/Provider/Services/ProviderUsers/ProviderUsersService.js | ||||||||||||||||||
| import axiosInstance from "../../../../Axios/axios"; | ||||||||||||||||||
|
|
||||||||||||||||||
| const ProviderUsersService = () => { | ||||||||||||||||||
| const getAllUsers = async (providerId) => { | ||||||||||||||||||
| try { | ||||||||||||||||||
| const response = await axiosInstance.get( | ||||||||||||||||||
| `providers/getAllUsers/${providerId}` | ||||||||||||||||||
| ); | ||||||||||||||||||
| // Access the correct data field | ||||||||||||||||||
| return Array.isArray(response.data.data) ? response.data.data : []; | ||||||||||||||||||
| } catch (error) { | ||||||||||||||||||
| console.error("Error fetching users:", error); | ||||||||||||||||||
| return []; | ||||||||||||||||||
| } | ||||||||||||||||||
|
Comment on lines
+12
to
+15
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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
|
||||||||||||||||||
| }; | ||||||||||||||||||
|
|
||||||||||||||||||
| return { getAllUsers }; | ||||||||||||||||||
| }; | ||||||||||||||||||
|
|
||||||||||||||||||
| export default ProviderUsersService; | ||||||||||||||||||
There was a problem hiding this comment.
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.