Uses component to get projects now
This commit is contained in:
parent
f3466854c7
commit
17a571fd7c
1 changed files with 3 additions and 21 deletions
|
@ -1,29 +1,11 @@
|
||||||
import { useEffect, useState } from "react";
|
import { useState } from "react";
|
||||||
import { api } from "../API/API";
|
|
||||||
import { Project } from "../Types/goTypes";
|
import { Project } from "../Types/goTypes";
|
||||||
|
import GetProjects from "./GetProjects";
|
||||||
|
|
||||||
function UserProjectListAdmin(props: { username: string }): JSX.Element {
|
function UserProjectListAdmin(props: { username: string }): JSX.Element {
|
||||||
const [projects, setProjects] = useState<Project[]>([]);
|
const [projects, setProjects] = useState<Project[]>([]);
|
||||||
|
|
||||||
useEffect(() => {
|
GetProjects({ setProjectsProp: setProjects, username: props.username });
|
||||||
const fetchProjects = async (): Promise<void> => {
|
|
||||||
try {
|
|
||||||
const token = localStorage.getItem("accessToken") ?? "";
|
|
||||||
const username = props.username;
|
|
||||||
|
|
||||||
const response = await api.getUserProjects(username, token);
|
|
||||||
if (response.success) {
|
|
||||||
setProjects(response.data ?? []);
|
|
||||||
} else {
|
|
||||||
console.error("Failed to fetch projects:", response.message);
|
|
||||||
}
|
|
||||||
} catch (error) {
|
|
||||||
console.error("Error fetching projects:", error);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
void fetchProjects();
|
|
||||||
}, [props.username]);
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className="border-2 border-black bg-white p-2 rounded-lg text-center">
|
<div className="border-2 border-black bg-white p-2 rounded-lg text-center">
|
||||||
|
|
Loading…
Reference in a new issue