2024-03-17 14:19:57 +01:00
|
|
|
import { useState, useContext } from "react";
|
2024-03-17 13:39:16 +01:00
|
|
|
import { NewWeeklyReport } from "../Types/goTypes";
|
2024-03-16 13:10:46 +01:00
|
|
|
import { api } from "../API/API";
|
|
|
|
import { useNavigate } from "react-router-dom";
|
|
|
|
import Button from "./Button";
|
|
|
|
|
2024-03-17 14:19:57 +01:00
|
|
|
export default function NewWeeklyReport(): JSX.Element {
|
2024-03-17 13:39:16 +01:00
|
|
|
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);
|
2024-03-16 13:10:46 +01:00
|
|
|
|
2024-03-17 14:19:57 +01:00
|
|
|
const handleNewWeeklyReport = async (): Promise<void> => {
|
|
|
|
const newWeeklyReport: NewWeeklyReport = {
|
2024-03-17 13:39:16 +01:00
|
|
|
projectName,
|
2024-03-16 13:10:46 +01:00
|
|
|
week,
|
2024-03-17 13:39:16 +01:00
|
|
|
developmentTime,
|
|
|
|
meetingTime,
|
|
|
|
adminTime,
|
|
|
|
ownWorkTime,
|
|
|
|
studyTime,
|
|
|
|
testingTime,
|
2024-03-16 13:10:46 +01:00
|
|
|
};
|
|
|
|
await Promise.resolve();
|
2024-03-17 14:19:57 +01:00
|
|
|
//await api.submitWeeklyReport(newWeeklyReport, token); Token is not yet imported
|
2024-03-16 13:10:46 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
const navigate = useNavigate();
|
2024-03-14 13:21:19 +01:00
|
|
|
|
|
|
|
return (
|
|
|
|
<>
|
|
|
|
<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">
|
2024-03-16 13:10:46 +01:00
|
|
|
<form
|
|
|
|
onSubmit={(e) => {
|
2024-03-17 13:39:16 +01:00
|
|
|
if (week === 0) {
|
2024-03-16 13:10:46 +01:00
|
|
|
alert("Please enter a week number");
|
|
|
|
e.preventDefault();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
e.preventDefault();
|
2024-03-17 14:19:57 +01:00
|
|
|
void handleNewWeeklyReport();
|
2024-03-16 13:10:46 +01:00
|
|
|
navigate("/project");
|
2024-03-14 13:21:19 +01:00
|
|
|
}}
|
2024-03-16 13:10:46 +01:00
|
|
|
>
|
|
|
|
<div className="flex flex-col items-center">
|
|
|
|
<input
|
|
|
|
className="w-fill h-[5vh] font-sans text-[3vh] pl-[1vw] rounded-full text-center pt-[1vh] pb-[1vh] border-2 border-black"
|
|
|
|
type="week"
|
|
|
|
placeholder="Week"
|
|
|
|
onChange={(e) => {
|
2024-03-17 13:39:16 +01:00
|
|
|
const weekNumber = parseInt(e.target.value.split("-W")[1]);
|
2024-03-16 13:10:46 +01:00
|
|
|
setWeek(weekNumber);
|
|
|
|
}}
|
|
|
|
onKeyDown={(event) => {
|
|
|
|
event.preventDefault();
|
|
|
|
}}
|
|
|
|
onPaste={(event) => {
|
|
|
|
event.preventDefault();
|
|
|
|
}}
|
|
|
|
/>
|
|
|
|
<table className="w-full text-center divide-y divide-x divide-white text-[30px]">
|
|
|
|
<thead>
|
|
|
|
<tr>
|
|
|
|
<th className="w-1/2 py-2 border-b-2 border-black">
|
|
|
|
Activity
|
|
|
|
</th>
|
|
|
|
<th className="w-1/2 py-2 border-b-2 border-black">
|
|
|
|
Total Time (min)
|
|
|
|
</th>
|
|
|
|
</tr>
|
|
|
|
</thead>
|
|
|
|
<tbody className="divide-y divide-black">
|
|
|
|
<tr className="h-[10vh]">
|
|
|
|
<td>Development</td>
|
|
|
|
<td>
|
|
|
|
<input
|
|
|
|
type="number"
|
|
|
|
min="0"
|
|
|
|
className="border-2 border-black rounded-md text-center w-1/2"
|
2024-03-17 13:39:16 +01:00
|
|
|
value={developmentTime}
|
2024-03-16 13:10:46 +01:00
|
|
|
onChange={(e) => {
|
2024-03-17 13:39:16 +01:00
|
|
|
setDevelopmentTime(parseInt(e.target.value));
|
2024-03-16 13:10:46 +01:00
|
|
|
}}
|
|
|
|
onKeyDown={(event) => {
|
|
|
|
const keyValue = event.key;
|
|
|
|
if (!/\d/.test(keyValue) && keyValue !== "Backspace")
|
|
|
|
event.preventDefault();
|
|
|
|
}}
|
|
|
|
/>
|
|
|
|
</td>
|
|
|
|
</tr>
|
|
|
|
<tr className="h-[10vh]">
|
|
|
|
<td>Meeting</td>
|
|
|
|
<td>
|
|
|
|
<input
|
|
|
|
type="number"
|
|
|
|
min="0"
|
|
|
|
className="border-2 border-black rounded-md text-center w-1/2"
|
2024-03-17 13:39:16 +01:00
|
|
|
value={meetingTime}
|
2024-03-16 13:10:46 +01:00
|
|
|
onChange={(e) => {
|
2024-03-17 13:39:16 +01:00
|
|
|
setMeetingTime(parseInt(e.target.value));
|
2024-03-16 13:10:46 +01:00
|
|
|
}}
|
|
|
|
onKeyDown={(event) => {
|
|
|
|
const keyValue = event.key;
|
|
|
|
if (!/\d/.test(keyValue) && keyValue !== "Backspace")
|
|
|
|
event.preventDefault();
|
|
|
|
}}
|
|
|
|
/>
|
|
|
|
</td>
|
|
|
|
</tr>
|
|
|
|
<tr className="h-[10vh]">
|
|
|
|
<td>Administration</td>
|
|
|
|
<td>
|
|
|
|
<input
|
|
|
|
type="number"
|
|
|
|
min="0"
|
|
|
|
className="border-2 border-black rounded-md text-center w-1/2"
|
2024-03-17 13:39:16 +01:00
|
|
|
value={adminTime}
|
2024-03-16 13:10:46 +01:00
|
|
|
onChange={(e) => {
|
2024-03-17 13:39:16 +01:00
|
|
|
setAdminTime(parseInt(e.target.value));
|
2024-03-16 13:10:46 +01:00
|
|
|
}}
|
|
|
|
onKeyDown={(event) => {
|
|
|
|
const keyValue = event.key;
|
|
|
|
if (!/\d/.test(keyValue) && keyValue !== "Backspace")
|
|
|
|
event.preventDefault();
|
|
|
|
}}
|
|
|
|
/>
|
|
|
|
</td>
|
|
|
|
</tr>
|
|
|
|
<tr className="h-[10vh]">
|
|
|
|
<td>Own Work</td>
|
|
|
|
<td>
|
|
|
|
<input
|
|
|
|
type="number"
|
|
|
|
min="0"
|
|
|
|
className="border-2 border-black rounded-md text-center w-1/2"
|
2024-03-17 13:39:16 +01:00
|
|
|
value={ownWorkTime}
|
2024-03-16 13:10:46 +01:00
|
|
|
onChange={(e) => {
|
2024-03-17 13:39:16 +01:00
|
|
|
setOwnWorkTime(parseInt(e.target.value));
|
2024-03-16 13:10:46 +01:00
|
|
|
}}
|
|
|
|
onKeyDown={(event) => {
|
|
|
|
const keyValue = event.key;
|
|
|
|
if (!/\d/.test(keyValue) && keyValue !== "Backspace")
|
|
|
|
event.preventDefault();
|
|
|
|
}}
|
|
|
|
/>
|
|
|
|
</td>
|
|
|
|
</tr>
|
|
|
|
<tr className="h-[10vh]">
|
|
|
|
<td>Studies</td>
|
|
|
|
<td>
|
|
|
|
<input
|
|
|
|
type="number"
|
|
|
|
min="0"
|
|
|
|
className="border-2 border-black rounded-md text-center w-1/2"
|
2024-03-17 13:39:16 +01:00
|
|
|
value={studyTime}
|
2024-03-16 13:10:46 +01:00
|
|
|
onChange={(e) => {
|
2024-03-17 13:39:16 +01:00
|
|
|
setStudyTime(parseInt(e.target.value));
|
2024-03-16 13:10:46 +01:00
|
|
|
}}
|
|
|
|
onKeyDown={(event) => {
|
|
|
|
const keyValue = event.key;
|
|
|
|
if (!/\d/.test(keyValue) && keyValue !== "Backspace")
|
|
|
|
event.preventDefault();
|
|
|
|
}}
|
|
|
|
/>
|
|
|
|
</td>
|
|
|
|
</tr>
|
|
|
|
<tr className="h-[10vh]">
|
|
|
|
<td>Testing</td>
|
|
|
|
<td>
|
|
|
|
<input
|
|
|
|
type="number"
|
|
|
|
min="0"
|
|
|
|
className="border-2 border-black rounded-md text-center w-1/2"
|
2024-03-17 13:39:16 +01:00
|
|
|
value={testingTime}
|
2024-03-16 13:10:46 +01:00
|
|
|
onChange={(e) => {
|
2024-03-17 13:39:16 +01:00
|
|
|
setTestingTime(parseInt(e.target.value));
|
2024-03-16 13:10:46 +01:00
|
|
|
}}
|
|
|
|
onKeyDown={(event) => {
|
|
|
|
const keyValue = event.key;
|
|
|
|
if (!/\d/.test(keyValue) && keyValue !== "Backspace")
|
|
|
|
event.preventDefault();
|
|
|
|
}}
|
|
|
|
/>
|
|
|
|
</td>
|
|
|
|
</tr>
|
|
|
|
</tbody>
|
|
|
|
</table>
|
|
|
|
<Button
|
|
|
|
text="Submit"
|
|
|
|
onClick={(): void => {
|
|
|
|
return;
|
|
|
|
}}
|
|
|
|
type="submit"
|
|
|
|
/>
|
|
|
|
</div>
|
|
|
|
</form>
|
2024-03-14 13:21:19 +01:00
|
|
|
</div>
|
|
|
|
</>
|
|
|
|
);
|
|
|
|
}
|