From 966f8540dfcbac5395ecb7733a5fe005f4c64879 Mon Sep 17 00:00:00 2001 From: Mattias Date: Sat, 16 Mar 2024 13:10:46 +0100 Subject: [PATCH] Created groundwork for the timereport --- frontend/src/Components/TimeReport.tsx | 244 ++++++++++++++++++++----- 1 file changed, 194 insertions(+), 50 deletions(-) diff --git a/frontend/src/Components/TimeReport.tsx b/frontend/src/Components/TimeReport.tsx index c4ddc38..cb33ad9 100644 --- a/frontend/src/Components/TimeReport.tsx +++ b/frontend/src/Components/TimeReport.tsx @@ -1,59 +1,203 @@ -function NewTimeReport(): JSX.Element { - const activities = [ - "Development", - "Meeting", - "Administration", - "Own Work", - "Studies", - "Testing", - ]; +import { useState } from "react"; +import { TimeReport } from "../Types/TimeReport"; +import { api } from "../API/API"; +import { useNavigate } from "react-router-dom"; +import Button from "./Button"; + +export default function NewTimeReport(): JSX.Element { + const [week, setWeek] = useState(""); + const [development, setDevelopment] = useState("0"); + const [meeting, setMeeting] = useState("0"); + const [administration, setAdministration] = useState("0"); + const [ownwork, setOwnWork] = useState("0"); + const [studies, setStudies] = useState("0"); + const [testing, setTesting] = useState("0"); + + const handleNewTimeReport = async (): Promise => { + const newTimeReport: TimeReport = { + week, + development, + meeting, + administration, + ownwork, + studies, + testing, + }; + await Promise.resolve(); + // await api.registerTimeReport(newTimeReport); This needs to be implemented! + }; + + const navigate = useNavigate(); return ( <>
- { - event.preventDefault(); +
{ + if (week === "") { + alert("Please enter a week number"); + e.preventDefault(); + return; + } + e.preventDefault(); + void handleNewTimeReport(); + navigate("/project"); }} - onPaste={(event) => { - event.preventDefault(); - }} - /> - - - - - - - - - {activities.map((activity, index) => ( - - - - - ))} - -
Activity - Total Time (min) -
{activity} - { - const keyValue = event.key; - if (!/\d/.test(keyValue) && keyValue !== "Backspace") - event.preventDefault(); - }} - /> -
+ > +
+ { + const weekNumber = e.target.value.split("-W")[1]; + setWeek(weekNumber); + }} + onKeyDown={(event) => { + event.preventDefault(); + }} + onPaste={(event) => { + event.preventDefault(); + }} + /> + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ Activity + + Total Time (min) +
Development + { + setDevelopment(e.target.value); + }} + onKeyDown={(event) => { + const keyValue = event.key; + if (!/\d/.test(keyValue) && keyValue !== "Backspace") + event.preventDefault(); + }} + /> +
Meeting + { + setMeeting(e.target.value); + }} + onKeyDown={(event) => { + const keyValue = event.key; + if (!/\d/.test(keyValue) && keyValue !== "Backspace") + event.preventDefault(); + }} + /> +
Administration + { + setAdministration(e.target.value); + }} + onKeyDown={(event) => { + const keyValue = event.key; + if (!/\d/.test(keyValue) && keyValue !== "Backspace") + event.preventDefault(); + }} + /> +
Own Work + { + setOwnWork(e.target.value); + }} + onKeyDown={(event) => { + const keyValue = event.key; + if (!/\d/.test(keyValue) && keyValue !== "Backspace") + event.preventDefault(); + }} + /> +
Studies + { + setStudies(e.target.value); + }} + onKeyDown={(event) => { + const keyValue = event.key; + if (!/\d/.test(keyValue) && keyValue !== "Backspace") + event.preventDefault(); + }} + /> +
Testing + { + setTesting(e.target.value); + }} + onKeyDown={(event) => { + const keyValue = event.key; + if (!/\d/.test(keyValue) && keyValue !== "Backspace") + event.preventDefault(); + }} + /> +
+
+
); } - -export default NewTimeReport;