diff --git a/frontend/src/Components/UserStatistics.tsx b/frontend/src/Components/UserStatistics.tsx new file mode 100644 index 0000000..efb61d9 --- /dev/null +++ b/frontend/src/Components/UserStatistics.tsx @@ -0,0 +1,145 @@ +import { useState, useEffect } from "react"; +import { useParams } from "react-router-dom"; +import { api } from "../API/API"; +import { projectTimes } from "./GetProjectTimes"; + +/** + * Renders the component for showing total time per role in a project. + * @returns JSX.Element + */ +export default function TimePerRole(): JSX.Element { + const [development, setDevelopment] = useState(0); + const [meeting, setMeeting] = useState(0); + const [admin, setAdmin] = useState(0); + const [own_work, setOwnWork] = useState(0); + const [study, setStudy] = useState(0); + const [testing, setTesting] = useState(0); + const total = development + meeting + admin + own_work + study + testing; + + const token = localStorage.getItem("accessToken") ?? ""; + const { projectName } = useParams(); + + const fetchTimePerActivity = async (): Promise => { + 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); + } + } + }; + + useEffect(() => { + void fetchTimePerActivity(); + }); + + return ( + <> +

+ Total Time In: {projectName}{" "} +

+
+
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Activity + Total Time (min) +
Development + +
Meeting + +
Administration + +
Own Work + +
Studies + +
Testing + +
In Total: +

{total}

+
+
+
+ + ); +}