Oh yeah I forgot the other half

This commit is contained in:
regalijan 2023-10-19 16:50:58 -04:00
parent 387cf6a6b2
commit 0a4ad7792d
Signed by: regalijan
GPG Key ID: 5D4196DA269EF520
11 changed files with 96 additions and 13 deletions

View File

@ -64,9 +64,11 @@ export default function () {
const pageProps = useLoaderData<typeof loader>(); const pageProps = useLoaderData<typeof loader>();
const { isOpen, onClose, onOpen } = useDisclosure(); const { isOpen, onClose, onOpen } = useDisclosure();
const [showSuccess, setShowSuccess] = useState(false); const [showSuccess, setShowSuccess] = useState(false);
const [loading, setLoading] = useState(false)
const toast = useToast(); const toast = useToast();
async function submit() { async function submit() {
setLoading(true)
const learned = (document.getElementById("learned") as HTMLInputElement) const learned = (document.getElementById("learned") as HTMLInputElement)
.value; .value;
const whyBanned = (document.getElementById("whyBanned") as HTMLInputElement) const whyBanned = (document.getElementById("whyBanned") as HTMLInputElement)
@ -86,7 +88,8 @@ export default function () {
method: "POST", method: "POST",
}).catch(() => {}); }).catch(() => {});
if (!submitReq) if (!submitReq) {
setLoading(false)
return toast({ return toast({
description: "Please check your internet and try again", description: "Please check your internet and try again",
duration: 10000, duration: 10000,
@ -94,8 +97,10 @@ export default function () {
status: "error", status: "error",
title: "Request Failed", title: "Request Failed",
}); });
}
if (!submitReq.ok) if (!submitReq.ok) {
setLoading(false)
return toast({ return toast({
description: ((await submitReq.json()) as { error: string }).error, description: ((await submitReq.json()) as { error: string }).error,
duration: 10000, duration: 10000,
@ -103,8 +108,10 @@ export default function () {
status: "error", status: "error",
title: "Error", title: "Error",
}); });
}
setShowSuccess(true); setShowSuccess(true);
setLoading(false)
} }
async function toggle(active: boolean) { async function toggle(active: boolean) {
@ -232,6 +239,8 @@ export default function () {
<Button <Button
disabled={pageProps.can_appeal} disabled={pageProps.can_appeal}
onClick={async () => await submit()} onClick={async () => await submit()}
loadingText='Submitting'
isLoading={loading}
> >
Submit Submit
</Button> </Button>

View File

@ -13,6 +13,7 @@ import { useState } from "react";
export default function () { export default function () {
const [showCookieBox, setShowCookieBox] = useState(false); const [showCookieBox, setShowCookieBox] = useState(false);
const [loading, setLoading] = useState(false)
return ( return (
<Container maxW="container.md"> <Container maxW="container.md">
<Heading pt="36px">Let's get started</Heading> <Heading pt="36px">Let's get started</Heading>
@ -31,6 +32,7 @@ export default function () {
/> />
<Button <Button
onClick={async () => { onClick={async () => {
setLoading(true)
const createTransferReq = await fetch("/api/data-transfers/create", { const createTransferReq = await fetch("/api/data-transfers/create", {
body: JSON.stringify({ body: JSON.stringify({
can_access: !showCookieBox, can_access: !showCookieBox,
@ -45,6 +47,7 @@ export default function () {
}); });
if (!createTransferReq.ok) { if (!createTransferReq.ok) {
setLoading(false)
useToast()({ useToast()({
description: ( description: (
(await createTransferReq.json()) as { error: string } (await createTransferReq.json()) as { error: string }
@ -62,6 +65,8 @@ export default function () {
); );
}} }}
pt="32px" pt="32px"
isLoading={loading}
loadingText='Processing...'
> >
Continue Continue
</Button> </Button>

View File

@ -42,6 +42,7 @@ export default function () {
const [supportsRequestStreams, setSupportsRequestStreams] = useState(false); const [supportsRequestStreams, setSupportsRequestStreams] = useState(false);
const toast = useToast(); const toast = useToast();
const [uploading, setUploading] = useState(false); const [uploading, setUploading] = useState(false);
const [loading, setLoading] = useState(false)
const fileTypes: { [k: string]: string } = { const fileTypes: { [k: string]: string } = {
gif: "image/gif", gif: "image/gif",
m4v: "video/x-m4v", m4v: "video/x-m4v",
@ -75,6 +76,7 @@ export default function () {
const { logged_in, site_key } = useLoaderData<typeof loader>(); const { logged_in, site_key } = useLoaderData<typeof loader>();
async function submit() { async function submit() {
setLoading(true)
const usernames = ( const usernames = (
document.getElementById("usernames") as HTMLInputElement document.getElementById("usernames") as HTMLInputElement
).value ).value
@ -83,29 +85,35 @@ export default function () {
const files = (document.getElementById("evidence") as HTMLInputElement) const files = (document.getElementById("evidence") as HTMLInputElement)
.files; .files;
if (!usernames.length) if (!usernames.length) {
setLoading(false)
return toast({ return toast({
description: "Must provide at least one username", description: "Must provide at least one username",
isClosable: true, isClosable: true,
status: "error", status: "error",
title: "Error", title: "Error",
}); });
}
if (!files?.length) if (!files?.length) {
setLoading(false)
return toast({ return toast({
description: "Must attach at least one file", description: "Must attach at least one file",
isClosable: true, isClosable: true,
status: "error", status: "error",
title: "Error", title: "Error",
}); });
}
if (usernames.length > 20) if (usernames.length > 20) {
setLoading(false)
return toast({ return toast({
description: "Only up to twenty users can be reported at a time", description: "Only up to twenty users can be reported at a time",
isClosable: true, isClosable: true,
status: "error", status: "error",
title: "Too Many Usernames", title: "Too Many Usernames",
}); });
}
let turnstileToken = ""; let turnstileToken = "";
@ -114,13 +122,15 @@ export default function () {
.getElementsByName("cf-turnstile-response") .getElementsByName("cf-turnstile-response")
.item(0) as HTMLInputElement; .item(0) as HTMLInputElement;
if (!tokenElem.value) if (!tokenElem.value) {
setLoading(false)
return toast({ return toast({
description: "Please complete the captcha and try again", description: "Please complete the captcha and try again",
isClosable: true, isClosable: true,
status: "error", status: "error",
title: "Captcha not completed", title: "Captcha not completed",
}); });
}
turnstileToken = tokenElem.value; turnstileToken = tokenElem.value;
} }
@ -150,6 +160,7 @@ export default function () {
}); });
if (!submitReq.ok) { if (!submitReq.ok) {
setLoading(false)
if (!logged_in) { if (!logged_in) {
try { try {
// @ts-expect-error // @ts-expect-error
@ -224,6 +235,7 @@ export default function () {
} }
if (shouldRecall) { if (shouldRecall) {
setLoading(false)
await fetch("/api/reports/recall", { await fetch("/api/reports/recall", {
body: JSON.stringify({ id }), body: JSON.stringify({ id }),
headers: { headers: {
@ -252,6 +264,7 @@ export default function () {
}); });
setShowSuccess(true); setShowSuccess(true);
setLoading(false)
} }
useEffect(() => { useEffect(() => {
@ -319,6 +332,8 @@ export default function () {
disabled={uploading} disabled={uploading}
mr="8px" mr="8px"
onClick={async () => await submit()} onClick={async () => await submit()}
loadingText='Submitting'
isLoading={loading}
> >
Submit Submit
</Button> </Button>

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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