From e4a0bb47530d5968bb69d5aa9ae8bf7b76604d43 Mon Sep 17 00:00:00 2001 From: Regalijan Date: Sat, 4 Nov 2023 22:51:43 -0400 Subject: [PATCH] Generally fix up inactivity notices --- components/NewInactivityNotice.tsx | 69 +++++++++++++++++++----------- functions/api/inactivity/[id].ts | 4 +- 2 files changed, 47 insertions(+), 26 deletions(-) diff --git a/components/NewInactivityNotice.tsx b/components/NewInactivityNotice.tsx index 23971d7..7da1026 100644 --- a/components/NewInactivityNotice.tsx +++ b/components/NewInactivityNotice.tsx @@ -26,23 +26,22 @@ export default function (props: { }) { const [departments, setDepartments] = useState([] as string[]); const [loading, setLoading] = useState(false); + const [start, setStart] = useState(""); + const [end, setEnd] = useState(""); + const [reason, setReason] = useState(""); const [isHiatus, setIsHiatus] = useState(false); const toast = useToast(); function reset() { - (document.getElementById("start") as HTMLInputElement).value = ""; - (document.getElementById("end") as HTMLInputElement).value = ""; - (document.getElementById("reason") as HTMLTextAreaElement).value = ""; + setEnd(""); + setReason(""); + setStart(""); props.onClose(); } async function submit() { setLoading(true); - const start = (document.getElementById("start") as HTMLInputElement).value; - const end = (document.getElementById("end") as HTMLInputElement).value; - const reason = (document.getElementById("reason") as HTMLTextAreaElement) - .value; if (!departments.length) { toast({ @@ -55,6 +54,17 @@ export default function (props: { return; } + if (!start || !end || !reason) { + toast({ + description: "One or more fields are missing", + status: "error", + title: "Validation Error", + }); + + setLoading(false); + return; + } + const inactivityPost = await fetch("/api/inactivity/new", { body: JSON.stringify({ departments, @@ -90,7 +100,7 @@ export default function (props: { title: "Success", }); - setLoading(true); + setLoading(false); props.onClose(); } @@ -103,16 +113,26 @@ export default function (props: { Start Date - + setStart(e.target.value)} + type="date" + />

End Date - + setEnd(e.target.value)} + type="date" + />

Reason