Corrected NewWeeklyReport (prev. TimeReports) and changed imports

This commit is contained in:
Mattias 2024-03-17 13:39:16 +01:00
parent 8d0da111eb
commit 62f1926305
5 changed files with 36 additions and 34 deletions

View file

@ -1,30 +1,32 @@
import { useState } from "react"; import { useState } from "react";
import { TimeReport } from "../Types/TimeReport"; import { NewWeeklyReport } from "../Types/goTypes";
import { api } from "../API/API"; import { api } from "../API/API";
import { useNavigate } from "react-router-dom"; import { useNavigate } from "react-router-dom";
import Button from "./Button"; import Button from "./Button";
export default function NewTimeReport(): JSX.Element { export default function NewTimeReport(): JSX.Element {
const [week, setWeek] = useState(""); const [projectName, setProjectName] = useState("");
const [development, setDevelopment] = useState("0"); const [week, setWeek] = useState(0);
const [meeting, setMeeting] = useState("0"); const [developmentTime, setDevelopmentTime] = useState(0);
const [administration, setAdministration] = useState("0"); const [meetingTime, setMeetingTime] = useState(0);
const [ownwork, setOwnWork] = useState("0"); const [adminTime, setAdminTime] = useState(0);
const [studies, setStudies] = useState("0"); const [ownWorkTime, setOwnWorkTime] = useState(0);
const [testing, setTesting] = useState("0"); const [studyTime, setStudyTime] = useState(0);
const [testingTime, setTestingTime] = useState(0);
const handleNewTimeReport = async (): Promise<void> => { const handleNewTimeReport = async (): Promise<void> => {
const newTimeReport: TimeReport = { const newTimeReport: NewWeeklyReport = {
projectName,
week, week,
development, developmentTime,
meeting, meetingTime,
administration, adminTime,
ownwork, ownWorkTime,
studies, studyTime,
testing, testingTime,
}; };
await Promise.resolve(); await Promise.resolve();
// await api.registerTimeReport(newTimeReport); This needs to be implemented! // await api.submitWeeklyReport(newTimeReport, token); Token is not defined yet
}; };
const navigate = useNavigate(); const navigate = useNavigate();
@ -34,7 +36,7 @@ export default function NewTimeReport(): JSX.Element {
<div className="border-4 border-black bg-white flex flex-col justify-start min-h-[65vh] h-fit w-[50vw] rounded-3xl overflow-scroll space-y-[2vh] p-[30px] items-center"> <div className="border-4 border-black bg-white flex flex-col justify-start min-h-[65vh] h-fit w-[50vw] rounded-3xl overflow-scroll space-y-[2vh] p-[30px] items-center">
<form <form
onSubmit={(e) => { onSubmit={(e) => {
if (week === "") { if (week === 0) {
alert("Please enter a week number"); alert("Please enter a week number");
e.preventDefault(); e.preventDefault();
return; return;
@ -50,7 +52,7 @@ export default function NewTimeReport(): JSX.Element {
type="week" type="week"
placeholder="Week" placeholder="Week"
onChange={(e) => { onChange={(e) => {
const weekNumber = e.target.value.split("-W")[1]; const weekNumber = parseInt(e.target.value.split("-W")[1]);
setWeek(weekNumber); setWeek(weekNumber);
}} }}
onKeyDown={(event) => { onKeyDown={(event) => {
@ -79,9 +81,9 @@ export default function NewTimeReport(): JSX.Element {
type="number" type="number"
min="0" min="0"
className="border-2 border-black rounded-md text-center w-1/2" className="border-2 border-black rounded-md text-center w-1/2"
value={development} value={developmentTime}
onChange={(e) => { onChange={(e) => {
setDevelopment(e.target.value); setDevelopmentTime(parseInt(e.target.value));
}} }}
onKeyDown={(event) => { onKeyDown={(event) => {
const keyValue = event.key; const keyValue = event.key;
@ -98,9 +100,9 @@ export default function NewTimeReport(): JSX.Element {
type="number" type="number"
min="0" min="0"
className="border-2 border-black rounded-md text-center w-1/2" className="border-2 border-black rounded-md text-center w-1/2"
value={meeting} value={meetingTime}
onChange={(e) => { onChange={(e) => {
setMeeting(e.target.value); setMeetingTime(parseInt(e.target.value));
}} }}
onKeyDown={(event) => { onKeyDown={(event) => {
const keyValue = event.key; const keyValue = event.key;
@ -117,9 +119,9 @@ export default function NewTimeReport(): JSX.Element {
type="number" type="number"
min="0" min="0"
className="border-2 border-black rounded-md text-center w-1/2" className="border-2 border-black rounded-md text-center w-1/2"
value={administration} value={adminTime}
onChange={(e) => { onChange={(e) => {
setAdministration(e.target.value); setAdminTime(parseInt(e.target.value));
}} }}
onKeyDown={(event) => { onKeyDown={(event) => {
const keyValue = event.key; const keyValue = event.key;
@ -136,9 +138,9 @@ export default function NewTimeReport(): JSX.Element {
type="number" type="number"
min="0" min="0"
className="border-2 border-black rounded-md text-center w-1/2" className="border-2 border-black rounded-md text-center w-1/2"
value={ownwork} value={ownWorkTime}
onChange={(e) => { onChange={(e) => {
setOwnWork(e.target.value); setOwnWorkTime(parseInt(e.target.value));
}} }}
onKeyDown={(event) => { onKeyDown={(event) => {
const keyValue = event.key; const keyValue = event.key;
@ -155,9 +157,9 @@ export default function NewTimeReport(): JSX.Element {
type="number" type="number"
min="0" min="0"
className="border-2 border-black rounded-md text-center w-1/2" className="border-2 border-black rounded-md text-center w-1/2"
value={studies} value={studyTime}
onChange={(e) => { onChange={(e) => {
setStudies(e.target.value); setStudyTime(parseInt(e.target.value));
}} }}
onKeyDown={(event) => { onKeyDown={(event) => {
const keyValue = event.key; const keyValue = event.key;
@ -174,9 +176,9 @@ export default function NewTimeReport(): JSX.Element {
type="number" type="number"
min="0" min="0"
className="border-2 border-black rounded-md text-center w-1/2" className="border-2 border-black rounded-md text-center w-1/2"
value={testing} value={testingTime}
onChange={(e) => { onChange={(e) => {
setTesting(e.target.value); setTestingTime(parseInt(e.target.value));
}} }}
onKeyDown={(event) => { onKeyDown={(event) => {
const keyValue = event.key; const keyValue = event.key;

View file

@ -1,6 +1,6 @@
import BasicWindow from "../../Components/BasicWindow"; import BasicWindow from "../../Components/BasicWindow";
import Button from "../../Components/Button"; import Button from "../../Components/Button";
import TimeReport from "../../Components/TimeReport"; import TimeReport from "../../Components/NewWeeklyReport";
function PMTotalTimeActivity(): JSX.Element { function PMTotalTimeActivity(): JSX.Element {
const content = ( const content = (

View file

@ -1,6 +1,6 @@
import BasicWindow from "../../Components/BasicWindow"; import BasicWindow from "../../Components/BasicWindow";
import Button from "../../Components/Button"; import Button from "../../Components/Button";
import TimeReport from "../../Components/TimeReport"; import TimeReport from "../../Components/NewWeeklyReport";
function PMViewUnsignedReport(): JSX.Element { function PMViewUnsignedReport(): JSX.Element {
const content = ( const content = (

View file

@ -1,6 +1,6 @@
import BasicWindow from "../../Components/BasicWindow"; import BasicWindow from "../../Components/BasicWindow";
import Button from "../../Components/Button"; import Button from "../../Components/Button";
import NewTimeReport from "../../Components/TimeReport"; import NewTimeReport from "../../Components/NewWeeklyReport";
function UserEditTimeReportPage(): JSX.Element { function UserEditTimeReportPage(): JSX.Element {
const content = ( const content = (

View file

@ -1,6 +1,6 @@
import BasicWindow from "../../Components/BasicWindow"; import BasicWindow from "../../Components/BasicWindow";
import Button from "../../Components/Button"; import Button from "../../Components/Button";
import NewTimeReport from "../../Components/TimeReport"; import NewTimeReport from "../../Components/NewWeeklyReport";
import { Link } from "react-router-dom"; import { Link } from "react-router-dom";
function UserNewTimeReportPage(): JSX.Element { function UserNewTimeReportPage(): JSX.Element {