Fix UserStatistics component to use new API.getStatistics function

This commit is contained in:
Davenludd 2024-04-14 15:47:26 +02:00
parent c96c0d7b4d
commit d1b6866c39

View file

@ -1,13 +1,13 @@
import { useState, useEffect } from "react"; import { useState, useEffect } from "react";
import { useParams } from "react-router-dom"; import { useParams } from "react-router-dom";
import { api } from "../API/API"; import { api } from "../API/API";
import { projectTimes } from "./GetProjectTimes"; import { Statistics } from "../Types/goTypes";
/** /**
* Renders the component for showing total time per role in a project. * Renders the component for showing total time per role in a project.
* @returns JSX.Element * @returns JSX.Element
*/ */
export default function TimePerRole(): JSX.Element { export default function UserStatistics(): JSX.Element {
const [development, setDevelopment] = useState<number>(0); const [development, setDevelopment] = useState<number>(0);
const [meeting, setMeeting] = useState<number>(0); const [meeting, setMeeting] = useState<number>(0);
const [admin, setAdmin] = useState<number>(0); const [admin, setAdmin] = useState<number>(0);
@ -20,23 +20,23 @@ export default function TimePerRole(): JSX.Element {
const { projectName } = useParams(); const { projectName } = useParams();
const fetchTimePerActivity = async (): Promise<void> => { const fetchTimePerActivity = async (): Promise<void> => {
const response = await api.getProjectTimes(projectName ?? "", token); const response = await api.getStatistics(projectName ?? "", token);
{ {
if (response.success) { if (response.success) {
const report: projectTimes = response.data ?? { const statistics: Statistics = response.data ?? {
development: 0, totalDevelopmentTime: 0,
meeting: 0, totalMeetingTime: 0,
admin: 0, totalAdminTime: 0,
own_work: 0, totalOwnWorkTime: 0,
study: 0, totalStudyTime: 0,
testing: 0, totalTestingTime: 0,
}; };
setDevelopment(report.development); setDevelopment(statistics.totalDevelopmentTime);
setMeeting(report.meeting); setMeeting(statistics.totalMeetingTime);
setAdmin(report.admin); setAdmin(statistics.totalAdminTime);
setOwnWork(report.own_work); setOwnWork(statistics.totalOwnWorkTime);
setStudy(report.study); setStudy(statistics.totalStudyTime);
setTesting(report.testing); setTesting(statistics.totalTestingTime);
} else { } else {
console.error("Failed to fetch weekly report:", response.message); console.error("Failed to fetch weekly report:", response.message);
} }