2024-03-20 16:36:24 +01:00
|
|
|
import { useState, useEffect } from "react";
|
|
|
|
import { useParams } from "react-router-dom";
|
2024-04-02 18:00:30 +02:00
|
|
|
import { api } from "../API/API";
|
|
|
|
import { projectTimes } from "./GetProjectTimes";
|
2024-03-20 16:36:24 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Renders the component for showing total time per role in a project.
|
|
|
|
* @returns JSX.Element
|
|
|
|
*/
|
|
|
|
export default function TimePerRole(): JSX.Element {
|
2024-04-03 18:05:30 +02:00
|
|
|
const [development, setDevelopment] = useState<number>(0);
|
|
|
|
const [meeting, setMeeting] = useState<number>(0);
|
|
|
|
const [admin, setAdmin] = useState<number>(0);
|
|
|
|
const [own_work, setOwnWork] = useState<number>(0);
|
|
|
|
const [study, setStudy] = useState<number>(0);
|
|
|
|
const [testing, setTesting] = useState<number>(0);
|
2024-04-14 15:52:13 +02:00
|
|
|
const total = development + meeting + admin + own_work + study + testing;
|
2024-04-02 18:00:30 +02:00
|
|
|
|
|
|
|
const token = localStorage.getItem("accessToken") ?? "";
|
2024-03-20 16:36:24 +01:00
|
|
|
const { projectName } = useParams();
|
|
|
|
|
|
|
|
const fetchTimePerActivity = async (): Promise<void> => {
|
2024-04-02 18:00:30 +02:00
|
|
|
const response = await api.getProjectTimes(projectName ?? "", token);
|
|
|
|
{
|
|
|
|
if (response.success) {
|
|
|
|
const report: projectTimes = response.data ?? {
|
|
|
|
development: 0,
|
|
|
|
meeting: 0,
|
|
|
|
admin: 0,
|
|
|
|
own_work: 0,
|
|
|
|
study: 0,
|
|
|
|
testing: 0,
|
|
|
|
};
|
|
|
|
setDevelopment(report.development);
|
|
|
|
setMeeting(report.meeting);
|
|
|
|
setAdmin(report.admin);
|
|
|
|
setOwnWork(report.own_work);
|
|
|
|
setStudy(report.study);
|
|
|
|
setTesting(report.testing);
|
|
|
|
} else {
|
|
|
|
console.error("Failed to fetch weekly report:", response.message);
|
|
|
|
}
|
|
|
|
}
|
2024-03-20 16:36:24 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
useEffect(() => {
|
|
|
|
void fetchTimePerActivity();
|
|
|
|
});
|
|
|
|
|
|
|
|
return (
|
|
|
|
<>
|
|
|
|
<h1 className="font-bold text-[30px] mb-[20px]">
|
2024-04-14 15:52:13 +02:00
|
|
|
Total Time Per Activity For All Members In: {projectName}{" "}
|
2024-03-20 16:36:24 +01:00
|
|
|
</h1>
|
|
|
|
<div className="border-4 border-black bg-white flex flex-col justify-start min-h-[65vh] h-fit w-[50vw] rounded-3xl overflow-scroll space-y-[2vh] p-[30px] items-center">
|
|
|
|
<div className="flex flex-col items-center">
|
|
|
|
<table className="w-full text-center divide-y divide-x divide-white text-[30px]">
|
|
|
|
<thead>
|
|
|
|
<tr>
|
|
|
|
<th className="w-1/2 py-2 border-b-2 border-black">Activity</th>
|
|
|
|
<th className="w-1/2 py-2 border-b-2 border-black">
|
|
|
|
Total Time (min)
|
|
|
|
</th>
|
|
|
|
</tr>
|
|
|
|
</thead>
|
|
|
|
<tbody className="divide-y divide-black">
|
|
|
|
<tr className="h-[10vh]">
|
|
|
|
<td>Development</td>
|
|
|
|
<td>
|
|
|
|
<input
|
|
|
|
type="string"
|
|
|
|
className="border-2 border-black rounded-md text-center w-1/2"
|
2024-04-02 18:02:40 +02:00
|
|
|
value={development}
|
2024-04-02 17:35:02 +02:00
|
|
|
readOnly
|
2024-03-20 16:36:24 +01:00
|
|
|
/>
|
|
|
|
</td>
|
|
|
|
</tr>
|
|
|
|
<tr className="h-[10vh]">
|
|
|
|
<td>Meeting</td>
|
|
|
|
<td>
|
|
|
|
<input
|
|
|
|
type="string"
|
|
|
|
className="border-2 border-black rounded-md text-center w-1/2"
|
2024-04-02 18:02:40 +02:00
|
|
|
value={meeting}
|
2024-04-02 17:35:02 +02:00
|
|
|
readOnly
|
2024-03-20 16:36:24 +01:00
|
|
|
/>
|
|
|
|
</td>
|
|
|
|
</tr>
|
|
|
|
<tr className="h-[10vh]">
|
|
|
|
<td>Administration</td>
|
|
|
|
<td>
|
|
|
|
<input
|
|
|
|
type="string"
|
|
|
|
className="border-2 border-black rounded-md text-center w-1/2"
|
2024-04-02 18:02:40 +02:00
|
|
|
value={admin}
|
2024-04-02 17:35:02 +02:00
|
|
|
readOnly
|
2024-03-20 16:36:24 +01:00
|
|
|
/>
|
|
|
|
</td>
|
|
|
|
</tr>
|
|
|
|
<tr className="h-[10vh]">
|
|
|
|
<td>Own Work</td>
|
|
|
|
<td>
|
|
|
|
<input
|
|
|
|
type="string"
|
|
|
|
className="border-2 border-black rounded-md text-center w-1/2"
|
2024-04-02 18:02:40 +02:00
|
|
|
value={own_work}
|
2024-04-02 17:35:02 +02:00
|
|
|
readOnly
|
2024-03-20 16:36:24 +01:00
|
|
|
/>
|
|
|
|
</td>
|
|
|
|
</tr>
|
|
|
|
<tr className="h-[10vh]">
|
|
|
|
<td>Studies</td>
|
|
|
|
<td>
|
|
|
|
<input
|
|
|
|
type="string"
|
|
|
|
className="border-2 border-black rounded-md text-center w-1/2"
|
2024-04-02 18:02:40 +02:00
|
|
|
value={study}
|
2024-04-02 17:35:02 +02:00
|
|
|
readOnly
|
2024-03-20 16:36:24 +01:00
|
|
|
/>
|
|
|
|
</td>
|
|
|
|
</tr>
|
|
|
|
<tr className="h-[10vh]">
|
|
|
|
<td>Testing</td>
|
|
|
|
<td>
|
|
|
|
<input
|
|
|
|
type="string"
|
|
|
|
className="border-2 border-black rounded-md text-center w-1/2"
|
2024-04-02 18:02:40 +02:00
|
|
|
value={testing}
|
2024-04-02 17:35:02 +02:00
|
|
|
readOnly
|
2024-03-20 16:36:24 +01:00
|
|
|
/>
|
|
|
|
</td>
|
|
|
|
</tr>
|
2024-04-14 15:52:13 +02:00
|
|
|
<tr className="h-[10vh] font-bold font-">
|
|
|
|
<td>In Total:</td>
|
|
|
|
<td>
|
|
|
|
<h1>{total}</h1>
|
|
|
|
</td>
|
|
|
|
</tr>
|
2024-03-20 16:36:24 +01:00
|
|
|
</tbody>
|
|
|
|
</table>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</>
|
|
|
|
);
|
|
|
|
}
|