GetUsersInProject component
This commit is contained in:
parent
75e835895a
commit
056ca3660d
1 changed files with 37 additions and 0 deletions
37
frontend/src/Components/GetUsersInProject.tsx
Normal file
37
frontend/src/Components/GetUsersInProject.tsx
Normal file
|
@ -0,0 +1,37 @@
|
|||
import { Dispatch, useEffect } from "react";
|
||||
import { PublicUser } from "../Types/goTypes";
|
||||
import { api } from "../API/API";
|
||||
|
||||
/**
|
||||
* Gets all projects that user is a member of
|
||||
* @param props - A setStateAction for the array you want to put projects in
|
||||
* @returns {void} Nothing
|
||||
* @example
|
||||
* const [projects, setProjects] = useState<Project[]>([]);
|
||||
* GetAllUsers({ setProjectsProp: setProjects });
|
||||
*/
|
||||
function GetUsersInProject(props: {
|
||||
projectName: string;
|
||||
setUsersProp: Dispatch<React.SetStateAction<PublicUser[]>>;
|
||||
}): void {
|
||||
const setUsers: Dispatch<React.SetStateAction<PublicUser[]>> =
|
||||
props.setUsersProp;
|
||||
useEffect(() => {
|
||||
const fetchUsers = async (): Promise<void> => {
|
||||
try {
|
||||
const token = localStorage.getItem("accessToken") ?? "";
|
||||
const response = await api.getAllUsersProject(props.projectName, token);
|
||||
if (response.success) {
|
||||
setUsers(response.data ?? []);
|
||||
} else {
|
||||
console.error("Failed to fetch projects:", response.message);
|
||||
}
|
||||
} catch (error) {
|
||||
console.error("Error fetching projects:", error);
|
||||
}
|
||||
};
|
||||
void fetchUsers();
|
||||
}, [props.projectName, setUsers]);
|
||||
}
|
||||
|
||||
export default GetUsersInProject;
|
Loading…
Add table
Reference in a new issue