From 3f8d56963ba03b25c25cd30fd5a8fdd003680aff Mon Sep 17 00:00:00 2001 From: Davenludd Date: Mon, 18 Mar 2024 12:49:58 +0100 Subject: [PATCH 01/10] Add ProjectNameContext to NewWeeklyReport and handle project selection in YourProjectsPage --- frontend/src/Components/NewWeeklyReport.tsx | 3 ++- frontend/src/Pages/YourProjectsPage.tsx | 25 +++++++++++++++++---- 2 files changed, 23 insertions(+), 5 deletions(-) diff --git a/frontend/src/Components/NewWeeklyReport.tsx b/frontend/src/Components/NewWeeklyReport.tsx index f5d92da..4f919aa 100644 --- a/frontend/src/Components/NewWeeklyReport.tsx +++ b/frontend/src/Components/NewWeeklyReport.tsx @@ -3,6 +3,7 @@ import { NewWeeklyReport } from "../Types/goTypes"; import { api } from "../API/API"; import { useNavigate } from "react-router-dom"; import Button from "./Button"; +import { ProjectNameContext } from "../Pages/YourProjectsPage"; export default function NewWeeklyReport(): JSX.Element { const [week, setWeek] = useState(0); @@ -13,7 +14,7 @@ export default function NewWeeklyReport(): JSX.Element { const [studyTime, setStudyTime] = useState(0); const [testingTime, setTestingTime] = useState(0); - // const projectName = useContext(projectNameContext); + const projectName = useContext(ProjectNameContext); const token = localStorage.getItem("accessToken") ?? ""; const handleNewWeeklyReport = async (): Promise => { diff --git a/frontend/src/Pages/YourProjectsPage.tsx b/frontend/src/Pages/YourProjectsPage.tsx index 30912a6..aabc606 100644 --- a/frontend/src/Pages/YourProjectsPage.tsx +++ b/frontend/src/Pages/YourProjectsPage.tsx @@ -1,11 +1,14 @@ -import React, { useState } from "react"; +import React, { useState, createContext, useEffect } from "react"; import { Project } from "../Types/goTypes"; import { api } from "../API/API"; import { Link } from "react-router-dom"; import BasicWindow from "../Components/BasicWindow"; +export const ProjectNameContext = createContext(""); + function UserProjectPage(): JSX.Element { const [projects, setProjects] = useState([]); + const [selectedProject, setSelectedProject] = useState(""); const getProjects = async (): Promise => { const username = localStorage.getItem("username") ?? ""; // replace with actual username @@ -18,20 +21,34 @@ function UserProjectPage(): JSX.Element { console.error(response.message); } }; + // Call getProjects when the component mounts + useEffect(() => { + getProjects(); + }, []); + + const handleProjectClick = (projectName: string): void => { + setSelectedProject(projectName); + }; const content = ( - <> +

Your Projects

{projects.map((project, index) => ( - + { + handleProjectClick(project.name); + }} + key={index} + >

{project.name}

))}
- +
); const buttons = <>; From 69d406720980d55b5bface33a47d89b24d413a40 Mon Sep 17 00:00:00 2001 From: Mattias Date: Mon, 18 Mar 2024 14:40:20 +0100 Subject: [PATCH 02/10] Added new component for viewing weeklyreport --- frontend/src/Components/ViewWeeklyReport.tsx | 243 +++++++++++++++++++ 1 file changed, 243 insertions(+) create mode 100644 frontend/src/Components/ViewWeeklyReport.tsx diff --git a/frontend/src/Components/ViewWeeklyReport.tsx b/frontend/src/Components/ViewWeeklyReport.tsx new file mode 100644 index 0000000..d6d4692 --- /dev/null +++ b/frontend/src/Components/ViewWeeklyReport.tsx @@ -0,0 +1,243 @@ +import { useState, useEffect } from "react"; +import { NewWeeklyReport } from "../Types/goTypes"; +import { api } from "../API/API"; +import { useNavigate } from "react-router-dom"; +import Button from "./Button"; + +export default function GetWeeklyReport(): JSX.Element { + const [projectName, setProjectName] = useState(""); + const [week, setWeek] = useState(0); + const [developmentTime, setDevelopmentTime] = useState(0); + const [meetingTime, setMeetingTime] = useState(0); + const [adminTime, setAdminTime] = useState(0); + const [ownWorkTime, setOwnWorkTime] = useState(0); + const [studyTime, setStudyTime] = useState(0); + const [testingTime, setTestingTime] = useState(0); + + const token = localStorage.getItem("accessToken") ?? ""; + + useEffect(() => { + const fetchWeeklyReport = async (): Promise => { + const response = await api.getWeeklyReport( + "username", + projectName, + "week", + token, + ); + + if (response.success) { + const report: NewWeeklyReport = response.data ?? { + projectName: "", + week: 0, + developmentTime: 0, + meetingTime: 0, + adminTime: 0, + ownWorkTime: 0, + studyTime: 0, + testingTime: 0, + }; + setProjectName(report.projectName); + setWeek(report.week); + setDevelopmentTime(report.developmentTime); + setMeetingTime(report.meetingTime); + setAdminTime(report.adminTime); + setOwnWorkTime(report.ownWorkTime); + setStudyTime(report.studyTime); + setTestingTime(report.testingTime); + } else { + console.error("Failed to fetch weekly report:", response.message); + } + }; + + fetchWeeklyReport(); + }, []); + + const handleNewWeeklyReport = async (): Promise => { + const newWeeklyReport: NewWeeklyReport = { + projectName, + week, + developmentTime, + meetingTime, + adminTime, + ownWorkTime, + studyTime, + testingTime, + }; + + await api.submitWeeklyReport(newWeeklyReport, token); + }; + + const navigate = useNavigate(); + + return ( + <> +
+
{ + if (week === 0) { + alert("Please enter a week number"); + e.preventDefault(); + return; + } + e.preventDefault(); + void handleNewWeeklyReport(); + navigate("/project"); + }} + > +
+ { + const weekNumber = parseInt(e.target.value.split("-W")[1]); + setWeek(weekNumber); + }} + onKeyDown={(event) => { + event.preventDefault(); + }} + onPaste={(event) => { + event.preventDefault(); + }} + /> + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ Activity + + Total Time (min) +
Development + { + setDevelopmentTime(parseInt(e.target.value)); + }} + onKeyDown={(event) => { + const keyValue = event.key; + if (!/\d/.test(keyValue) && keyValue !== "Backspace") + event.preventDefault(); + }} + /> +
Meeting + { + setMeetingTime(parseInt(e.target.value)); + }} + onKeyDown={(event) => { + const keyValue = event.key; + if (!/\d/.test(keyValue) && keyValue !== "Backspace") + event.preventDefault(); + }} + /> +
Administration + { + setAdminTime(parseInt(e.target.value)); + }} + onKeyDown={(event) => { + const keyValue = event.key; + if (!/\d/.test(keyValue) && keyValue !== "Backspace") + event.preventDefault(); + }} + /> +
Own Work + { + setOwnWorkTime(parseInt(e.target.value)); + }} + onKeyDown={(event) => { + const keyValue = event.key; + if (!/\d/.test(keyValue) && keyValue !== "Backspace") + event.preventDefault(); + }} + /> +
Studies + { + setStudyTime(parseInt(e.target.value)); + }} + onKeyDown={(event) => { + const keyValue = event.key; + if (!/\d/.test(keyValue) && keyValue !== "Backspace") + event.preventDefault(); + }} + /> +
Testing + { + setTestingTime(parseInt(e.target.value)); + }} + onKeyDown={(event) => { + const keyValue = event.key; + if (!/\d/.test(keyValue) && keyValue !== "Backspace") + event.preventDefault(); + }} + /> +
+
+
+
+ + ); +} From 0634f836893470d4297cc8f0373b2e5d128f52b9 Mon Sep 17 00:00:00 2001 From: Mattias Date: Mon, 18 Mar 2024 14:40:32 +0100 Subject: [PATCH 03/10] Now displaying the right component --- frontend/src/Pages/UserPages/UserEditTimeReportPage.tsx | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/frontend/src/Pages/UserPages/UserEditTimeReportPage.tsx b/frontend/src/Pages/UserPages/UserEditTimeReportPage.tsx index d82ea8c..9da19fe 100644 --- a/frontend/src/Pages/UserPages/UserEditTimeReportPage.tsx +++ b/frontend/src/Pages/UserPages/UserEditTimeReportPage.tsx @@ -1,13 +1,13 @@ import BasicWindow from "../../Components/BasicWindow"; import Button from "../../Components/Button"; import BackButton from "../../Components/BackButton"; -import NewTimeReport from "../../Components/NewWeeklyReport"; +import ViewWeeklyReport from "../../Components/ViewWeeklyReport"; function UserEditTimeReportPage(): JSX.Element { const content = ( <>

Edit Time Report

- + ); From b82f73d192f4c7a3f8f09229e02c2ab165258562 Mon Sep 17 00:00:00 2001 From: Mattias Date: Mon, 18 Mar 2024 14:42:21 +0100 Subject: [PATCH 04/10] Removed button --- frontend/src/Pages/UserPages/UserEditTimeReportPage.tsx | 8 -------- 1 file changed, 8 deletions(-) diff --git a/frontend/src/Pages/UserPages/UserEditTimeReportPage.tsx b/frontend/src/Pages/UserPages/UserEditTimeReportPage.tsx index 9da19fe..0acef75 100644 --- a/frontend/src/Pages/UserPages/UserEditTimeReportPage.tsx +++ b/frontend/src/Pages/UserPages/UserEditTimeReportPage.tsx @@ -1,5 +1,4 @@ import BasicWindow from "../../Components/BasicWindow"; -import Button from "../../Components/Button"; import BackButton from "../../Components/BackButton"; import ViewWeeklyReport from "../../Components/ViewWeeklyReport"; @@ -13,13 +12,6 @@ function UserEditTimeReportPage(): JSX.Element { const buttons = ( <> -