Refactor input fields to handle empty values

This commit is contained in:
Davenludd 2024-03-21 10:25:27 +01:00
parent e2d2310275
commit 856ae40900

View file

@ -113,9 +113,14 @@ export default function GetWeeklyReport(): JSX.Element {
type="number"
min="0"
className="border-2 border-black rounded-md text-center w-1/2"
value={developmentTime}
value={developmentTime === 0 ? "" : developmentTime}
onChange={(e) => {
if (e.target.value === "") {
setDevelopmentTime(0);
return;
} else {
setDevelopmentTime(parseInt(e.target.value));
}
}}
onKeyDown={(event) => {
const keyValue = event.key;
@ -132,9 +137,14 @@ export default function GetWeeklyReport(): JSX.Element {
type="number"
min="0"
className="border-2 border-black rounded-md text-center w-1/2"
value={meetingTime}
value={meetingTime === 0 ? "" : meetingTime}
onChange={(e) => {
if (e.target.value === "") {
setMeetingTime(0);
return;
} else {
setMeetingTime(parseInt(e.target.value));
}
}}
onKeyDown={(event) => {
const keyValue = event.key;
@ -151,9 +161,14 @@ export default function GetWeeklyReport(): JSX.Element {
type="number"
min="0"
className="border-2 border-black rounded-md text-center w-1/2"
value={adminTime}
value={adminTime === 0 ? "" : adminTime}
onChange={(e) => {
if (e.target.value === "") {
setAdminTime(0);
return;
} else {
setAdminTime(parseInt(e.target.value));
}
}}
onKeyDown={(event) => {
const keyValue = event.key;
@ -170,9 +185,14 @@ export default function GetWeeklyReport(): JSX.Element {
type="number"
min="0"
className="border-2 border-black rounded-md text-center w-1/2"
value={ownWorkTime}
value={ownWorkTime === 0 ? "" : ownWorkTime}
onChange={(e) => {
if (e.target.value === "") {
setOwnWorkTime(0);
return;
} else {
setOwnWorkTime(parseInt(e.target.value));
}
}}
onKeyDown={(event) => {
const keyValue = event.key;
@ -189,9 +209,14 @@ export default function GetWeeklyReport(): JSX.Element {
type="number"
min="0"
className="border-2 border-black rounded-md text-center w-1/2"
value={studyTime}
value={studyTime === 0 ? "" : studyTime}
onChange={(e) => {
if (e.target.value === "") {
setStudyTime(0);
return;
} else {
setStudyTime(parseInt(e.target.value));
}
}}
onKeyDown={(event) => {
const keyValue = event.key;
@ -208,9 +233,14 @@ export default function GetWeeklyReport(): JSX.Element {
type="number"
min="0"
className="border-2 border-black rounded-md text-center w-1/2"
value={testingTime}
value={testingTime === 0 ? "" : testingTime}
onChange={(e) => {
if (e.target.value === "") {
setTestingTime(0);
return;
} else {
setTestingTime(parseInt(e.target.value));
}
}}
onKeyDown={(event) => {
const keyValue = event.key;