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
diff --git a/functions/api/inactivity/[id].ts b/functions/api/inactivity/[id].ts
index ecd3bed..f9de2db 100644
--- a/functions/api/inactivity/[id].ts
+++ b/functions/api/inactivity/[id].ts
@@ -67,7 +67,7 @@ export async function onRequestPost(context: RequestContext) {
if (Object.values(decisions).length === requestedNotice.departments.length) {
requestedNotice.open = false;
- const approved = !Object.values(decisions).find((d) => !d);
+ const approved = !Object.values(decisions).filter((d) => !d).length;
await context.env.D1.prepare(
"UPDATE inactivity_notices SET approved = ?, open = 0 WHERE id = ?;",
@@ -81,7 +81,7 @@ export async function onRequestPost(context: RequestContext) {
`Inactivity Request ${approved ? "Approved" : "Denied"}`,
accepted
? "Your inactivity request was approved."
- : "Your inactivity request was denied, please reach to management if you require more details.",
+ : "Your inactivity request was denied, please reach out to management if you require more details.",
requestedNotice.fcm_token,
);
} else {