-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refactor UserManagementPage component and UserAPIClient
- Add useEffect and useState to UserManagementPage component to fetch and display users - Update UserManagementPage component UI to display a table of users - Add fetchUsers function to UserManagementPage component to fetch users from the backend - Create UserAPIClient module to handle API requests for user data - Implement get function in UserAPIClient to fetch users from the backend - Define User type in UserTypes module to represent user data
- Loading branch information
1 parent
ff1a9b7
commit c79c2af
Showing
3 changed files
with
90 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
import axios from "axios"; | ||
import { User } from "../types/UserTypes"; | ||
import { getLocalStorageObj } from "../utils/LocalStorageUtils"; | ||
import AUTHENTICATED_USER_KEY from "../constants/AuthConstants"; | ||
|
||
const baseURL = process.env.REACT_APP_BACKEND_URL; | ||
|
||
const get = async (): Promise<User[]> => { | ||
try { | ||
const currentUser: { accessToken?: string } = | ||
getLocalStorageObj(AUTHENTICATED_USER_KEY) || {}; | ||
const accessToken = currentUser?.accessToken; | ||
|
||
const { data } = await axios.get(`${baseURL}/users`, { | ||
headers: { | ||
Authorization: `Bearer ${accessToken}`, | ||
}, | ||
withCredentials: true, | ||
}); | ||
|
||
return data; | ||
} catch (error) { | ||
throw new Error(`Failed to get users: ${error}`); | ||
} | ||
}; | ||
|
||
export default { get }; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
export type User = { | ||
id: number; | ||
firstName: string; | ||
lastName: string; | ||
email: string; | ||
role: string; | ||
status: string; | ||
}; |