From ff07bd1ed6bb1ca0b6cb0f7e861e765bbba68e22 Mon Sep 17 00:00:00 2001 From: Davenludd Date: Tue, 9 Apr 2024 22:14:00 +0200 Subject: [PATCH] Update OtherUsersTR component to include unsign and delete functionality --- frontend/src/Components/OtherUsersTR.tsx | 68 +++++++++++++++++++++--- 1 file changed, 62 insertions(+), 6 deletions(-) diff --git a/frontend/src/Components/OtherUsersTR.tsx b/frontend/src/Components/OtherUsersTR.tsx index 4cbbd48..40e0b94 100644 --- a/frontend/src/Components/OtherUsersTR.tsx +++ b/frontend/src/Components/OtherUsersTR.tsx @@ -1,7 +1,7 @@ import { useState, useEffect } from "react"; import { WeeklyReport } from "../Types/goTypes"; import { api } from "../API/API"; -import { useParams } from "react-router-dom"; +import { useParams, useNavigate } from "react-router-dom"; import Button from "./Button"; /** @@ -18,6 +18,7 @@ export default function OtherUsersTR(): JSX.Element { const [ownWorkTime, setOwnWorkTime] = useState(0); const [studyTime, setStudyTime] = useState(0); const [testingTime, setTestingTime] = useState(0); + const [reportId, setReportId] = useState(0); const token = localStorage.getItem("accessToken") ?? ""; const { projectName } = useParams(); @@ -48,6 +49,7 @@ export default function OtherUsersTR(): JSX.Element { studyTime: 0, testingTime: 0, }; + setReportId(report.reportId); setWeek(report.week); setDevelopmentTime(report.developmentTime); setMeetingTime(report.meetingTime); @@ -63,6 +65,27 @@ export default function OtherUsersTR(): JSX.Element { void fetchUsersWeeklyReport(); }); + const handleUnsignWeeklyReport = async (): Promise => { + const response = await api.unsignReport(reportId, token); + console.log(response); + console.log(reportId); + if (response.success) { + return true; + } else { + return false; + } + }; + + const handleDeleteWeeklyReport = async (): Promise => { + const response = await api.deleteWeeklyReport(reportId, token); + console.log(response); + if (response.success) { + return true; + } + return false; + }; + const navigate = useNavigate(); + return ( <>

{username}'s Report

@@ -156,15 +179,48 @@ export default function OtherUsersTR(): JSX.Element { - {signedOrUnsigned === "signed" && ( +
+ {signedOrUnsigned === "signed" && ( +