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

@ -27,6 +27,7 @@ export default function (props: AppealCardProps) {
);
const [action, setAction] = useState("");
const [feedback, setFeedback] = useState("");
const [loading, setLoading] = useState(false)
const toast = useToast();
useEffect(() => {
@ -41,6 +42,7 @@ export default function (props: AppealCardProps) {
}
async function takeAction(action: string) {
setLoading(true)
const actionReq = await fetch(`/api/appeals/${props.id}/${action}`, {
body: feedback ? JSON.stringify({ feedback }) : "{}",
headers: {
@ -50,6 +52,7 @@ export default function (props: AppealCardProps) {
});
if (actionReq.ok) {
setLoading(false)
toast({
description: `Appeal ${action === "accept" ? "accepted" : "denied"}`,
duration: 5000,
@ -59,6 +62,7 @@ export default function (props: AppealCardProps) {
document.getElementById(`appeal_${props.id}`)?.remove();
} else {
setLoading(false)
toast({
description: ((await actionReq.json()) as { error: string }).error,
duration: 10000,
@ -68,6 +72,7 @@ export default function (props: AppealCardProps) {
}
onClose();
setLoading(false)
}
return (
@ -86,6 +91,8 @@ export default function (props: AppealCardProps) {
<ModalFooter>
<Button
onClick={async () => await takeAction(action.toLowerCase())}
isLoading={loading}
loadingText='Submitting...'
>
Submit
</Button>

View File

@ -18,9 +18,12 @@ import {
useDisclosure,
useToast,
} from "@chakra-ui/react";
import { useState } from "react";
export default function (props: GameAppealProps) {
const [loading, setLoading] = useState(false)
async function performAction(action: "accept" | "deny"): Promise<void> {
setLoading(true)
const statsReduction = parseInt(
(document.getElementById("reductPercentage") as HTMLInputElement).value,
);
@ -51,6 +54,8 @@ export default function (props: GameAppealProps) {
title: "An error occurred...",
},
);
setLoading(false)
}
const { isOpen, onClose, onOpen } = useDisclosure();
@ -108,6 +113,8 @@ export default function (props: GameAppealProps) {
colorScheme="blue"
ml="8px"
onClick={async () => await performAction("accept")}
isLoading={loading}
loadingText='Submitting...'
>
Submit
</Button>

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>

View File

@ -27,6 +27,7 @@ import { useState } from "react";
export default function(props: { isOpen: boolean; onClose: () => void }) {
const actionMap: { [k: string]: number } = {};
const [users, setUsers] = useState([] as string[]);
const [loading, setLoading] = useState(true)
const toast = useToast();
const fileTypes: { [k: string]: string } = {
gif: "image/gif",
@ -79,6 +80,7 @@ export default function(props: { isOpen: boolean; onClose: () => void }) {
}
async function submit() {
setLoading(true)
const actions: number[] = [];
const usernames: string[] = [];
@ -92,7 +94,10 @@ export default function(props: { isOpen: boolean; onClose: () => void }) {
const files = (document.getElementById("evidence") as HTMLInputElement)
.files;
if (!files) return;
if (!files) {
setLoading(false)
return
}
const [evidence] = files;
@ -111,6 +116,7 @@ export default function(props: { isOpen: boolean; onClose: () => void }) {
});
if (!submitReq.ok) {
setLoading(false)
toast({
description: ((await submitReq.json()) as { error: string }).error,
status: "error",
@ -135,6 +141,7 @@ export default function(props: { isOpen: boolean; onClose: () => void }) {
});
if (!fileUpload.ok) {
setLoading(false)
await fetch("/api/reports/recall", {
body: JSON.stringify({ id }),
headers: {
@ -165,6 +172,8 @@ export default function(props: { isOpen: boolean; onClose: () => void }) {
status: "success",
title: "Success"
});
setLoading(false)
}
return (
@ -276,6 +285,8 @@ export default function(props: { isOpen: boolean; onClose: () => void }) {
}
ml="8px"
onClick={async () => await submit()}
isLoading={loading}
loadingText='Submitting...'
>
Submit
</Button>

View File

@ -22,6 +22,7 @@ export default function(props: {
onClose: () => void;
}) {
const [departments, setDepartments] = useState([] as string[]);
const [loading, setLoading] = useState(false)
const toast = useToast();
function reset() {
@ -33,13 +34,22 @@ export default function(props: {
}
async function submit() {
setLoading(true)
const start = (document.getElementById("start") as HTMLInputElement).value;
const end = (document.getElementById("start") as HTMLInputElement).value;
const reason = (document.getElementById("reason") as HTMLTextAreaElement)
.value;
if (!departments.length)
return alert("You need to select at least one department!");
if (!departments.length) {
toast({
title: 'Validation Error',
description: 'You need to select at least one department',
status: "error"
})
setLoading(false)
return;
}
const inactivityPost = await fetch("/api/inactivity/new", {
body: JSON.stringify({
@ -55,6 +65,7 @@ export default function(props: {
});
if (!inactivityPost.ok) {
setLoading(false)
toast({
description: ((await inactivityPost.json()) as { error: string }).error,
duration: 10000,
@ -74,6 +85,7 @@ export default function(props: {
title: "Success"
});
setLoading(true)
props.onClose();
}
@ -116,6 +128,8 @@ export default function(props: {
colorScheme="blue"
ml="8px"
onClick={async () => await submit()}
isLoading={loading}
loadingText='Submitting...'
>
Submit
</Button>

View File

@ -157,6 +157,8 @@ export default function (props: { isOpen: boolean; onClose: () => void }) {
colorScheme="blue"
ml="8px"
onClick={async () => await submit()}
isLoading={loading}
loadingText="Submitting..."
>
Submit
</Button>

View File

@ -18,6 +18,7 @@ import { useState } from "react";
export default function (props: ReportCardProps) {
const [attachmentIdx, setAttachmentIdx] = useState(0);
const [loading, setLoading] = useState(false)
const toast = useToast();
const targetMap: { [k: number]: string } = {};
const [attachmentsReady, setAttachmentReady] = useState(
@ -43,6 +44,7 @@ export default function (props: ReportCardProps) {
}
async function submitActions() {
setLoading(true)
const submitReq = await fetch(`/api/reports/${props.id}/action`, {
body: JSON.stringify(actionMap),
headers: {
@ -52,6 +54,7 @@ export default function (props: ReportCardProps) {
});
if (!submitReq.ok) {
setLoading(false)
toast({
description: ((await submitReq.json()) as { error: string }).error,
status: "error",
@ -66,6 +69,7 @@ export default function (props: ReportCardProps) {
status: "success",
title: "Success",
});
setLoading(false)
}
return (
@ -187,6 +191,8 @@ export default function (props: ReportCardProps) {
<Button
colorScheme="blue"
onClick={async () => await submitActions()}
isLoading={loading}
loadingText='Submitting...'
>
Submit
</Button>

View File

@ -35,12 +35,10 @@ export default function ({
</svg>
<Spacer />
</Flex>
<Center>
<br />
<Heading>{heading}</Heading>
<Heading textAlign="center">{heading}</Heading>
<br />
<Text>{message}</Text>
</Center>
<Text textAlign="center">{message}</Text>
</Container>
);
}