import { useState } from "react"; import { NewWeeklyReport } from "../Types/goTypes"; import { api } from "../API/API"; import { useNavigate, useParams } from "react-router-dom"; import Button from "./Button"; export default function NewWeeklyReport(): JSX.Element { 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 { projectName } = useParams(); const token = localStorage.getItem("accessToken") ?? ""; const handleNewWeeklyReport = async (): Promise => { const newWeeklyReport: NewWeeklyReport = { projectName: 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(-1); }} >
{ 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(); }} />
); }