Oh yeah I forgot the other half

This commit is contained in:
2023-10-19 16:50:58 -04:00
parent 387cf6a6b2
commit 0a4ad7792d
11 changed files with 96 additions and 13 deletions

View File

@ -13,11 +13,14 @@ import {
UnorderedList,
useToast
} from "@chakra-ui/react";
import { useState } from "react";
export default function(props: InactivityNoticeProps) {
const toast = useToast();
const [loading, setLoading] = useState(false)
async function makeDecision(accepted: boolean) {
setLoading(true)
const decisionReq = await fetch(`/api/inactivity/${props.id}`, {
body: JSON.stringify({ accepted }),
headers: {
@ -27,6 +30,7 @@ export default function(props: InactivityNoticeProps) {
});
if (!decisionReq.ok) {
setLoading(false)
toast({
description: ((await decisionReq.json()) as { error: string }).error,
isClosable: true,
@ -44,6 +48,7 @@ export default function(props: InactivityNoticeProps) {
title: "Success"
});
setLoading(false)
location.reload();
}
@ -103,6 +108,8 @@ export default function(props: InactivityNoticeProps) {
<Button
colorScheme="red"
onClick={async () => await makeDecision(false)}
isLoading={loading}
loadingText='Processing...'
>
Deny
</Button>
@ -110,6 +117,8 @@ export default function(props: InactivityNoticeProps) {
colorScheme="blue"
ml="8px"
onClick={async () => await makeDecision(true)}
isLoading={loading}
loadingText='Processing...'
>
Accept
</Button>