TTime/frontend/src/Pages/YourProjectsPage.tsx

46 lines
1.4 KiB
TypeScript
Raw Normal View History

2024-03-19 09:14:30 +01:00
import { useState, useEffect } from "react";
2024-03-18 09:56:07 +01:00
import { Project } from "../Types/goTypes";
import { Link } from "react-router-dom";
import BasicWindow from "../Components/BasicWindow";
2024-03-19 09:14:30 +01:00
import { api } from "../API/API";
function UserProjectPage(): JSX.Element {
2024-03-18 23:36:59 +01:00
const [projects, setProjects] = useState<Project[]>([]);
2024-03-18 23:36:59 +01:00
const getProjects = async (): Promise<void> => {
const token = localStorage.getItem("accessToken") ?? "";
const response = await api.getUserProjects(token);
console.log(response);
if (response.success) {
setProjects(response.data ?? []);
} else {
console.error(response.message);
}
};
// Call getProjects when the component mounts
useEffect(() => {
2024-03-19 02:11:47 +01:00
void getProjects();
2024-03-18 23:36:59 +01:00
}, []);
2024-03-07 11:43:19 +01:00
const content = (
2024-03-19 09:14:30 +01:00
<>
2024-03-07 11:43:19 +01:00
<h1 className="font-bold text-[30px] mb-[20px]">Your Projects</h1>
<div className="border-4 border-black bg-white flex flex-col items-center justify-center min-h-[65vh] h-fit w-[50vw] rounded-3xl content-center overflow-scroll space-y-[10vh] p-[30px]">
{projects.map((project, index) => (
2024-03-19 09:14:30 +01:00
<Link to={`/project/${project.name}`} key={index}>
<h1 className="font-bold underline text-[30px] cursor-pointer">
{project.name}
</h1>
</Link>
))}
2024-03-07 11:43:19 +01:00
</div>
2024-03-19 09:14:30 +01:00
</>
);
2024-03-07 11:43:19 +01:00
const buttons = <></>;
return <BasicWindow content={content} buttons={buttons} />;
}
export default UserProjectPage;