From 4fa6cc2c99338a691f1e5197a48109acdc350d37 Mon Sep 17 00:00:00 2001 From: regalijan Date: Thu, 19 Oct 2023 16:50:50 -0400 Subject: [PATCH] Fix toasts and actually close on submit on inactivity notice modal --- components/NewInactivityNotice.tsx | 27 +++++++++++++++++---------- 1 file changed, 17 insertions(+), 10 deletions(-) diff --git a/components/NewInactivityNotice.tsx b/components/NewInactivityNotice.tsx index 93a206a..9d7a6bc 100644 --- a/components/NewInactivityNotice.tsx +++ b/components/NewInactivityNotice.tsx @@ -12,16 +12,18 @@ import { Text, Textarea, useToast, - VStack, + VStack } from "@chakra-ui/react"; import { useState } from "react"; -export default function (props: { +export default function(props: { departments: string[]; isOpen: boolean; onClose: () => void; }) { const [departments, setDepartments] = useState([] as string[]); + const toast = useToast(); + function reset() { (document.getElementById("start") as HTMLInputElement).value = ""; (document.getElementById("end") as HTMLInputElement).value = ""; @@ -43,30 +45,35 @@ export default function (props: { body: JSON.stringify({ end, reason, - start, + start }), headers: { - "content-type": "application/json", + "content-type": "application/json" }, - method: "POST", + method: "POST" }); - if (!inactivityPost.ok) - return useToast()({ + if (!inactivityPost.ok) { + toast({ description: ((await inactivityPost.json()) as { error: string }).error, duration: 10000, isClosable: true, status: "error", - title: "Error", + title: "Error" }); - useToast()({ + return; + } + + toast({ description: "Your inactivity notice has been created", duration: 10000, isClosable: true, status: "success", - title: "Success", + title: "Success" }); + + props.onClose(); } return (