2024-03-21 12:46:05 +01:00
|
|
|
//Info: This component is used to display all the time reports for a project. It will display the week number,
|
|
|
|
//total time spent, and if the report has been signed or not. The user can click on a report to edit it.
|
|
|
|
import { useEffect, useState } from "react";
|
2024-03-21 13:59:10 +01:00
|
|
|
import { NewWeeklyReport } from "../Types/goTypes";
|
2024-03-21 12:46:05 +01:00
|
|
|
import { Link, useParams } from "react-router-dom";
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Renders a component that displays all the time reports for a specific project.
|
|
|
|
* @returns {JSX.Element} representing the component.
|
|
|
|
*/
|
|
|
|
function AllTimeReportsInProject(): JSX.Element {
|
2024-03-21 13:59:10 +01:00
|
|
|
const { username } = useParams();
|
2024-03-21 12:46:05 +01:00
|
|
|
const { projectName } = useParams();
|
2024-03-21 13:59:10 +01:00
|
|
|
const [weeklyReports, setWeeklyReports] = useState<NewWeeklyReport[]>([]);
|
2024-03-21 12:46:05 +01:00
|
|
|
|
2024-03-21 13:59:10 +01:00
|
|
|
/* // Call getProjects when the component mounts
|
2024-03-21 12:46:05 +01:00
|
|
|
useEffect(() => {
|
|
|
|
const getWeeklyReports = async (): Promise<void> => {
|
|
|
|
const token = localStorage.getItem("accessToken") ?? "";
|
|
|
|
const response = await api.getWeeklyReportsForUser(
|
|
|
|
projectName ?? "",
|
|
|
|
token,
|
|
|
|
);
|
|
|
|
console.log(response);
|
|
|
|
if (response.success) {
|
|
|
|
setWeeklyReports(response.data ?? []);
|
|
|
|
} else {
|
|
|
|
console.error(response.message);
|
|
|
|
}
|
2024-03-21 13:59:10 +01:00
|
|
|
}; */
|
|
|
|
// Mock data
|
|
|
|
const getWeeklyReports = async (): Promise<void> => {
|
|
|
|
// Simulate a delay
|
|
|
|
await Promise.resolve();
|
|
|
|
const mockWeeklyReports: NewWeeklyReport[] = [
|
|
|
|
{
|
|
|
|
projectName: "Project 1",
|
|
|
|
week: 1,
|
|
|
|
developmentTime: 10,
|
|
|
|
meetingTime: 2,
|
|
|
|
adminTime: 1,
|
|
|
|
ownWorkTime: 3,
|
|
|
|
studyTime: 4,
|
|
|
|
testingTime: 5,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
projectName: "Project 1",
|
|
|
|
week: 2,
|
|
|
|
developmentTime: 8,
|
|
|
|
meetingTime: 2,
|
|
|
|
adminTime: 1,
|
|
|
|
ownWorkTime: 3,
|
|
|
|
studyTime: 4,
|
|
|
|
testingTime: 5,
|
|
|
|
},
|
|
|
|
// Add more reports as needed
|
|
|
|
];
|
2024-03-21 12:46:05 +01:00
|
|
|
|
2024-03-21 13:59:10 +01:00
|
|
|
// Use the mock data instead of the real data
|
|
|
|
setWeeklyReports(mockWeeklyReports);
|
|
|
|
};
|
|
|
|
useEffect(() => {
|
2024-03-21 12:46:05 +01:00
|
|
|
void getWeeklyReports();
|
2024-03-21 13:59:10 +01:00
|
|
|
}, []);
|
2024-03-21 12:46:05 +01:00
|
|
|
|
|
|
|
return (
|
|
|
|
<>
|
2024-03-21 13:59:10 +01:00
|
|
|
<h1 className="text-[30px] font-bold">{username}'s Time Reports</h1>
|
2024-03-21 12:46:05 +01:00
|
|
|
<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] text-[30px]">
|
|
|
|
{weeklyReports.map((newWeeklyReport, index) => (
|
|
|
|
<Link
|
2024-03-21 13:59:10 +01:00
|
|
|
to={`/editOthersTR/${projectName}/${username}/${newWeeklyReport.week}`}
|
2024-03-21 12:46:05 +01:00
|
|
|
key={index}
|
|
|
|
className="border-b-2 border-black w-full"
|
|
|
|
>
|
|
|
|
<div className="flex justify-between">
|
|
|
|
<h1>
|
|
|
|
<span className="font-bold">{"Week: "}</span>
|
|
|
|
{newWeeklyReport.week}
|
|
|
|
</h1>
|
|
|
|
<h1>
|
|
|
|
<span className="font-bold">{"Total Time: "}</span>
|
|
|
|
{newWeeklyReport.developmentTime +
|
|
|
|
newWeeklyReport.meetingTime +
|
|
|
|
newWeeklyReport.adminTime +
|
|
|
|
newWeeklyReport.ownWorkTime +
|
|
|
|
newWeeklyReport.studyTime +
|
|
|
|
newWeeklyReport.testingTime}{" "}
|
|
|
|
min
|
|
|
|
</h1>
|
|
|
|
<h1>
|
|
|
|
<span className="font-bold">{"Signed: "}</span>
|
2024-03-21 13:59:10 +01:00
|
|
|
NO
|
2024-03-21 12:46:05 +01:00
|
|
|
</h1>
|
|
|
|
</div>
|
|
|
|
</Link>
|
|
|
|
))}
|
|
|
|
</div>
|
|
|
|
</>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
export default AllTimeReportsInProject;
|