Change loading to false before displaying error message
This commit is contained in:
parent
3155442796
commit
7ec760efd4
@ -10,7 +10,7 @@ import {
|
|||||||
ModalOverlay,
|
ModalOverlay,
|
||||||
Select,
|
Select,
|
||||||
Text,
|
Text,
|
||||||
useToast,
|
useToast
|
||||||
} from "@chakra-ui/react";
|
} from "@chakra-ui/react";
|
||||||
import { useState } from "react";
|
import { useState } from "react";
|
||||||
|
|
||||||
@ -24,7 +24,7 @@ export default function (props: { isOpen: boolean; onClose: () => void }) {
|
|||||||
if (!props.isOpen) return;
|
if (!props.isOpen) return;
|
||||||
|
|
||||||
const evidenceElement = document.getElementById(
|
const evidenceElement = document.getElementById(
|
||||||
"evidence",
|
"evidence"
|
||||||
) as HTMLInputElement;
|
) as HTMLInputElement;
|
||||||
|
|
||||||
if (!evidenceElement.files && e.clipboardData?.files) {
|
if (!evidenceElement.files && e.clipboardData?.files) {
|
||||||
@ -74,7 +74,7 @@ export default function (props: { isOpen: boolean; onClose: () => void }) {
|
|||||||
|
|
||||||
const postReq = await fetch("/api/infractions/new", {
|
const postReq = await fetch("/api/infractions/new", {
|
||||||
body: form,
|
body: form,
|
||||||
method: "POST",
|
method: "POST"
|
||||||
});
|
});
|
||||||
|
|
||||||
if (postReq.ok) {
|
if (postReq.ok) {
|
||||||
@ -84,13 +84,15 @@ export default function (props: { isOpen: boolean; onClose: () => void }) {
|
|||||||
duration: 5000,
|
duration: 5000,
|
||||||
isClosable: true,
|
isClosable: true,
|
||||||
status: "success",
|
status: "success",
|
||||||
title: "Success",
|
title: "Success"
|
||||||
});
|
});
|
||||||
|
|
||||||
props.onClose();
|
props.onClose();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
setLoading(false);
|
||||||
|
|
||||||
toast({
|
toast({
|
||||||
description: `Failed to create infraction (${
|
description: `Failed to create infraction (${
|
||||||
((await postReq.json()) as { error: string }).error
|
((await postReq.json()) as { error: string }).error
|
||||||
@ -98,10 +100,8 @@ export default function (props: { isOpen: boolean; onClose: () => void }) {
|
|||||||
duration: 5000,
|
duration: 5000,
|
||||||
isClosable: true,
|
isClosable: true,
|
||||||
status: "error",
|
status: "error",
|
||||||
title: "Error",
|
title: "Error"
|
||||||
});
|
});
|
||||||
|
|
||||||
setLoading(false);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
|
Loading…
x
Reference in New Issue
Block a user